Package adams.flow.control
Class AbstractTee
-
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,Pausable
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,FlowPauseStateListener
,VariableChangeListener
,AtomicExecution
,Actor
,ActorHandler
,ControlActor
,ErrorHandler
,Flushable
,InputConsumer
,MutableActorHandler
,OutputProducer
,SubFlowWrapUp
,Serializable
,Comparable
- Direct Known Subclasses:
RemoteExecutionTrigger
,Tee
,Trigger
public abstract class AbstractTee extends AbstractControlActor implements InputConsumer, OutputProducer, MutableActorHandler, AtomicExecution
Abstract ancestor for actors that tee-off tokens.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractTee.TeeSwingWorker
SwingWorker for asynchronous execution of the tee's sub-actors.
-
Field Summary
Fields Modifier and Type Field Description static String
BACKUP_INPUT
the key for storing the input token in the backup.protected Sequence
m_Actors
the flow items.protected boolean
m_Asynchronous
whether to execute sub-actors asynchronously.protected AbstractTee.TeeSwingWorker
m_AsynchronousWorker
the swingworker in use for asynchronous execution.protected Token
m_InputToken
the input token.protected int
m_MinimumActiveActors
the minimum active actors this handler requires.protected Token
m_OutputToken
the output token.-
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
-
-
Constructor Summary
Constructors Constructor Description AbstractTee()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Class[]
accepts()
Returns the class that the consumer accepts.String
actorsTipText()
Returns the tip text for this property.String
add(int index, Actor actor)
Inserts the actor at the given position.String
add(Actor actor)
Inserts the actor at the end.String
asynchronousTipText()
Returns the tip text for this property.protected Hashtable<String,Object>
backupState()
Backs up the current state of the actor before update the variables.protected boolean
canProcessInput(Token token)
Returns whether the token can be processed in the tee actor.String
check()
Performs checks on the "sub-actors".protected abstract String
checkTeeActor(int index, Actor actor)
Checks the tee actor before it is set.protected abstract String
checkTeeActors(Actor[] actors)
Checks the tee actors before they are set via the setTeeActors method.void
cleanUp()
Cleans up after the execution has finished.protected Token
createTeeToken(Token token)
Creates the token to tee-off.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.String
execute()
Executes the flow item.String
finishBeforeStoppingTipText()
Returns the tip text for this property.protected void
finishedAsynchronousExecution()
Called by the asynchronous swingworker when finished.void
flushExecution()
Stops the processing of tokens without stopping the flow.protected void
forceVariables(Variables value)
Updates the Variables instance in use.Class[]
generates()
Returns the class of objects that it generates.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[]
getActors()
Returns the actors to tee-off to.boolean
getAsynchronous()
Returns whether to finish processing before stopping execution.boolean
getFinishBeforeStopping()
Returns whether to finish processing before stopping execution.protected Sequence
getInternalActors()
Returns the internal representation of the actors.int
getMinimumActiveActors()
Returns the minimum of (active) actors that need to be present in the tee branch.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.boolean
hasInput()
Returns whether an input token is currently present.boolean
hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.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.Token
output()
Returns the generated token.protected String
processInput(Token token)
Processes the token normal, i.e., not in thread.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
setActors(Actor[] value)
Sets the actor to tee-off to.void
setAsynchronous(boolean value)
Sets whether to finish processing before stopping execution.void
setFinishBeforeStopping(boolean value)
Sets whether to finish processing before stopping execution.void
setLoggingLevel(LoggingLevel value)
Sets the logging level.void
setMinimumActiveActors(int value)
Sets the minimum of (active) actors that need to be present in the tee branch.void
setSkip(boolean value)
Sets whether the transformation is skipped or not.void
setStoppingTimeout(int value)
Sets the timeout for waiting for the sub-flow to stop.protected String
setUpSubActors()
Performs the setUp of the sub-actors.protected abstract String
setUpTeeActors()
Gets called in the setUp() method.int
size()
Returns the size of the group.void
stopExecution()
Stops the execution.String
stoppingTimeoutTipText()
Returns the tip text for this property.protected void
updateParent()
Updates the parent of all actors in this group.protected void
waitForAsynchronousExecution()
Waits for the asynchronous execution to finish.void
wrapUp()
Finishes up the execution.-
Methods inherited from class adams.flow.control.AbstractControlActor
active, canInspectOptions, destroy, firstActive, firstInputConsumer, flowPauseStateChanged, isPaused, isSubFlowWrappedUp, lastActive, pauseExecution, preExecute, reset, resumeExecution, setParent, setUp, wrapUpSubFlow
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canPerformSetUpCheck, compareTo, configureLogger, equals, 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, 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, globalInfo, loggingLevelTipText, newOptionManager, 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
compareTo, destroy, equals, 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, setStopFlowOnError, setUp, 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
-
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_INPUT
public static final String BACKUP_INPUT
the key for storing the input token in the backup.- See Also:
- Constant Field Values
-
m_Actors
protected Sequence m_Actors
the flow items.
-
m_InputToken
protected transient Token m_InputToken
the input token.
-
m_OutputToken
protected transient Token m_OutputToken
the output token.
-
m_MinimumActiveActors
protected int m_MinimumActiveActors
the minimum active actors this handler requires.
-
m_Asynchronous
protected boolean m_Asynchronous
whether to execute sub-actors asynchronously.
-
m_AsynchronousWorker
protected AbstractTee.TeeSwingWorker m_AsynchronousWorker
the swingworker in use for asynchronous execution.
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractControlActor
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Specified by:
setLoggingLevel
in interfaceLoggingLevelHandler
- Overrides:
setLoggingLevel
in classAbstractOptionHandler
- Parameters:
value
- the level
-
setSkip
public void setSkip(boolean value)
Sets whether the transformation is skipped or not.- Specified by:
setSkip
in interfaceActor
- Overrides:
setSkip
in classAbstractActor
- Parameters:
value
- true if transformation is to be skipped
-
check
public String check()
Performs checks on the "sub-actors".- Specified by:
check
in interfaceActorHandler
- Overrides:
check
in classAbstractControlActor
- Returns:
- null if checks passed or null in case of an error
-
checkTeeActor
protected abstract String checkTeeActor(int index, Actor actor)
Checks the tee actor before it is set. Returns an error message if the actor is not acceptable, null otherwise.- Parameters:
index
- the index the actor gets setactor
- the actor to check- Returns:
- null if accepted, otherwise error message
-
checkTeeActors
protected abstract String checkTeeActors(Actor[] actors)
Checks the tee actors before they are set via the setTeeActors method. Returns an error message if the actors are not acceptable, null otherwise.- Parameters:
actors
- the actors to check- Returns:
- null if accepted, otherwise error message
-
setActors
public void setActors(Actor[] value)
Sets the actor to tee-off to.- Parameters:
value
- the actor
-
getActors
public Actor[] getActors()
Returns the actors to tee-off to.- Returns:
- the actors
-
actorsTipText
public String actorsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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.
-
setAsynchronous
public void setAsynchronous(boolean value)
Sets whether to finish processing before stopping execution.- Parameters:
value
- if true then actor finishes processing first
-
getAsynchronous
public boolean getAsynchronous()
Returns whether to finish processing before stopping execution.- Returns:
- true if actor finishes processing first
-
asynchronousTipText
public String asynchronousTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
updateParent
protected void updateParent()
Updates the parent of all actors in this group.- Overrides:
updateParent
in classAbstractControlActor
-
forceVariables
protected void forceVariables(Variables value)
Updates the Variables instance in use.
Use with caution!- Overrides:
forceVariables
in classAbstractControlActor
- Parameters:
value
- the instance to use
-
size
public int size()
Returns the size of the group.- Specified by:
size
in interfaceActorHandler
- Specified by:
size
in classAbstractControlActor
- Returns:
- always 1
-
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
- See Also:
checkTeeActor(int, Actor)
-
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
-
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
- See Also:
checkTeeActor(int, Actor)
-
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
-
getInternalActors
protected Sequence getInternalActors()
Returns the internal representation of the actors.- Returns:
- the internal actors
-
finishedAsynchronousExecution
protected void finishedAsynchronousExecution()
Called by the asynchronous swingworker when finished.
-
waitForAsynchronousExecution
protected void waitForAsynchronousExecution()
Waits for the asynchronous execution to finish.
-
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
-
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
-
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:
- adams.flow.core.Unknown.class
-
setUpTeeActors
protected abstract String setUpTeeActors()
Gets called in the setUp() method. Returns null if tee-actors are fine, otherwise error message.- Returns:
- null if everything OK, otherwise error message
-
setMinimumActiveActors
public void setMinimumActiveActors(int value)
Sets the minimum of (active) actors that need to be present in the tee branch.- Parameters:
value
- the required minimum of actors
-
getMinimumActiveActors
public int getMinimumActiveActors()
Returns the minimum of (active) actors that need to be present in the tee branch.- Returns:
- the required minimum of actors
-
setUpSubActors
protected String setUpSubActors()
Performs the setUp of the sub-actors.- Overrides:
setUpSubActors
in classAbstractControlActor
- Returns:
- null if everything is fine, otherwise error message
-
createTeeToken
protected Token createTeeToken(Token token)
Creates the token to tee-off.- Parameters:
token
- the input token- Returns:
- the token to tee-off
-
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
-
canProcessInput
protected boolean canProcessInput(Token token)
Returns whether the token can be processed in the tee actor.- Parameters:
token
- the token to process- Returns:
- true if token can be processed
-
processInput
protected String processInput(Token token)
Processes the token normal, i.e., not in thread.- Parameters:
token
- the token to process- Returns:
- an optional error message, null if everything OK
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
execute
public String execute()
Executes the flow item.- Specified by:
execute
in interfaceActor
- Overrides:
execute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Specified by:
generates
in interfaceOutputProducer
- Returns:
- adams.flow.core.Unknown.class
-
output
public Token output()
Returns the generated token.- Specified by:
output
in interfaceOutputProducer
- Returns:
- the generated token
-
hasPendingOutput
public boolean hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.- Specified by:
hasPendingOutput
in interfaceOutputProducer
- Returns:
- true if there is pending output
-
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.- 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
-
cleanUp
public void cleanUp()
Cleans up after the execution has finished. Also removes graphical components.- Specified by:
cleanUp
in interfaceActor
- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractControlActor
-
-