Package adams.flow.control
Class Branch
-
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,Pausable
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,ThreadLimiter
,VariablesInspectionHandler
,FlowPauseStateListener
,VariableChangeListener
,AtomicExecution
,Actor
,ActorHandler
,ControlActor
,ErrorHandler
,Flushable
,InputConsumer
,MutableActorHandler
,SubFlowWrapUp
,Serializable
,Comparable
- Direct Known Subclasses:
ArrayGenerate
public class Branch extends AbstractControlActor implements InputConsumer, MutableActorHandler, AtomicExecution, ThreadLimiter
Branches off the flow into several sub-branches, each being supplied with a copy of the same object being passed into this meta-actor.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-name <java.lang.String> (property: name) The name of the actor. default: Branch
-annotation <adams.core.base.BaseText> (property: annotations) The annotations to attach to this actor. default:
-skip <boolean> (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is. default: false
-stop-flow-on-error <boolean> (property: stopFlowOnError) If set to true, the flow gets stopped in case this actor encounters an error; useful for critical actors. default: false
-finish-before-stopping <boolean> (property: finishBeforeStopping) If enabled, actor first finishes processing all data before stopping. default: false
-branch <adams.flow.core.Actor> [-branch ...] (property: branches) The different branches that branch off and will be supplied with a copy of the same object. default:
-num-threads <int> (property: numThreads) The number of threads to use for executing the branches; -1 = number of CPUs/cores; 0 or 1 = sequential execution. default: -1 minimum: -1
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
BACKUP_CURRENT
the key for storing the current token in the backup.protected int
m_ActualNumThreads
the actual number of threads to use.protected List<Actor>
m_Branches
the branches.protected HashMap<Integer,Token>
m_CollectedOutput
the collected output.protected boolean
m_CollectOutput
whether to collect the output of the branches.protected Token
m_CurrentToken
the token that gets passed on to all sub-branches.protected ExecutorService
m_Executor
the executor service to use for parallel execution.protected boolean
m_FinishBeforeStopping
whether to finish execution first before stopping.protected boolean
m_HasGlobalTransformers
whether the branch contains global transformers somewhere or not.protected int
m_NumThreads
the number of threads to use for parallel execution.protected int
m_StoppingTimeout
the timeout in milliseconds for stopping in case of atomic execution (<= 0 is infinity).protected int
m_StoppingWarningInterval
the interval in msec to warn if actors haven't stopped yet (and not stopping timeout set).-
Fields inherited from class adams.flow.control.AbstractControlActor
m_Compatibility, m_PauseStateManager, m_SetUpSubActors
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]
accepts()
Returns the class that the consumer accepts.String
add(int index, Actor actor)
Inserts the actor at the given position.String
add(Actor actor)
Inserts the actor at the end.protected Hashtable<String,Object>
backupState()
Backs up the current state of the actor before update the variables.String
branchesTipText()
Returns the tip text for this property.String
check()
Checks whether all the connections are valid, i.e., the input and output types fit and whether the flow chain is connected properly.protected String
checkBranch(Actor branch)
Checks the sub-branch.Token
currentInput()
Returns the current input token, if any.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.protected String
executeParallel()
Executes the branches in parallel.protected String
executeSequential()
Executes the branches sequentially.String
finishBeforeStoppingTipText()
Returns the tip text for this property.void
flushExecution()
Stops the processing of tokens without stopping the flow.Actor
get(int index)
Returns the actor at the given position.ActorHandlerInfo
getActorHandlerInfo()
Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.Actor[]
getBranches()
Returns the branches.HashMap<Integer,Token>
getCollectedOutput()
Returns the collected output from the branches, if any.boolean
getCollectOutput()
Returns whether the output of the branches is collected.boolean
getFinishBeforeStopping()
Returns whether to finish processing before stopping execution.int
getNumThreads()
Returns the number of threads to use for executing the branches.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.int
getStoppingTimeout()
Returns the timeout for waiting for the sub-flow to stop.int
getStoppingWarningInterval()
Returns the interval for outputting warnings if the sub-flow hasn't stopped yet (and no stopping timeout set).String
globalInfo()
Returns a string describing the object.protected boolean
hasGlobalTransformers()
Checks for global transformers that might get accessed by parallel threads.boolean
hasInput()
Returns whether an input token is currently present.int
indexOf(String actor)
Returns the index of the actor.protected void
initialize()
Initializes the members.void
input(Token token)
The method that accepts the input token and then processes it.String
numThreadsTipText()
Returns the tip text for this property.Actor
remove(int index)
Removes the actor at the given position and returns the removed object.void
removeAll()
Removes all actors.protected void
restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.String
set(int index, Actor actor)
Sets the actor at the given position.void
setBranches(Actor[] value)
Sets the branches.void
setCollectOutput(boolean value)
Whether to collect the output of the branches.void
setFinishBeforeStopping(boolean value)
Sets whether to finish processing before stopping execution.void
setNumThreads(int value)
Sets the number of threads to use for executing the branches.void
setStoppingTimeout(int value)
Sets the timeout for waiting for the sub-flow to stop.void
setStoppingWarningInterval(int value)
Sets the interval for outputting warnings if the sub-flow hasn't stopped yet (and no stopping timeout set).String
setUp()
Initializes the sub-actors for flow execution.int
size()
Returns the size of the group.void
stopExecution()
Stops the execution.String
stoppingTimeoutTipText()
Returns the tip text for this property.String
stoppingWarningIntervalTipText()
Returns the tip text for this property.void
wrapUp()
Finishes up the execution.-
Methods inherited from class adams.flow.control.AbstractControlActor
active, canInspectOptions, cleanUp, destroy, firstActive, firstInputConsumer, flowPauseStateChanged, forceVariables, isPaused, isSubFlowWrappedUp, lastActive, pauseExecution, preExecute, reset, resumeExecution, setParent, setUpSubActors, updateParent, wrapUpSubFlow
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canPerformSetUpCheck, compareTo, configureLogger, equals, execute, finalUpdateVariables, findVariables, findVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, pruneBackup, pruneBackup, setAnnotations, setErrorHandler, setName, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, toCommandLine, variableChanged
-
Methods inherited from interface adams.flow.core.ActorHandler
firstActive, lastActive
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
BACKUP_CURRENT
public static final String BACKUP_CURRENT
the key for storing the current token in the backup.- See Also:
- Constant Field Values
-
m_NumThreads
protected int m_NumThreads
the number of threads to use for parallel execution.
-
m_ActualNumThreads
protected int m_ActualNumThreads
the actual number of threads to use.
-
m_Executor
protected ExecutorService m_Executor
the executor service to use for parallel execution.
-
m_CurrentToken
protected transient Token m_CurrentToken
the token that gets passed on to all sub-branches.
-
m_HasGlobalTransformers
protected boolean m_HasGlobalTransformers
whether the branch contains global transformers somewhere or not.
-
m_FinishBeforeStopping
protected boolean m_FinishBeforeStopping
whether to finish execution first before stopping.
-
m_StoppingTimeout
protected int m_StoppingTimeout
the timeout in milliseconds for stopping in case of atomic execution (<= 0 is infinity).
-
m_StoppingWarningInterval
protected int m_StoppingWarningInterval
the interval in msec to warn if actors haven't stopped yet (and not stopping timeout set).
-
m_CollectOutput
protected boolean m_CollectOutput
whether to collect the output of the branches.
-
-
Constructor Detail
-
Branch
public Branch()
Default constructor.
-
Branch
public Branch(String name)
Initializes the actor with the specified name.- Parameters:
name
- the name to use
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractControlActor
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
setFinishBeforeStopping
public void setFinishBeforeStopping(boolean value)
Sets whether to finish processing before stopping execution.- Specified by:
setFinishBeforeStopping
in interfaceAtomicExecution
- Parameters:
value
- if true then actor finishes processing first
-
getFinishBeforeStopping
public boolean getFinishBeforeStopping()
Returns whether to finish processing before stopping execution.- Specified by:
getFinishBeforeStopping
in interfaceAtomicExecution
- Returns:
- true if actor finishes processing first
-
finishBeforeStoppingTipText
public String finishBeforeStoppingTipText()
Returns the tip text for this property.- Specified by:
finishBeforeStoppingTipText
in interfaceAtomicExecution
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStoppingTimeout
public void setStoppingTimeout(int value)
Sets the timeout for waiting for the sub-flow to stop.- Specified by:
setStoppingTimeout
in interfaceAtomicExecution
- Parameters:
value
- timeout in milliseconds (<= 0 for infinity)
-
getStoppingTimeout
public int getStoppingTimeout()
Returns the timeout for waiting for the sub-flow to stop.- Specified by:
getStoppingTimeout
in interfaceAtomicExecution
- Returns:
- timeout in milliseconds (<= 0 for infinity)
-
stoppingTimeoutTipText
public String stoppingTimeoutTipText()
Returns the tip text for this property.- Specified by:
stoppingTimeoutTipText
in interfaceAtomicExecution
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStoppingWarningInterval
public void setStoppingWarningInterval(int value)
Sets the interval for outputting warnings if the sub-flow hasn't stopped yet (and no stopping timeout set).- Parameters:
value
- interval in milliseconds (<= 0 no warning)
-
getStoppingWarningInterval
public int getStoppingWarningInterval()
Returns the interval for outputting warnings if the sub-flow hasn't stopped yet (and no stopping timeout set).- Returns:
- interval in milliseconds (<= 0 no warning)
-
stoppingWarningIntervalTipText
public String stoppingWarningIntervalTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setBranches
public void setBranches(Actor[] value)
Sets the branches.- Parameters:
value
- the branches
-
getBranches
public Actor[] getBranches()
Returns the branches.- Returns:
- the branches
-
branchesTipText
public String branchesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setNumThreads
public void setNumThreads(int value)
Sets the number of threads to use for executing the branches.- Specified by:
setNumThreads
in interfaceThreadLimiter
- Parameters:
value
- the number of threads: -1 = # of CPUs/cores; 0/1 = sequential execution
-
getNumThreads
public int getNumThreads()
Returns the number of threads to use for executing the branches.- Specified by:
getNumThreads
in interfaceThreadLimiter
- Returns:
- the number of threads: -1 = # of CPUs/cores; 0/1 = sequential execution
-
numThreadsTipText
public String numThreadsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setCollectOutput
public void setCollectOutput(boolean value)
Whether to collect the output of the branches.- Parameters:
value
- true if to collect the output
-
getCollectOutput
public boolean getCollectOutput()
Returns whether the output of the branches is collected.- Returns:
- true if output collected
-
getCollectedOutput
public HashMap<Integer,Token> getCollectedOutput()
Returns the collected output from the branches, if any.- Returns:
- the collected output, null if not available
-
setUp
public String setUp()
Initializes the sub-actors for flow execution.- Specified by:
setUp
in interfaceActor
- Overrides:
setUp
in classAbstractControlActor
- Returns:
- null if everything is fine, otherwise error message
- See Also:
AbstractActor.reset()
-
getActorHandlerInfo
public ActorHandlerInfo getActorHandlerInfo()
Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.- Specified by:
getActorHandlerInfo
in interfaceActorHandler
- Specified by:
getActorHandlerInfo
in classAbstractControlActor
- Returns:
- the info
-
size
public int size()
Returns the size of the group.- Specified by:
size
in interfaceActorHandler
- Specified by:
size
in classAbstractControlActor
- Returns:
- the size
-
get
public Actor get(int index)
Returns the actor at the given position.- Specified by:
get
in interfaceActorHandler
- Specified by:
get
in classAbstractControlActor
- Parameters:
index
- the position- Returns:
- the actor
-
set
public String set(int index, Actor actor)
Sets the actor at the given position.- Specified by:
set
in interfaceActorHandler
- Specified by:
set
in classAbstractControlActor
- Parameters:
index
- the positionactor
- the actor to set at this position- Returns:
- null if everything is fine, otherwise the error
-
add
public String add(Actor actor)
Inserts the actor at the end.- Specified by:
add
in interfaceMutableActorHandler
- Parameters:
actor
- the actor to insert- Returns:
- null if everything is fine, otherwise the error
-
add
public String add(int index, Actor actor)
Inserts the actor at the given position.- Specified by:
add
in interfaceMutableActorHandler
- Parameters:
index
- the positionactor
- the actor to insert- Returns:
- null if everything is fine, otherwise the error
-
remove
public Actor remove(int index)
Removes the actor at the given position and returns the removed object.- Specified by:
remove
in interfaceMutableActorHandler
- Parameters:
index
- the position- Returns:
- the removed actor
-
removeAll
public void removeAll()
Removes all actors.- Specified by:
removeAll
in interfaceMutableActorHandler
-
indexOf
public int indexOf(String actor)
Returns the index of the actor.- Specified by:
indexOf
in interfaceActorHandler
- Specified by:
indexOf
in classAbstractControlActor
- Parameters:
actor
- the name of the actor to look for- Returns:
- the index of -1 if not found
-
backupState
protected Hashtable<String,Object> backupState()
Backs up the current state of the actor before update the variables.- Overrides:
backupState
in classAbstractActor
- Returns:
- the backup
- See Also:
AbstractActor.updateVariables()
,AbstractActor.restoreState(Hashtable)
-
restoreState
protected void restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.- Overrides:
restoreState
in classAbstractActor
- Parameters:
state
- the backup of the state to restore from- See Also:
AbstractActor.updateVariables()
,AbstractActor.backupState()
-
accepts
public Class[] accepts()
Returns the class that the consumer accepts.- Specified by:
accepts
in interfaceInputConsumer
- Returns:
- depends on the sub-branches
-
input
public void input(Token token)
The method that accepts the input token and then processes it.- Specified by:
input
in interfaceInputConsumer
- Parameters:
token
- the token to accept and process
-
hasInput
public boolean hasInput()
Returns whether an input token is currently present.- Specified by:
hasInput
in interfaceInputConsumer
- Returns:
- true if input token present
-
currentInput
public Token currentInput()
Returns the current input token, if any.- Specified by:
currentInput
in interfaceInputConsumer
- Returns:
- the input token, null if none present
-
checkBranch
protected String checkBranch(Actor branch)
Checks the sub-branch.- Parameters:
branch
- the branch to check- Returns:
- null if everything correct, otherwise the error message
-
check
public String check()
Checks whether all the connections are valid, i.e., the input and output types fit and whether the flow chain is connected properly.- Specified by:
check
in interfaceActorHandler
- Overrides:
check
in classAbstractControlActor
- Returns:
- null if everything is fine, otherwise the offending connection
-
hasGlobalTransformers
protected boolean hasGlobalTransformers()
Checks for global transformers that might get accessed by parallel threads.- Returns:
- true if the branch contains global transformers that are accessed by
-
executeParallel
protected String executeParallel()
Executes the branches in parallel.- Returns:
- null if everything is fine, otherwise error message
-
executeSequential
protected String executeSequential()
Executes the branches sequentially.- Returns:
- null if everything is fine, otherwise error message
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
flushExecution
public void flushExecution()
Stops the processing of tokens without stopping the flow.- Specified by:
flushExecution
in interfaceActorHandler
- Specified by:
flushExecution
in interfaceFlushable
- Overrides:
flushExecution
in classAbstractControlActor
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecution
in interfaceActor
- Specified by:
stopExecution
in interfaceStoppable
- Overrides:
stopExecution
in classAbstractControlActor
-
wrapUp
public void wrapUp()
Finishes up the execution.- Specified by:
wrapUp
in interfaceActor
- Overrides:
wrapUp
in classAbstractControlActor
-
-