Package adams.gui.scripting
Class ScriptingEngineThread
- java.lang.Object
-
- java.lang.Thread
-
- adams.gui.scripting.ScriptingEngineThread
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected LinkedBlockingQueue<ScriptingCommand>
m_Commands
the current command queue.protected AbstractScriptingEngine
m_Owner
the owning engine.protected boolean
m_Processing
whether any command is currently being processed.protected boolean
m_Running
whether the thread is running.-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description ScriptingEngineThread(AbstractScriptingEngine owner)
Initializes the thread.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(ScriptingCommand cmd)
Adds the command to the queue.void
clear()
Clears the queue of scripting commands.protected String
doProcess(ScriptingCommand cmd)
Executes the given command.AbstractScriptingEngine
getOwner()
Returns the owning scripting engine.boolean
isEmpty()
Returns whether there are no commands currently in the queue.boolean
isProcessing()
Returns whether a command is currently being processed.boolean
isRunning()
Returns whether the thread is still active and waits for commands to execute.protected void
postProcess(ScriptingCommand cmd, boolean success, String lastError)
Performs some postprocessing.protected void
preProcess(ScriptingCommand cmd)
Performs some preprocessing.void
run()
Executes the scripting commands.void
stopExecution()
Stops the execution of scripting commands.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
m_Owner
protected AbstractScriptingEngine m_Owner
the owning engine.
-
m_Commands
protected LinkedBlockingQueue<ScriptingCommand> m_Commands
the current command queue.
-
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
-
getOwner
public AbstractScriptingEngine getOwner()
Returns the owning scripting engine.- Returns:
- the owner
-
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 interfaceStoppable
-
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 executedsuccess
- true if successfully executedlastError
- the error, or null if none happened
-
-