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 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_ForceExit

        protected boolean m_ForceExit
        whether the force an exit after the flows were stopped.
      • 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.
    • Constructor Detail

      • FlowRunner

        public FlowRunner()
    • Method Detail

      • 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.
      • 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 interface Pausable
      • isPaused

        public boolean isPaused()
        Returns whether the object is currently paused.
        Specified by:
        isPaused in interface Pausable
        Returns:
        true if object is paused
      • resumeExecution

        public void resumeExecution()
        Resumes the execution.
        Specified by:
        resumeExecution in interface Pausable
      • stopExecution

        public void stopExecution()
        Stops the execution.
        Specified by:
        stopExecution in interface Stoppable
      • 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 instantiate
        options - 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 use
        flow - the flow runner class to execute
        args - 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