Package adams.flow
Class FlowRunner
-
- All Implemented Interfaces:
Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,Pausable,SizeOfHandler,Stoppable,RemoteScriptingEngineHandler,Serializable
public class FlowRunner extends AbstractOptionHandler implements Stoppable, Pausable, RemoteScriptingEngineHandler
Executes flows from command-line.
It is also possible to traverse a directory and execute all flows within that match a regular expression.
Using the 'no-execute' option, you can suppress the flow execution, but still test whether the flow loads and can be fully set up and wrapped up.
-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
-home <java.lang.String> (property: home) The directory to use as the project's home directory, overriding the automatically determined one. default:
-headless <boolean> (property: headless) If set to true, the actor is run in headless mode without GUI components. default: false
-non-interactive <boolean> (property: nonInteractive) If set to true, interactive actors suppress their interaction with the user. default: false
-register <boolean> (property: register) If set to true, the flow gets register with the 'running flows registry', making it visible to remote commands. default: false
-input <adams.core.io.PlaceholderFile> (property: input) The file (or directory containing flows) to load the actor from. default: ${CWD}-include <adams.core.base.BaseRegExp> (property: include) The regular expression for including flows when traversing a directory rather than just executing a single flow. default: .*\\\\.(flow|flow.gz) more: https://docs.oracle.com/javase/tutorial/essential/regex/ https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
-clean-up <boolean> (property: cleanUp) If set to true, then a clean up is performed after execution, removing any graphical output as well. default: false
-no-execute <boolean> (property: noExecute) If set to true, then flow execution is suppressed; flow is only loaded, set up and wrapped up. default: false
-remote-scripting-engine-cmdline <java.lang.String> (property: remoteScriptingEngineCmdLine) The command-line of the remote scripting engine to execute at startup time; use empty string for disable scripting. default:
-shutdown-hook <adams.core.shutdown.AbstractShutdownHook> (property: shutdownHook) The shutdown hook to use. default: adams.core.shutdown.Null
-force-exit <boolean> (property: forceExit) If set to true, then the runner will trigger a System.exit call to forcefully exit the process. default: false
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Actorm_Actorthe actor to execute.protected booleanm_CleanUpwhether to clean up after execution, i.e., removing graphical output automatically.protected booleanm_ForceExitwhether the force an exit after the flows were stopped.protected booleanm_Headlesswhether the execution is to be headless, i.e., no GUI components.protected Stringm_Homethe directory to use as the project's home directory.protected BaseRegExpm_Includeregular expression for including flows when traversing a directory.protected PlaceholderFilem_Inputthe flow file/dir with flows to execute.protected booleanm_InterruptedByUserwhether the flow was interrupted by the user.protected Actorm_LastActorthe last actor that was executed.protected booleanm_NoExecutewhether to suppress flow execution, simply load/setUp/wrapUp instead.protected booleanm_NonInteractivewhether the use non-interactive execution.protected booleanm_Registerwhether to register the flow.protected RemoteScriptingEnginem_RemoteScriptingEnginethe remote command scripting engine.protected Stringm_RemoteScriptingEngineCmdLinethe commandline of the remote scripting engine to use at startup time.protected Set<RemoteScriptingEngineUpdateListener>m_RemoteScriptingEngineUpdateListenersthe listeners for changes to the remote scripting engine.protected AbstractShutdownHookm_ShutdownHookthe shutdown hook.static StringMETHOD_STOPALLENGINESthe method for stopping all engines.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description FlowRunner()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRemoteScriptingEngine(RemoteScriptingEngine value)Adds the scripting engine to execute.voidaddRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)Adds the listener for remote scripting engine changes.StringcleanUpTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.Stringexecute()Executes the actor if possible.StringforceExitTipText()Returns the tip text for this property.static FlowRunnerforCommandLine(String cmdline)Instantiates the flow from the given commandline (i.e., classname and optional options).static FlowRunnerforName(String classname, String[] options)Instantiates the flow runner with the given options.booleangetForceExit()Returns whether to force the process exit after flows were stopped.StringgetHome()Returns the directory to use as home directory instead of the automatically determined one.BaseRegExpgetInclude()Returns the regular expression for matching flow files when traversing a directory.PlaceholderFilegetInput()Returns the file (or directory with flows) to load the actor from.ActorgetLastActor()Returns the instance of the last actor that was executed.booleangetRegister()Returns whether to register the flow with the running flows registry, making it visible to remote commands.RemoteScriptingEnginegetRemoteScriptingEngine()Returns the current scripting engine if any.StringgetRemoteScriptingEngineCmdLine()Returns the commandline of the remote scripting engine to execute at startup time.AbstractShutdownHookgetShutdownHook()Returns the shutdown hook to install/use.StringglobalInfo()Returns a string describing the object.StringheadlessTipText()Returns the tip text for this property.StringhomeTipText()Returns the tip text for this property.StringincludeTipText()Returns the tip text for this property.protected voidinitialize()Initializes the members.StringinputTipText()Returns the tip text for this property.booleanisCleanUp()Returns whether to perform a clean up after the execution and remove graphical output.booleanisHeadless()Returns whether the actor is run in headless mode.booleanisNoExecute()Returns whether to suppress flow execution.booleanisNonInteractive()Returns whether to run the flow without interaction with the user.booleanisPaused()Returns whether the object is currently paused.static voidmain(String[] args)Runs the flow with the given options.StringnoExecuteTipText()Returns the tip text for this property.StringnonInteractiveTipText()Returns the tip text for this property.voidnotifyRemoteScriptingEngineUpdateListeners(RemoteScriptingEngineUpdateEvent e)Notifies all listeners of remote scripting engine changes.voidpauseExecution()Pauses the execution.StringregisterTipText()Returns the tip text for this property.StringremoteScriptingEngineCmdLineTipText()Returns the tip text for this property.voidremoveRemoteScriptingEngine(RemoteScriptingEngine value)Removes the scripting engine (and stops it).voidremoveRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)Removes the listener for remote scripting engine changes.voidresumeExecution()Resumes the execution.static voidrunFlow(Class env, Class flow, String[] args)Runs the flow runner from commandline.voidsetCleanUp(boolean value)Sets whether to clean up after execution, i.e., removing graphical output.voidsetForceExit(boolean value)Sets whether to force the process exit after flows were stopped.voidsetHeadless(boolean value)Sets whether the actor is to be run in headless mode, i.e., suppressing GUI components.voidsetHome(String value)Overrides the automatic detection of the project's home directory and uses the specified directory instead.voidsetInclude(BaseRegExp value)Sets the regular expression to match flow files against when traversing a directory.voidsetInput(PlaceholderFile value)Sets the file (or directory with flows) to load the actor from.voidsetNoExecute(boolean value)Sets whether to suppress flow execution.voidsetNonInteractive(boolean value)Sets whether to run the flow without interaction with the user.voidsetRegister(boolean value)Sets whether to register the flow with the running flows registry, making it visible to remote commands.voidsetRemoteScriptingEngine(RemoteScriptingEngine value)Sets the scripting engine to execute.voidsetRemoteScriptingEngineCmdLine(String value)Sets the commandline of the remote scripting engine to execute at startup time.voidsetShutdownHook(AbstractShutdownHook value)Sets the shutdown hook to install/use.StringshutdownHookTipText()Returns the tip text for this property.voidstopExecution()Stops the execution.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
METHOD_STOPALLENGINES
public static final String METHOD_STOPALLENGINES
the method for stopping all engines.- See Also:
- Constant Field Values
-
m_Input
protected PlaceholderFile m_Input
the flow file/dir with flows to execute.
-
m_Include
protected BaseRegExp m_Include
regular expression for including flows when traversing a directory.
-
m_Headless
protected boolean m_Headless
whether the execution is to be headless, i.e., no GUI components.
-
m_NonInteractive
protected boolean m_NonInteractive
whether the use non-interactive execution.
-
m_Register
protected boolean m_Register
whether to register the flow.
-
m_Home
protected String m_Home
the directory to use as the project's home directory.
-
m_NoExecute
protected boolean m_NoExecute
whether to suppress flow execution, simply load/setUp/wrapUp instead.
-
m_CleanUp
protected boolean m_CleanUp
whether to clean up after execution, i.e., removing graphical output automatically.
-
m_RemoteScriptingEngineCmdLine
protected String m_RemoteScriptingEngineCmdLine
the commandline of the remote scripting engine to use at startup time.
-
m_RemoteScriptingEngine
protected RemoteScriptingEngine m_RemoteScriptingEngine
the remote command scripting engine.
-
m_ShutdownHook
protected AbstractShutdownHook m_ShutdownHook
the shutdown hook.
-
m_ForceExit
protected boolean m_ForceExit
whether the force an exit after the flows were stopped.
-
m_RemoteScriptingEngineUpdateListeners
protected Set<RemoteScriptingEngineUpdateListener> m_RemoteScriptingEngineUpdateListeners
the listeners for changes to the remote scripting engine.
-
m_Actor
protected Actor m_Actor
the actor to execute.
-
m_LastActor
protected Actor m_LastActor
the last actor that was executed.
-
m_InterruptedByUser
protected boolean m_InterruptedByUser
whether the flow was interrupted by the user.
-
-
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
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractOptionHandler
-
setHome
public void setHome(String value)
Overrides the automatic detection of the project's home directory and uses the specified directory instead. No placeholders allowed, should be absolute.- Parameters:
value- the directory to use
-
getHome
public String getHome()
Returns the directory to use as home directory instead of the automatically determined one.- Returns:
- the directory to use
-
homeTipText
public String homeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setHeadless
public void setHeadless(boolean value)
Sets whether the actor is to be run in headless mode, i.e., suppressing GUI components.- Parameters:
value- if true then GUI components will be suppressed
-
isHeadless
public boolean isHeadless()
Returns whether the actor is run in headless mode.- Returns:
- true if GUI components are suppressed
-
headlessTipText
public String headlessTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setNonInteractive
public void setNonInteractive(boolean value)
Sets whether to run the flow without interaction with the user.- Parameters:
value- if true then interactive actors get suppressed
-
isNonInteractive
public boolean isNonInteractive()
Returns whether to run the flow without interaction with the user.- Returns:
- true if interactive actors get suppressed
-
nonInteractiveTipText
public String nonInteractiveTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRegister
public void setRegister(boolean value)
Sets whether to register the flow with the running flows registry, making it visible to remote commands.- Parameters:
value- true if to register
-
getRegister
public boolean getRegister()
Returns whether to register the flow with the running flows registry, making it visible to remote commands.- Returns:
- true if to register
-
registerTipText
public String registerTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setInput
public void setInput(PlaceholderFile value)
Sets the file (or directory with flows) to load the actor from.- Parameters:
value- the file/dir
-
getInput
public PlaceholderFile getInput()
Returns the file (or directory with flows) to load the actor from.- Returns:
- the file/dir
-
inputTipText
public String inputTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setInclude
public void setInclude(BaseRegExp value)
Sets the regular expression to match flow files against when traversing a directory.- Parameters:
value- the regular expression
-
getInclude
public BaseRegExp getInclude()
Returns the regular expression for matching flow files when traversing a directory.- Returns:
- the regular expression
-
includeTipText
public String includeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setCleanUp
public void setCleanUp(boolean value)
Sets whether to clean up after execution, i.e., removing graphical output.- Parameters:
value- if true then a clean up is performed after execution
-
isCleanUp
public boolean isCleanUp()
Returns whether to perform a clean up after the execution and remove graphical output.- Returns:
- true if clean up is performed after execution
-
cleanUpTipText
public String cleanUpTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setNoExecute
public void setNoExecute(boolean value)
Sets whether to suppress flow execution.- Parameters:
value- if true then no execution
-
isNoExecute
public boolean isNoExecute()
Returns whether to suppress flow execution.- Returns:
- true if no execution
-
noExecuteTipText
public String noExecuteTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRemoteScriptingEngineCmdLine
public void setRemoteScriptingEngineCmdLine(String value)
Sets the commandline of the remote scripting engine to execute at startup time.- Parameters:
value- the commandline, use empty string if not to use one
-
getRemoteScriptingEngineCmdLine
public String getRemoteScriptingEngineCmdLine()
Returns the commandline of the remote scripting engine to execute at startup time.- Returns:
- the commandline, empty string it not to use one
-
remoteScriptingEngineCmdLineTipText
public String remoteScriptingEngineCmdLineTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setShutdownHook
public void setShutdownHook(AbstractShutdownHook value)
Sets the shutdown hook to install/use.- Parameters:
value- the hook
-
getShutdownHook
public AbstractShutdownHook getShutdownHook()
Returns the shutdown hook to install/use.- Returns:
- the hook
-
shutdownHookTipText
public String shutdownHookTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setForceExit
public void setForceExit(boolean value)
Sets whether to force the process exit after flows were stopped.- Parameters:
value- if true then force exit
-
getForceExit
public boolean getForceExit()
Returns whether to force the process exit after flows were stopped.- Returns:
- true if to force exit
-
forceExitTipText
public String forceExitTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
addRemoteScriptingEngine
public void addRemoteScriptingEngine(RemoteScriptingEngine value)
Adds the scripting engine to execute. Doesn't stop any running engines.- Specified by:
addRemoteScriptingEnginein interfaceRemoteScriptingEngineHandler- Parameters:
value- the engine to add
-
removeRemoteScriptingEngine
public void removeRemoteScriptingEngine(RemoteScriptingEngine value)
Removes the scripting engine (and stops it). Doesn't stop any running engines.- Specified by:
removeRemoteScriptingEnginein interfaceRemoteScriptingEngineHandler- Parameters:
value- the engine to remove
-
setRemoteScriptingEngine
public void setRemoteScriptingEngine(RemoteScriptingEngine value)
Sets the scripting engine to execute. Any running engine is stopped first.- Specified by:
setRemoteScriptingEnginein interfaceRemoteScriptingEngineHandler- Parameters:
value- the engine to use, null to turn off scripting
-
getRemoteScriptingEngine
public RemoteScriptingEngine getRemoteScriptingEngine()
Returns the current scripting engine if any.- Specified by:
getRemoteScriptingEnginein interfaceRemoteScriptingEngineHandler- Returns:
- the engine in use, null if none running
-
addRemoteScriptingEngineUpdateListener
public void addRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Adds the listener for remote scripting engine changes.- Specified by:
addRemoteScriptingEngineUpdateListenerin interfaceRemoteScriptingEngineHandler- Parameters:
l- the listener
-
removeRemoteScriptingEngineUpdateListener
public void removeRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Removes the listener for remote scripting engine changes.- Specified by:
removeRemoteScriptingEngineUpdateListenerin interfaceRemoteScriptingEngineHandler- Parameters:
l- the listener
-
notifyRemoteScriptingEngineUpdateListeners
public void notifyRemoteScriptingEngineUpdateListeners(RemoteScriptingEngineUpdateEvent e)
Notifies all listeners of remote scripting engine changes.- Parameters:
e- the event to send
-
getLastActor
public Actor getLastActor()
Returns the instance of the last actor that was executed.- Returns:
- the actor or null if no actor has been run yet
-
execute
public String execute()
Executes the actor if possible.- Returns:
- the error if one occurred, otherwise null (= everything OK)
-
pauseExecution
public void pauseExecution()
Pauses the execution.- Specified by:
pauseExecutionin interfacePausable
-
isPaused
public boolean isPaused()
Returns whether the object is currently paused.
-
resumeExecution
public void resumeExecution()
Resumes the execution.- Specified by:
resumeExecutionin interfacePausable
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecutionin interfaceStoppable
-
forName
public static FlowRunner forName(String classname, String[] options)
Instantiates the flow runner with the given options.- Parameters:
classname- the classname of the flow runner to instantiateoptions- the options for the flow- Returns:
- the instantiated flow or null if an error occurred
-
forCommandLine
public static FlowRunner forCommandLine(String cmdline)
Instantiates the flow from the given commandline (i.e., classname and optional options).- Parameters:
cmdline- the classname (and optional options) of the flow to instantiate- Returns:
- the instantiated flow or null if an error occurred
-
runFlow
public static void runFlow(Class env, Class flow, String[] args)
Runs the flow runner from commandline.- Parameters:
env- the environment class to useflow- the flow runner class to executeargs- the commandline arguments, use -help to display all
-
main
public static void main(String[] args)
Runs the flow with the given options. Use "-f <file>" to supply a flow setup file to execute.- Parameters:
args- the options to use
-
-