Class ScriptingEngineThread

  • All Implemented Interfaces:
    Stoppable, Runnable

    public class ScriptingEngineThread
    extends Thread
    implements Stoppable
    A class for processing the scripting commands.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • m_Running

        protected boolean m_Running
        whether the thread is running.
      • m_Processing

        protected boolean m_Processing
        whether any command is currently being processed.
    • Constructor Detail

      • ScriptingEngineThread

        public ScriptingEngineThread​(AbstractScriptingEngine owner)
        Initializes the thread.
        Parameters:
        owner - the owning scripting engine
    • Method Detail

      • clear

        public void clear()
        Clears the queue of scripting commands.
      • add

        public void add​(ScriptingCommand cmd)
        Adds the command to the queue.
        Parameters:
        cmd - the command to add
      • stopExecution

        public void stopExecution()
        Stops the execution of scripting commands.
        Specified by:
        stopExecution in interface Stoppable
      • isRunning

        public boolean isRunning()
        Returns whether the thread is still active and waits for commands to execute.
        Returns:
        true if accepting commands to process
      • isProcessing

        public boolean isProcessing()
        Returns whether a command is currently being processed.
        Returns:
        true if a command is being processed
      • isEmpty

        public boolean isEmpty()
        Returns whether there are no commands currently in the queue.
        Returns:
        true if no commands waiting to be executed
      • preProcess

        protected void preProcess​(ScriptingCommand cmd)
        Performs some preprocessing.
        Parameters:
        cmd - the command that is about to be executed
      • doProcess

        protected String doProcess​(ScriptingCommand cmd)
                            throws Exception
        Executes the given command.
        Parameters:
        cmd - the command to execute
        Returns:
        the error message, null if no problems occurred
        Throws:
        Exception - if execution fails
      • postProcess

        protected void postProcess​(ScriptingCommand cmd,
                                   boolean success,
                                   String lastError)
        Performs some postprocessing.
        Parameters:
        cmd - the command that was executed
        success - true if successfully executed
        lastError - the error, or null if none happened
      • run

        public void run()
        Executes the scripting commands.
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread