com.googlecode.sarasvati.mem
Class MemGraphProcess

java.lang.Object
  extended by com.googlecode.sarasvati.mem.MemGraphProcess
All Implemented Interfaces:
HasEventQueue, GraphProcess

public class MemGraphProcess
extends Object
implements GraphProcess


Constructor Summary
MemGraphProcess(Graph graph)
           
 
Method Summary
 void addActiveArcToken(ArcToken token)
          Adds an ArcToken to the list of active ArcTokens.
 void addActiveNodeToken(NodeToken token)
          Adds a NodeToken to the list of active NodeTokens.
 void addNodeToken(NodeToken token)
          Adds a NodeToken to the list of all NodeTokens for this process.
 ArcToken dequeueArcTokenForExecution()
          Returns the next ArcToken to execute
 void enqueueArcTokenForExecution(ArcToken token)
          Adds an arc token to the execution queue
 List<ArcToken> getActiveArcTokens()
          Returns the list of current ArcTokens.
 List<NodeToken> getActiveNodeTokens()
          Returns the list of current NodeTokens.
 Env getEnv()
          Returns the environment for the process.
 ExecutionEventQueue getEventQueue()
          Returns the event queue which manages the set of listeners for the instance and handles firing events to those listeners.
 Graph getGraph()
          Returns the graph being executed.
 List<NodeToken> getNodeTokens()
          Returns the list of all NodeTokens.
 NodeToken getParentToken()
          If this a nested process, then this will return the parent NodeToken and null otherwise.
 ProcessState getState()
          Returns the current ProcessState
 List<NodeToken> getTokensOnNode(Node node, Engine engine)
          Returns the collection of NodeTokens which have been created on the given Node.
 boolean hasActiveTokens()
          Return true if the process has any active arc or node tokens.
 boolean isArcTokenQueueEmpty()
          Return true if the arc token queue is empty, false otherwise
 boolean isCanceled()
          Returns true if the process state is either ProcessState.PendingCancel or ProcessState.Canceled
 boolean isComplete()
          Returns true if the process state is either ProcessState.PendingCompletion or ProcessState.Completed
 boolean isExecuting()
          Returns true if the process state is ProcessState.Executing
 long nextTokenId()
           
 void removeActiveArcToken(ArcToken token)
          Removes an ArcToken from the list of active ArcTokens.
 void removeActiveNodeToken(NodeToken token)
          Removes a NodeToken from the list of active NodeTokens.
 void setParentToken(NodeToken parentToken)
           
 void setState(ProcessState state)
          Sets the current ProcessState.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemGraphProcess

public MemGraphProcess(Graph graph)
Method Detail

addActiveArcToken

public void addActiveArcToken(ArcToken token)
Description copied from interface: GraphProcess
Adds an ArcToken to the list of active ArcTokens. Active ArcTokens have been executed, but are not complete. They are waiting for other ArcTokens to arrive at their target node (which will be a join node).

Specified by:
addActiveArcToken in interface GraphProcess
Parameters:
token - The token being added

addActiveNodeToken

public void addActiveNodeToken(NodeToken token)
Description copied from interface: GraphProcess
Adds a NodeToken to the list of active NodeTokens.

Specified by:
addActiveNodeToken in interface GraphProcess
Parameters:
token - The token being added

getNodeTokens

public List<NodeToken> getNodeTokens()
Description copied from interface: GraphProcess
Returns the list of all NodeTokens.

Specified by:
getNodeTokens in interface GraphProcess
Returns:
The list of all NodeTokens.

getActiveArcTokens

public List<ArcToken> getActiveArcTokens()
Description copied from interface: GraphProcess
Returns the list of current ArcTokens.

Specified by:
getActiveArcTokens in interface GraphProcess
Returns:
The list of current ArcTokens.

getActiveNodeTokens

public List<NodeToken> getActiveNodeTokens()
Description copied from interface: GraphProcess
Returns the list of current NodeTokens.

Specified by:
getActiveNodeTokens in interface GraphProcess
Returns:
The list of current NodeTokens.

addNodeToken

public void addNodeToken(NodeToken token)
Description copied from interface: GraphProcess
Adds a NodeToken to the list of all NodeTokens for this process.

Specified by:
addNodeToken in interface GraphProcess
Parameters:
token - The token being added

getEnv

public Env getEnv()
Description copied from interface: GraphProcess
Returns the environment for the process.

Specified by:
getEnv in interface GraphProcess
Returns:
An Env containing variables defined on this process

getGraph

