Package edu.wisc.ssec.mcidasv.jython
Class Runner
java.lang.Object
java.lang.Thread
edu.wisc.ssec.mcidasv.jython.Runner
- All Implemented Interfaces:
Runnable
This class represents a specialized
Thread
that creates and executes
Commands
. A BlockingQueue
is used to maintain
thread safety and to cause a Runner
to wait when the queue is at
capacity or has no Commands
to execute.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Console
Console
that created thisRunner
instance.private final Interpreter
The Jython interpreter that will actually run the queued commands.private boolean
Not in use yet.private static final org.slf4j.Logger
private final BlockingQueue
<Command> Queue ofCommands
awaiting execution.private static final int
The maximum number ofCommands
that can be queued.private final OutputStreamDemux
Acts like a global error stream that redirects data to whicheverConsole
matches the current thread name.private final OutputStreamDemux
Acts like a global output stream that redirects data to whicheverConsole
matches the current thread name.private final org.python.core.PySystemState
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) org.python.core.PyStringMap
Fetches, copies, and returns theinterpreter
's local namespace.void
queueBatch
(String source, List<String> batch) Queues up a series of Jython statements.private void
queueCommand
(Command command) Queues up a command for execution.void
Queues up a Jython file to be run byinterpreter
.void
Queues up a line of Jython for execution.void
queueObject
(String name, Object object) Queues the addition of an object tointerpreter
's local namespace.void
queueRemoval
(String name) Queues the removal of an object frominterpreter
's local namespace.void
run()
Takes commands out of the queue and executes them.(package private) void
setCallbackHandler
(ConsoleCallback newCallback) Registers a new callback handler.toString()
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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, yield
-
Field Details
-
logger
-
QUEUE_CAPACITY
The maximum number ofCommands
that can be queued.- See Also:
-
STD_OUT
Acts like a global output stream that redirects data to whicheverConsole
matches the current thread name. -
STD_ERR
Acts like a global error stream that redirects data to whicheverConsole
matches the current thread name. -
queue
Queue ofCommands
awaiting execution. -
console
Console
that created thisRunner
instance. -
systemState
-
interpreter
The Jython interpreter that will actually run the queued commands. -
interrupted
Not in use yet.
-
-
Constructor Details
-
Runner
Creates a new "console runner thread" for a givenConsole
.- Parameters:
console
-Console
responsible for adding user input and displaying output. Cannot benull
.
-
Runner
Creates a new "console runner thread" for a givenConsole
and supplies aList
of initial "commands" to be executed.- Parameters:
console
-Console
responsible for adding user input and displaying output. Cannot benull
.commands
- Lines to be run right away. Cannot benull
.
-
-
Method Details
-
setCallbackHandler
Registers a new callback handler. Currently this only forwards the new handler toInterpreter.setCallbackHandler(ConsoleCallback)
.- Parameters:
newCallback
- The callback handler to register.
-
copyLocals
org.python.core.PyStringMap copyLocals()Fetches, copies, and returns theinterpreter
's local namespace.- Returns:
- Copy of the interpreter's local namespace.
-
run
Takes commands out of the queue and executes them. We get a lot of mileage out of BlockingQueue; it's thread-safe and will block if the queue is at capacity or empty.Please note that this method needs to be the first method that gets called after creating a
Runner
. -
queueBatch
Queues up a series of Jython statements. Currently each command is treated as though the current user just entered it; the command appears in the input along with whatever output the command generates.- Parameters:
source
- Batched command source. Anything but null is acceptable.batch
- The actual commands to execute.
-
queueLine
Queues up a line of Jython for execution.- Parameters:
line
- Text of the command.
-
queueObject
Queues the addition of an object tointerpreter
's local namespace.- Parameters:
name
- Object name as it will appear tointerpreter
.object
- Object to put ininterpreter
's local namespace.
-
queueRemoval
Queues the removal of an object frominterpreter
's local namespace.- Parameters:
name
- Name of the object to be removed, as it appears to Jython.- See Also:
-
queueFile
Queues up a Jython file to be run byinterpreter
.- Parameters:
name
-__name__
attribute to use for loadingpath
.path
- The path to the Jython file.
-
queueCommand
Queues up a command for execution.- Parameters:
command
- Command to place in the execution queue.
-
toString
-