|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.googlecode.sarasvati.impl.BaseEngine
public abstract class BaseEngine
Contains all the engine logic which is not backend specific.
Instances of BaseEngine have local state which is not thread-safe. Create a new Engine instance for each thread that needs one.
Constructor Summary | |
---|---|
BaseEngine(String applicationContext)
Creates a new Engine with the given application context. |
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 Engine.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. |
BaseEngine |
getParentEngine()
If this engine was created to execute a nested process, it will remember the engine which created it. |
BaseEngine |
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. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.googlecode.sarasvati.Engine |
---|
getFactory, getLoader, getLoader, getRepository |
Constructor Detail |
---|
public BaseEngine(String applicationContext)
applicationContext
- The application contextMethod Detail |
---|
public GraphProcess startProcess(String graphName)
Engine
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.
startProcess
in interface Engine
graphName
- The name of the graph to execute.
public GraphProcess startProcess(Graph graph)
Engine
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.
startProcess
in interface Engine
graph
- The Graph
to execute.
GraphProcess
executing the given Graph
.public void startProcess(GraphProcess process)
Engine
NodeToken
on each
start node contained in the given process.
startProcess
in interface Engine
process
- The process on which to begin execution.public void cancelProcess(GraphProcess process)
Engine
ProcessState.PendingCancel
.
cancelProcess
in interface Engine
process
- The process to cancelpublic void finalizeComplete(GraphProcess process)
Engine
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.
finalizeComplete
in interface Engine
process
- The process being completed.public void finalizeCancel(GraphProcess process)
Engine
Engine.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
finalizeCancel
in interface Engine
process
- The process being canceled.public void complete(NodeToken token, String arcName)
Engine
Node.execute(Engine, NodeToken)
does not contain a
call to Engine.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.
complete
in interface Engine
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.public void completeAsynchronous(NodeToken token, String arcName)
Engine
Engine.executeQueuedArcTokens(GraphProcess)
.
completeAsynchronous
in interface Engine
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.public void completeWithNewTokenSet(NodeToken token, String arcName, String tokenSetName, int numberOfTokens, boolean asynchronous, Env initialEnv, Map<String,List<?>> initialMemberEnv)
Engine
completeWithNewTokenSet
in interface Engine
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.public void executeQueuedArcTokens(GraphProcess process)
Engine
ArcToken
s queued for execution, this method
will execute them.
executeQueuedArcTokens
in interface Engine
process
- The process whose queued arc tokens to queuepublic void setupScriptEnv(ScriptEnv env, NodeToken token)
Engine
setupScriptEnv
in interface Engine
env
- The script environment to add variables totoken
- The NodeToken which is currently being executedpublic void addNodeType(String type, Class<? extends Node> nodeClass)
Engine
GraphFactory
for this engine. Specifies
what class will be used for a given node type, when loading process
definitions from XML file.
addNodeType
in interface Engine
type
- The type identifier, as used in the process definition filenodeClass
- The node class which will be instantiated for this typepublic void addGlobalCustomNodeType(String type, Class<? extends CustomNode> nodeClass)
Engine
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.
addGlobalCustomNodeType
in interface Engine
type
- The type identifier, as used in the process definition filenodeClass
- The custom node class which will be instantiated for this typepublic void backtrack(NodeToken token)
Engine
backtrack
in interface Engine
token
- The destination token to backtrack to.public RubricEnv newRubricEnv(NodeToken token)
Engine
RubricEnv
to be used to evaluate a Rubric statement
defining a guard for the given NodeToken
.
newRubricEnv
in interface Engine
token
- The token which will provide some of the state for the RubricEnv
public JoinLangEnv newJoinLangEnv(ArcToken token)
Engine
JoinLangEnv
to be used to evaluate a JoinLang statement
controlling if the given ArcToken
satisfies a join.
newJoinLangEnv
in interface Engine
token
- The token which will provide some of the state for the JoinLangEnv
ArcToken
.public GuardResult evaluateGuard(NodeToken token, String guard)
Engine
evaluateGuard
in interface Engine
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.
public BaseEngine newEngine(boolean forNested)
Engine
newEngine
in interface Engine
forNested
- Indicates whether this new engine is being created to track
execution of a nested process.
public BaseEngine getParentEngine()
Engine
getParentEngine
in interface Engine
public void addExecutionListener(Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
Engine
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().
addExecutionListener
in interface Engine
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.public void removeExecutionListener(Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
Engine
removeExecutionListener
in interface Engine
listenerClass
- The type of listener to removeeventTypes
- The set of event types to remove the listener for, or none to remove for allpublic void addExecutionListener(GraphProcess process, Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
Engine
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().
addExecutionListener
in interface Engine
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.public void removeExecutionListener(GraphProcess process, Class<? extends ExecutionListener> listenerClass, ExecutionEventType... eventTypes)
Engine
removeExecutionListener
in interface Engine
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 allpublic EventActions fireEvent(ExecutionEvent event)
Engine
fireEvent
in interface Engine
event
- The event to send to all interested listeners.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |