public final class Runner extends java.lang.Thread
| Modifier and Type | Field and Description |
|---|---|
private Console |
console
Console that created this Runner instance. |
private Interpreter |
interpreter
The Jython interpreter that will actually run the queued commands.
|
private boolean |
interrupted
Not in use yet.
|
private static org.slf4j.Logger |
logger |
private java.util.concurrent.BlockingQueue<Command> |
queue
Queue of
Commands awaiting execution. |
private static int |
QUEUE_CAPACITY
The maximum number of
Commands that can be queued. |
private OutputStreamDemux |
STD_ERR
Acts like a global error stream that redirects data to whichever
Console matches the current thread name. |
private OutputStreamDemux |
STD_OUT
Acts like a global output stream that redirects data to whichever
Console matches the current thread name. |
private org.python.core.PySystemState |
systemState |
| Constructor and Description |
|---|
Runner(Console console)
Creates a new "console runner thread" for a given
Console. |
Runner(Console console,
java.util.List<java.lang.String> commands)
Creates a new "console runner thread" for a given
Console and supplies a List of initial
"commands" to be executed. |
| Modifier and Type | Method and Description |
|---|---|
(package private) org.python.core.PyStringMap |
copyLocals()
Fetches, copies, and returns the
interpreter's local namespace. |
void |
queueBatch(java.lang.String source,
java.util.List<java.lang.String> batch)
Queues up a series of Jython statements.
|
private void |
queueCommand(Command command)
Queues up a command for execution.
|
void |
queueFile(java.lang.String name,
java.lang.String path)
Queues up a Jython file to be run by
interpreter. |
void |
queueLine(java.lang.String line)
Queues up a line of Jython for execution.
|
void |
queueObject(java.lang.String name,
java.lang.Object object)
Queues the addition of an object to
interpreter's local
namespace. |
void |
queueRemoval(java.lang.String name)
Queues the removal of an object from
interpreter'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.
|
java.lang.String |
toString() |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yieldprivate static final org.slf4j.Logger logger
private static final int QUEUE_CAPACITY
Commands that can be queued.private final OutputStreamDemux STD_OUT
Console matches the current thread name.private final OutputStreamDemux STD_ERR
Console matches the current thread name.private final java.util.concurrent.BlockingQueue<Command> queue
Commands awaiting execution.private final org.python.core.PySystemState systemState
private final Interpreter interpreter
private boolean interrupted
public Runner(Console console)
Console.console - Console responsible for adding user input and
displaying output. Cannot be null.public Runner(Console console, java.util.List<java.lang.String> commands)
Console and supplies a List of initial
"commands" to be executed.console - Console responsible for adding user input and
displaying output. Cannot be null.commands - Lines to be run right away. Cannot be null.void setCallbackHandler(ConsoleCallback newCallback)
Interpreter.setCallbackHandler(ConsoleCallback).newCallback - The callback handler to register.org.python.core.PyStringMap copyLocals()
interpreter's local namespace.public void run()
Please note that this method needs to be the first method that
gets called after creating a Runner.
run in interface java.lang.Runnablerun in class java.lang.Threadpublic void queueBatch(java.lang.String source, java.util.List<java.lang.String> batch)
source - Batched command source. Anything but null is acceptable.batch - The actual commands to execute.public void queueLine(java.lang.String line)
line - Text of the command.public void queueObject(java.lang.String name, java.lang.Object object)
interpreter's local
namespace.name - Object name as it will appear to interpreter.object - Object to put in interpreter's local namespace.public void queueRemoval(java.lang.String name)
interpreter's local
namespace.name - Name of the object to be removed, as it appears to
Jython.queueObject(String, Object)public void queueFile(java.lang.String name, java.lang.String path)
interpreter.name - __name__ attribute to use for loading path.path - The path to the Jython file.private void queueCommand(Command command)
command - Command to place in the execution queue.public java.lang.String toString()
toString in class java.lang.Thread