public Graph getGraph()
Description copied from interface: GraphProcess
Returns the graph being executed.

Specified by:
getGraph in interface GraphProcess
Returns:
The graph being executed.

getParentToken

public NodeToken getParentToken()
Description copied from interface: GraphProcess
If this a nested process, then this will return the parent NodeToken and null otherwise. A nested process is one was started from a different process. The process is started when a specific node is executed. The node will be in a wait state while the nested process executes. When the nested process completes, the node execution will be completed.

Specified by:
getParentToken in interface GraphProcess
Returns:
If this is a nested process, this will return the parent NodeToken, and null otherwise.

setParentToken

public void setParentToken(NodeToken parentToken)

removeActiveArcToken

public void removeActiveArcToken(ArcToken token)
Description copied from interface: GraphProcess
Removes an ArcToken from the list of active ArcTokens.

Specified by:
removeActiveArcToken in interface GraphProcess
Parameters:
token - The token being removed.

removeActiveNodeToken

public void removeActiveNodeToken(NodeToken token)
Description copied from interface: GraphProcess
Removes a NodeToken from the list of active NodeTokens.

Specified by:
removeActiveNodeToken in interface GraphProcess
Parameters:
token - The token being removed.

dequeueArcTokenForExecution

public ArcToken dequeueArcTokenForExecution()
Description copied from interface: GraphProcess
Returns the next ArcToken to execute

Specified by:
dequeueArcTokenForExecution in interface GraphProcess
Returns:
The next ArcToken to execute

enqueueArcTokenForExecution

public void enqueueArcTokenForExecution(ArcToken token)
Description copied from interface: GraphProcess
Adds an arc token to the execution queue

Specified by:
enqueueArcTokenForExecution in interface GraphProcess
Parameters:
token - to enqueue

isArcTokenQueueEmpty

public boolean isArcTokenQueueEmpty()
Description copied from interface: GraphProcess
Return true if the arc token queue is empty, false otherwise

Specified by:
isArcTokenQueueEmpty in interface GraphProcess
Returns:
True if the arc token queue is empty

getState

public ProcessState getState()
Description copied from interface: GraphProcess
Returns the current ProcessState

Specified by:
getState in interface GraphProcess
Returns:
The current ProcessState

setState

public void setState(ProcessState state)
Description copied from interface: GraphProcess
Sets the current ProcessState. The state should be set to ProcessState.Created by GraphFactory.newProcess(Graph). It should then be set to ProcessState.Executing by Engine.startProcess(GraphProcess)

Specified by:
setState in interface GraphProcess
Parameters:
state - The new ProcessState

isCanceled

public boolean isCanceled()
Description copied from interface: GraphProcess
Returns true if the process state is either ProcessState.PendingCancel or ProcessState.Canceled

Specified by:
isCanceled in interface GraphProcess
Returns:
True if the process state is either ProcessState.PendingCancel or ProcessState.Canceled

isComplete

public boolean isComplete()
Description copied from interface: GraphProcess
Returns true if the process state is either ProcessState.PendingCompletion or ProcessState.Completed

Specified by:
isComplete in interface GraphProcess
Returns:
True if the process state is either ProcessState.PendingCompletion or ProcessState.Completed

isExecuting

public boolean isExecuting()
Description copied from interface: GraphProcess
Returns true if the process state is ProcessState.Executing

Specified by:
isExecuting in interface GraphProcess
Returns:
True if the process state is ProcessState.Executing

hasActiveTokens

public boolean hasActiveTokens()
Description copied from interface: GraphProcess
Return true if the process has any active arc or node tokens. A process with no active tokens should be marked pending complete.

Specified by:
hasActiveTokens in interface GraphProcess
Returns:
True if the process has active tokens, false otherwise.

nextTokenId

public long nextTokenId()

getEventQueue

public ExecutionEventQueue getEventQueue()
Description copied from interface: HasEventQueue
Returns the event queue which manages the set of listeners for the instance and handles firing events to those listeners.

Specified by:
getEventQueue in interface HasEventQueue
Returns:
The event queue for this instance.

getTokensOnNode

public List<NodeToken> getTokensOnNode(Node node,
                                       Engine engine)
Description copied from interface: GraphProcess
Returns the collection of NodeTokens which have been created on the given Node.

Specified by:
getTokensOnNode in interface GraphProcess
Parameters:
node - The node whose tokens we are interested in
engine - The engine that may assist in generating the list.
Returns:
the collection of NodeTokens which have been created on the given Node.