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 Actor
m_Actor
the actor to execute.protected boolean
m_CleanUp
whether to clean up after execution, i.e., removing graphical output automatically.protected boolean
m_ForceExit
whether the force an exit after the flows were stopped.protected boolean
m_Headless
whether the execution is to be headless, i.e., no GUI components.protected String
m_Home
the directory to use as the project's home directory.protected BaseRegExp
m_Include
regular expression for including flows when traversing a directory.protected PlaceholderFile
m_Input
the flow file/dir with flows to execute.protected boolean
m_InterruptedByUser
whether the flow was interrupted by the user.protected Actor
m_LastActor
the last actor that was executed.protected boolean
m_NoExecute
whether to suppress flow execution, simply load/setUp/wrapUp instead.protected boolean
m_NonInteractive
whether the use non-interactive execution.protected boolean
m_Register
whether to register the flow.protected RemoteScriptingEngine
m_RemoteScriptingEngine
the remote command scripting engine.protected String
m_RemoteScriptingEngineCmdLine
the commandline of the remote scripting engine to use at startup time.protected Set<RemoteScriptingEngineUpdateListener>
m_RemoteScriptingEngineUpdateListeners
the listeners for changes to the remote scripting engine.protected AbstractShutdownHook
m_ShutdownHook
the shutdown hook.static String
METHOD_STOPALLENGINES
the 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 void
addRemoteScriptingEngine(RemoteScriptingEngine value)
Adds the scripting engine to execute.void
addRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Adds the listener for remote scripting engine changes.String
cleanUpTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.String
execute()
Executes the actor if possible.String
forceExitTipText()
Returns the tip text for this property.static FlowRunner
forCommandLine(String cmdline)
Instantiates the flow from the given commandline (i.e., classname and optional options).static FlowRunner
forName(String classname, String[] options)
Instantiates the flow runner with the given options.boolean
getForceExit()
Returns whether to force the process exit after flows were stopped.String
getHome()
Returns the directory to use as home directory instead of the automatically determined one.BaseRegExp
getInclude()
Returns the regular expression for matching flow files when traversing a directory.PlaceholderFile
getInput()
Returns the file (or directory with flows) to load the actor from.Actor
getLastActor()
Returns the instance of the last actor that was executed.boolean
getRegister()
Returns whether to register the flow with the running flows registry, making it visible to remote commands.RemoteScriptingEngine
getRemoteScriptingEngine()
Returns the current scripting engine if any.String
getRemoteScriptingEngineCmdLine()
Returns the commandline of the remote scripting engine to execute at startup time.AbstractShutdownHook
getShutdownHook()
Returns the shutdown hook to install/use.String
globalInfo()
Returns a string describing the object.String
headlessTipText()
Returns the tip text for this property.String
homeTipText()
Returns the tip text for this property.String
includeTipText()
Returns the tip text for this property.protected void
initialize()
Initializes the members.String
inputTipText()
Returns the tip text for this property.boolean
isCleanUp()
Returns whether to perform a clean up after the execution and remove graphical output.boolean
isHeadless()
Returns whether the actor is run in headless mode.boolean
isNoExecute()
Returns whether to suppress flow execution.boolean
isNonInteractive()
Returns whether to run the flow without interaction with the user.boolean
isPaused()
Returns whether the object is currently paused.static void
main(String[] args)
Runs the flow with the given options.String
noExecuteTipText()
Returns the tip text for this property.String
nonInteractiveTipText()
Returns the tip text for this property.void
notifyRemoteScriptingEngineUpdateListeners(RemoteScriptingEngineUpdateEvent e)
Notifies all listeners of remote scripting engine changes.void
pauseExecution()
Pauses the execution.String
registerTipText()
Returns the tip text for this property.String
remoteScriptingEngineCmdLineTipText()
Returns the tip text for this property.void
removeRemoteScriptingEngine(RemoteScriptingEngine value)
Removes the scripting engine (and stops it).void
removeRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Removes the listener for remote scripting engine changes.void
resumeExecution()
Resumes the execution.static void
runFlow(Class env, Class flow, String[] args)
Runs the flow runner from commandline.void
setCleanUp(boolean value)
Sets whether to clean up after execution, i.e., removing graphical output.void
setForceExit(boolean value)
Sets whether to force the process exit after flows were stopped.void
setHeadless(boolean value)
Sets whether the actor is to be run in headless mode, i.e., suppressing GUI components.void
setHome(String value)
Overrides the automatic detection of the project's home directory and uses the specified directory instead.void
setInclude(BaseRegExp value)
Sets the regular expression to match flow files against when traversing a directory.void
setInput(PlaceholderFile value)
Sets the file (or directory with flows) to load the actor from.void
setNoExecute(boolean value)
Sets whether to suppress flow execution.void
setNonInteractive(boolean value)
Sets whether to run the flow without interaction with the user.void
setRegister(boolean value)
Sets whether to register the flow with the running flows registry, making it visible to remote commands.void
setRemoteScriptingEngine(RemoteScriptingEngine value)
Sets the scripting engine to execute.void
setRemoteScriptingEngineCmdLine(String value)
Sets the commandline of the remote scripting engine to execute at startup time.void
setShutdownHook(AbstractShutdownHook value)
Sets the shutdown hook to install/use.String
shutdownHookTipText()
Returns the tip text for this property.void
stopExecution()
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:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in 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:
addRemoteScriptingEngine
in 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:
removeRemoteScriptingEngine
in 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:
setRemoteScriptingEngine
in 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:
getRemoteScriptingEngine
in 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:
addRemoteScriptingEngineUpdateListener
in interfaceRemoteScriptingEngineHandler
- Parameters:
l
- the listener
-
removeRemoteScriptingEngineUpdateListener
public void removeRemoteScriptingEngineUpdateListener(RemoteScriptingEngineUpdateListener l)
Removes the listener for remote scripting engine changes.- Specified by:
removeRemoteScriptingEngineUpdateListener
in 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:
pauseExecution
in interfacePausable
-
isPaused
public boolean isPaused()
Returns whether the object is currently paused.
-
resumeExecution
public void resumeExecution()
Resumes the execution.- Specified by:
resumeExecution
in interfacePausable
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecution
in 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
-
-