|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Engine
An Engine
executes a process. A Graph
specifies
how it should be executed and a GraphProcess
tracks the current state
of execution. But it is an Engine which creates instances of ArcToken
,
NodeToken
and GraphProcess
and which invokes
Node.guard(Engine, NodeToken)
and Node.execute(Engine, NodeToken)
.
Unless an Engine implementation states otherwise, Engine instances should not be considered thread-safe. A new Engine instance should be created for each thread that needs one.
Method Summary | |
---|---|
void |
addExecutionListener(Class<? extends ExecutionListener> listenerClass,
ExecutionEventType... eventTypes)
Adds a listener of the given type for the given event types for all processes. |
void |
addExecutionListener(GraphProcess process,
Class<? extends ExecutionListener> listenerClass,
ExecutionEventType... eventTypes)
Adds a listener for the given event types for the given process. |
void |
addGlobalCustomNodeType(String type,
Class<? extends CustomNode> nodeClass)
Adds the type to the GraphFactory for this engine. |
void |
addNodeType(String type,
Class<? extends Node> nodeClass)
Adds the type to the GraphFactory for this engine. |
void |
backtrack(NodeToken token)
Backtracks execution to the point where the given node token was active. |
void |
cancelProcess(GraphProcess process)
Cancels the given process. |
void |
complete(NodeToken token,
String arcName)
Continues execution of a process in a wait state. |
void |
completeAsynchronous(NodeToken token,
String arcName)
Marks the given node token completed and generates the next set of arc tokens. |
void |
completeWithNewTokenSet(NodeToken token,
String arcName,
String tokenSetName,
int numberOfTokens,
boolean asynchronous,
Env initialEnv,
Map<String,List<?>> initialMemberEnv)
Marks the given node token, creates new token set and generates the next set of arc tokens as members of that new token set. |
GuardResult |
evaluateGuard(NodeToken token,
String guard)
Nodes, by default, will pass off guard evaluation to the Engine. |
void |
executeQueuedArcTokens(GraphProcess process)
If this process has any ArcToken s queued for execution, this method
will execute them. |
void |
finalizeCancel(GraphProcess process)
Called by the engine when a process is cancelled, via cancelProcess(GraphProcess) . |
void |
finalizeComplete(GraphProcess process)
Called by the engine when the process is detected to be completed. |
EventActions |
fireEvent(ExecutionEvent event)
This will send the given event to listeners who have registered for events on all processes and to listeners who have registered for events on the process that originated this event. |
GraphFactory |
getFactory()
Returns an appropriate GraphFactory for this Engine . |
GraphLoader<? extends Graph> |
getLoader()
Returns an appropriate GraphLoader for this Engine . |
GraphLoader<? extends Graph> |
getLoader(GraphValidator validator)
Returns an appropriate GraphLoader for this Engine . |
Engine |
getParentEngine()
If this engine was created to execute a nested process, it will remember the engine which created it. |
GraphRepository<? extends Graph> |
getRepository()
Returns an appropriate GraphRepository for this Engine . |
Engine |
newEngine(boolean forNested)
Since an Engine can have state specific to the currently executing process, there are times we want to create a new engine (such as when executing a nested process). |
JoinLangEnv |
newJoinLangEnv(ArcToken token)
Creates a JoinLangEnv to be used to evaluate a JoinLang statement
controlling if the given ArcToken satisfies a join. |
RubricEnv |
newRubricEnv(NodeToken token)
Creates a RubricEnv to be used to evaluate a Rubric statement
defining a guard for the given NodeToken . |
void |
removeExecutionListener(Class<? extends ExecutionListener> listenerClass,
ExecutionEventType... eventTypes)
Will remove the given listener type from the set of global listeners. |
void |
removeExecutionListener(GraphProcess process,
Class<? extends ExecutionListener> listenerClass,
ExecutionEventType... eventTypes)
Will remove the listener from the given proces. |
void |
setupScriptEnv(ScriptEnv env,
NodeToken token)
Adds whatever variables of interest to the script environment. |
GraphProcess |
startProcess(Graph graph)
Given a Graph , creates a new GraphProcess executing that graph. |
void |
startProcess(GraphProcess process)
Sometimes it is desirable to separate process creation from starting execution of the process. |
GraphProcess |
startProcess(String graphName)
Starts an instance of the latest graph with the given name. |
Method Detail |
---|
GraphProcess startProcess(String graphName)
Graph graph = engine.getRepository().getLatestGraph( graphName ); GraphProcess process = engine.startProcess( graph );If no process definition exists for the given name, a
SarasvatiException
will be thrown.
graphName
- The name of the graph to execute.
SarasvatiException
- If no process definition is defined for that name.GraphProcess startProcess(Graph graph)
Graph
, creates a new GraphProcess
executing that graph.
A NodeToken
will be generated on each start nodes (determined by
Graph.getStartNodes()
), and these NodeTokens will be executed.
If the graph does not contain Nodes which go into a wait state, the
GraphProcess
returned will be completed.
graph
- The Graph
to execute.
GraphProcess
executing the given Graph
.void startProcess(GraphProcess process)
NodeToken
on each
start node contained in the given process.
process
- The process on which to begin execution.void cancelProcess(GraphProcess process)
ProcessState.PendingCancel
.
process
- The process to cancelvoid finalizeComplete(GraphProcess process)
ProcessState.Completed
and perform
whatever cleanup is required.
If an ExecutionListener
returns an EventActions
object
specifying EventActionType.DELAY_PROCESS_FINALIZE_COMPLETE
, then
this method will *not* be called, and be manually invoked from user logic
If this process is a nested process, at this point the containing token will be completed.
process
- The process being completed.void finalizeCancel(GraphProcess process)
cancelProcess(GraphProcess)
.
It will set the state to ProcessState.Canceled
and perform whatever
cleanup is required.
If an ExecutionListener
returns an EventActions
object
specifying EventActionType.DELAY_PROCESS_FINALIZE_CANCEL
, then
this method will *not* be called, and be manually invoked from user logic
process
- The process being canceled.void complete(NodeToken token, String arcName)
Node.execute(Engine, NodeToken)
does not contain a
call to complete(NodeToken, String)
, then execution
of the graph will halt at that point. This is generally referred to as a wait
state. It may happen, for example, if the action represented by that node
must be done by a human or some external system.
Node
has completed its
work, it should invoke this method to continue executing the process.
ProcessState.Executing
this call will return immediately.
token
- The NodeToken
to resume execution onarcName
- The name of the Arc
(or arcs, as more than one Arc
can
have the same name) to generate ArcTokens on.void completeAsynchronous(NodeToken token, String arcName)
executeQueuedArcTokens(GraphProcess)
.
token
- The token to mark completedarcName
- The name of the Arc
(or arcs, as more than one Arc
can
have the same name) to generate ArcTokens on.void completeWithNewTokenSet(NodeToken token, String arcName, String tokenSetName, int numberOfTokens, boolean asynchronous, Env initialEnv, Map<String,List<?>> initialMemberEnv)
token
- The node token to completearcName
- The name of the Arc
(or arcs, as more than one Arc
can
have the same name) to generate ArcTokens on.tokenSetName
- The token set namenumberOfTokens
- The number of tokens to generate on each arcasynchronous
- If true, the engine will return after creating the arc tokens.
If false, the new arc tokens will be processed immediately.initialEnv
- The initial environment for the new token set. May be null.initialMemberEnv
- The initial environment for the new token set members. May be null.void executeQueuedArcTokens(GraphProcess process)
ArcToken
s queued for execution, this method
will execute them.
process
- The process whose queued arc tokens to queueGraphRepository<? extends Graph> getRepository()
GraphRepository
for this Engine
. Subclasses
may override this to provide custom behavior.
GraphRepository
for this Engine
GraphFactory getFactory()
GraphFactory
for this Engine
. Subclasses
may override this provide customer behavior.
GraphFactory
which will generate the appropriate types for this Engine
.GraphLoader<? extends Graph> getLoader()
GraphLoader
for this Engine
. Subclasses
may override this provide customer behavior.
Equivalent to getLoader( null )
GraphLoader
which, by default, will use the factory and repository from this engine.GraphLoader<? extends Graph> getLoader(GraphValidator validator)
GraphLoader
for this Engine
. Subclasses
may override this provide customer behavior.
GraphLoader
which, by default, will use the factory and repository from this engine.void addNodeType(String type, Class<? extends Node> nodeClass)
GraphFactory
for this engine. Specifies
what class will be used for a given node type, when loading process
definitions from XML file.
type
- The type identifier, as used in the process definition filenodeClass
- The node class which will be instantiated for this typevoid addGlobalCustomNodeType(String type, Class<? extends CustomNode> nodeClass)
GraphFactory
for this engine. Specifies
what class will be used for a given node type, when loading process
definitions from XML file.
Adds a class for a custom node type globally, for all GraphFactory instances. Only custom types can have global instances, since they are backend agnostic.
type
- The type identifier, as used in the process definition filenodeClass
- The custom node class which will be instantiated for this typeEventActions fireEvent(ExecutionEvent event)
event
- The event to send to all interested listeners.
void addExecutionListener(Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
ExecutionListener
Global execution listeners must be thread safe. Because
listeners are specified by type, they must have a default constructor and be
instantiatable by a call to listenerClass.newInstance().
listenerClass
- The listener type to be addedeventTypes
- The event types to be notified for. If no types are specified, the listener is added for all event types.void addExecutionListener(GraphProcess process, Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
ExecutionListener
Execution listeners must be thread safe. Because
listeners are specified by type, they must have a default constructor and be
instantiatable by a call to listenerClass.newInstance().
process
- The process to add the listener for, or null for all processeslistenerClass
- The listener type to be added.eventTypes
- The event types to be notified for. If no listener types are specified, the listener is added for all event types.void removeExecutionListener(Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
listenerClass
- The type of listener to removeeventTypes
- The set of event types to remove the listener for, or none to remove for allvoid removeExecutionListener(GraphProcess process, Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
process
- The process to remove the listener from, or null to remove from the global listener setlistenerClass
- The type of listener to removeeventTypes
- The set of event types to remove the listener for, or none to remove for allvoid setupScriptEnv(ScriptEnv env, NodeToken token)
env
- The script environment to add variables totoken
- The NodeToken which is currently being executedRubricEnv newRubricEnv(NodeToken token)
RubricEnv
to be used to evaluate a Rubric statement
defining a guard for the given NodeToken
.
token
- The token which will provide some of the state for the RubricEnv
JoinLangEnv newJoinLangEnv(ArcToken token)
JoinLangEnv
to be used to evaluate a JoinLang statement
controlling if the given ArcToken
satisfies a join.
token
- The token which will provide some of the state for the JoinLangEnv
ArcToken
.GuardResult evaluateGuard(NodeToken token, String guard)
token
- The NodeToken for which the guard is being evaluated.guard
- The guard statement to be evaluated. Maybe blank or null, which
by convention should cause AcceptTokenGuardResult
to be returned.
Engine newEngine(boolean forNested)
forNested
- Indicates whether this new engine is being created to track
execution of a nested process.
Engine getParentEngine()
void backtrack(NodeToken token)
token
- The destination token to backtrack to.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |