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 min-user-mode: Expert
-name <java.lang.String> (property: name) The name of the actor. default: Branch
-annotation <adams.core.base.BaseAnnotation> (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 execution at this level gets stopped in case this actor encounters an error; the error gets propagated; useful for critical actors. default: false min-user-mode: Expert
-silent <boolean> (property: silent) If enabled, then no errors are output in the console; Note: the enclosing actor handler must have this enabled as well. default: false min-user-mode: Expert
-finish-before-stopping <boolean> (property: finishBeforeStopping) If enabled, actor first finishes processing all data before stopping. default: false
-stopping-timeout <int> (property: stoppingTimeout) The timeout in milliseconds when waiting for actors to finish (<= 0 for infinity; see 'finishBeforeStopping'). default: -1 minimum: -1
-stopping-warning-interval <int> (property: stoppingWarningInterval) The interval in milliseconds to output logging warnings if the actors haven't stopped yet (and no stopping timeout set); no warning if <= 0. default: 10000 minimum: -1
-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 parallel execution; > 0: specific number of cores to use (capped by actual number of cores available, 1 = sequential execution); = 0: number of cores; < 0: number of free cores (eg -2 means 2 free cores; minimum of one core is used) default: 0
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringBACKUP_CURRENTthe key for storing the current token in the backup.protected intm_ActualNumThreadsthe actual number of threads to use.protected List<Actor>m_Branchesthe branches.protected HashMap<Integer,Token>m_CollectedOutputthe collected output.protected booleanm_CollectOutputwhether to collect the output of the branches.protected Tokenm_CurrentTokenthe token that gets passed on to all sub-branches.protected ExecutorServicem_Executorthe executor service to use for parallel execution.protected booleanm_FinishBeforeStoppingwhether to finish execution first before stopping.protected booleanm_HasCallableTransformerswhether the branch contains callable transformers somewhere or not.protected intm_NumThreadsthe number of threads to use for parallel execution.protected intm_StoppingTimeoutthe timeout in milliseconds for stopping in case of atomic execution (<= 0 is infinity).protected intm_StoppingWarningIntervalthe 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.Stringadd(int index, Actor actor)Inserts the actor at the given position.Stringadd(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.StringbranchesTipText()Returns the tip text for this property.Stringcheck()Checks whether all the connections are valid, i.e., the input and output types fit and whether the flow chain is connected properly.protected StringcheckBranch(Actor branch)Checks the sub-branch.TokencurrentInput()Returns the current input token, if any.voiddefineOptions()Adds options to the internal list of options.protected StringdoExecute()Executes the flow item.protected StringexecuteParallel()Executes the branches in parallel.protected StringexecuteSequential()Executes the branches sequentially.StringfinishBeforeStoppingTipText()Returns the tip text for this property.voidflushExecution()Stops the processing of tokens without stopping the flow.Actorget(int index)Returns the actor at the given position.ActorHandlerInfogetActorHandlerInfo()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.booleangetCollectOutput()Returns whether the output of the branches is collected.booleangetFinishBeforeStopping()Returns whether to finish processing before stopping execution.intgetNumThreads()Returns the number of threads to use for executing the branches.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.intgetStoppingTimeout()Returns the timeout for waiting for the sub-flow to stop.intgetStoppingWarningInterval()Returns the interval for outputting warnings if the sub-flow hasn't stopped yet (and no stopping timeout set).StringglobalInfo()Returns a string describing the object.protected booleanhasCallableTransformers()Checks for callable transformers that might get accessed by parallel threads.booleanhasInput()Returns whether an input token is currently present.intindexOf(String actor)Returns the index of the actor.protected voidinitialize()Initializes the members.voidinput(Token token)The method that accepts the input token and then processes it.StringnumThreadsTipText()Returns the tip text for this property.Actorremove(int index)Removes the actor at the given position and returns the removed object.voidremoveAll()Removes all actors.protected voidrestoreState(Hashtable<String,Object> state)Restores the state of the actor before the variables got updated.Stringset(int index, Actor actor)Sets the actor at the given position.voidsetBranches(Actor[] value)Sets the branches.voidsetCollectOutput(boolean value)Whether to collect the output of the branches.voidsetFinishBeforeStopping(boolean value)Sets whether to finish processing before stopping execution.voidsetNumThreads(int value)Sets the number of threads to use for executing the branches.voidsetStoppingTimeout(int value)Sets the timeout for waiting for the sub-flow to stop.voidsetStoppingWarningInterval(int value)Sets the interval for outputting warnings if the sub-flow hasn't stopped yet (and no stopping timeout set).StringsetUp()Initializes the sub-actors for flow execution.intsize()Returns the size of the group.voidstopExecution()Stops the execution.StringstoppingTimeoutTipText()Returns the tip text for this property.StringstoppingWarningIntervalTipText()Returns the tip text for this property.voidwrapUp()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_HasCallableTransformers
protected boolean m_HasCallableTransformers
whether the branch contains callable 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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractControlActor
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfoin interfaceActor- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin 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:
setFinishBeforeStoppingin interfaceAtomicExecution- Parameters:
value- if true then actor finishes processing first
-
getFinishBeforeStopping
public boolean getFinishBeforeStopping()
Returns whether to finish processing before stopping execution.- Specified by:
getFinishBeforeStoppingin interfaceAtomicExecution- Returns:
- true if actor finishes processing first
-
finishBeforeStoppingTipText
public String finishBeforeStoppingTipText()
Returns the tip text for this property.- Specified by:
finishBeforeStoppingTipTextin 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:
setStoppingTimeoutin 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:
getStoppingTimeoutin interfaceAtomicExecution- Returns:
- timeout in milliseconds (<= 0 for infinity)
-
stoppingTimeoutTipText
public String stoppingTimeoutTipText()
Returns the tip text for this property.- Specified by:
stoppingTimeoutTipTextin 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:
setNumThreadsin 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:
getNumThreadsin 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:
setUpin interfaceActor- Overrides:
setUpin 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:
getActorHandlerInfoin interfaceActorHandler- Specified by:
getActorHandlerInfoin classAbstractControlActor- Returns:
- the info
-
size
public int size()
Returns the size of the group.- Specified by:
sizein interfaceActorHandler- Specified by:
sizein classAbstractControlActor- Returns:
- the size
-
get
public Actor get(int index)
Returns the actor at the given position.- Specified by:
getin interfaceActorHandler- Specified by:
getin 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:
setin interfaceActorHandler- Specified by:
setin 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:
addin 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:
addin 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:
removein interfaceMutableActorHandler- Parameters:
index- the position- Returns:
- the removed actor
-
removeAll
public void removeAll()
Removes all actors.- Specified by:
removeAllin interfaceMutableActorHandler
-
indexOf
public int indexOf(String actor)
Returns the index of the actor.- Specified by:
indexOfin interfaceActorHandler- Specified by:
indexOfin 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:
backupStatein 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:
restoreStatein 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:
acceptsin 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:
inputin interfaceInputConsumer- Parameters:
token- the token to accept and process
-
hasInput
public boolean hasInput()
Returns whether an input token is currently present.- Specified by:
hasInputin interfaceInputConsumer- Returns:
- true if input token present
-
currentInput
public Token currentInput()
Returns the current input token, if any.- Specified by:
currentInputin 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:
checkin interfaceActorHandler- Overrides:
checkin classAbstractControlActor- Returns:
- null if everything is fine, otherwise the offending connection
-
hasCallableTransformers
protected boolean hasCallableTransformers()
Checks for callable 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:
doExecutein 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:
flushExecutionin interfaceActorHandler- Specified by:
flushExecutionin interfaceFlushable- Overrides:
flushExecutionin classAbstractControlActor
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecutionin interfaceActor- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractControlActor
-
wrapUp
public void wrapUp()
Finishes up the execution.- Specified by:
wrapUpin interfaceActor- Overrides:
wrapUpin classAbstractControlActor
-
-