Package adams.flow.control
Class SequentialDirector
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.flow.control.AbstractDirector
-
- adams.flow.control.SequentialDirector
-
- All Implemented Interfaces:
CleanUpHandler,LoggingSupporter,SizeOfHandler,Stoppable,StoppableWithFeedback,FlowPauseStateListener,Serializable
- Direct Known Subclasses:
SequenceSource.SequenceSourceDirector,SubProcess.SubProcessDirector
public class SequentialDirector extends AbstractDirector
Manages the execution of actors in sequential order.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_Executedwhether the director was executed at all.protected List<Token>m_FinalOutputfor storing the token that the last actor generated.protected booleanm_Finishedwhether execution has finished.-
Fields inherited from class adams.flow.control.AbstractDirector
m_ControlActor, m_Flushing, m_LoggingPrefix, m_Paused, m_Stopped, m_Stopping
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description SequentialDirector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int[]activeIndices()Returns the indices of the active (= non-skipped) actors.protected int[]activeIndices(int from, int to)Returns the indices of the active (= non-skipped) actors in the given range.protected StringcheckActorHasStopped(Actor actor)Checks whether the actor has already stopped.voidcleanUp()Cleans up data structures, frees up memory.protected StringdoExecute(Actor actor)Calls the execute() method of the actor.protected StringdoExecuteActors(Actor startActor)Peforms the execution of the actors.protected ActordoExecuteStandalones()Executes all the standalone actors.protected booleandoHasOutput(Actor actor)Checks whether the actor has pending output.protected StringdoInput(Actor actor, Token input)Presents the specified token to the actor.protected TokendoOutput(Actor actor)Retrieves the token from the actor.Stringexecute()Executes the group of actors.voidflushExecution()Stops the processing of tokens without stopping the flow.protected List<Token>getFinalOutput()Returns the vector for storing final outputs.protected StringhandleError(Actor actor, String action, String msg)Handles the given error message, calling the actor's error handler, if defined.protected StringhandleException(Actor actor, String msg, Throwable t)Handles the error message, by outputting the exception on stderr and generating/returning a combined error string.protected voidinitialize()Initializes the members.protected booleanisFinalOutputRecorded()Returns whether the final output of actors is recorded.booleanisFinished()Checks whether the director has finished.voidstopExecution()Stops the execution.-
Methods inherited from class adams.flow.control.AbstractDirector
configureLogger, flowPauseStateChanged, getControlActor, getVariables, handleException, hasControlActor, isFlushing, isPaused, isStopped, isStopping, pause, pauseExecution, setControlActor, setLoggingLevel, toString, updatePrefix
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractDirector
-
isFinalOutputRecorded
protected boolean isFinalOutputRecorded()
Returns whether the final output of actors is recorded.
Default implementation returns false.- Returns:
- true if final output is to be recorded
-
getFinalOutput
protected List<Token> getFinalOutput()
Returns the vector for storing final outputs. Gets instantiated if necessary.- Returns:
- the vector for storing the tokens
- See Also:
m_FinalOutput
-
checkActorHasStopped
protected String checkActorHasStopped(Actor actor)
Checks whether the actor has already stopped. If so, outputs a message on the commandline and returns the error message.- Parameters:
actor- the actor to check- Returns:
- null if actor not stopped, otherwise the error message
-
handleException
protected String handleException(Actor actor, String msg, Throwable t)
Handles the error message, by outputting the exception on stderr and generating/returning a combined error string.- Parameters:
actor- the actor that generated the exceptionmsg- the error messaget- the exception- Returns:
- the combined error string
-
handleError
protected String handleError(Actor actor, String action, String msg)
Handles the given error message, calling the actor's error handler, if defined.- Parameters:
actor- the actor to let the error handleaction- the action when the error occurredmsg- the error message, skips handling if null- Returns:
- the (potentially) updated error message
-
doInput
protected String doInput(Actor actor, Token input)
Presents the specified token to the actor.- Parameters:
actor- the actor to use (InputConsumer)input- the input token- Returns:
- the error message, null if everything OK
-
doExecute
protected String doExecute(Actor actor)
Calls the execute() method of the actor.- Parameters:
actor- the actor to use- Returns:
- a potential error message
-
doHasOutput
protected boolean doHasOutput(Actor actor)
Checks whether the actor has pending output.- Parameters:
actor- the actor to use (OutputProducer)- Returns:
- the token that was retrieved from the actor, null in case of an error and not 'stopping on errors'
- See Also:
AbstractActor.getStopFlowOnError()
-
doOutput
protected Token doOutput(Actor actor)
Retrieves the token from the actor.- Parameters:
actor- the actor to use- Returns:
- the token that was retrieved from the actor, null in case of an error and not 'stopping on errors'
- See Also:
AbstractActor.getStopFlowOnError()
-
activeIndices
protected int[] activeIndices()
Returns the indices of the active (= non-skipped) actors.- Returns:
- the indices of active actors
-
activeIndices
protected int[] activeIndices(int from, int to)Returns the indices of the active (= non-skipped) actors in the given range.- Parameters:
from- the first actor (incl)to- the last actor (incl)- Returns:
- the indices of active actors
-
doExecuteStandalones
protected Actor doExecuteStandalones()
Executes all the standalone actors. Returns the first non-standalone actor.- Returns:
- the first non-standalone actor or null if non present
-
doExecuteActors
protected String doExecuteActors(Actor startActor)
Peforms the execution of the actors.- Parameters:
startActor- the actor to start with- Returns:
- null if everything ok, otherwise the error message
-
execute
public String execute()
Executes the group of actors.- Specified by:
executein classAbstractDirector- Returns:
- null if everything went smooth
-
isFinished
public boolean isFinished()
Checks whether the director has finished.- Overrides:
isFinishedin classAbstractDirector- Returns:
- true if execution finished (or stopped)
-
flushExecution
public void flushExecution()
Stops the processing of tokens without stopping the flow.- Overrides:
flushExecutionin classAbstractDirector
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractDirector
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceCleanUpHandler- Overrides:
cleanUpin classAbstractDirector
-
-