|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread info.rolandkrueger.roklib.cli.ConsoleThread
public class ConsoleThread
This is a class that provides a shell similar to those of programs like
gdb or bc. This class is running in a thread. It simply
reads one line after the other from an input stream and hands it over to a
given handler. This handler, which must implement the interface
CommandHandler
, can then process the command string. The input stream
from which the user commands are read and the output stream to which the
console's output is written are configurable. If these streams are not
specified they default to the standard input and standard ouput. Thus, it is
possible to read in commands from a Swing frame, for instance.
CommandHandler
,
ConsoleCommandObject
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
Thread.State, Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
private CommandHandler |
mCommandHandler
|
private String |
mGreetingMsg
|
private InputStream |
mInputStream
|
private PrintStream |
mOutput
|
private Object |
mPrompt
|
private BufferedReader |
mReader
|
private boolean |
mShutdownRequested
|
private static Logger |
sLogger
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
private |
ConsoleThread()
Default constructor. |
|
ConsoleThread(CommandHandler handler,
String greetingMsg,
Object prompt,
OutputStream outStream,
InputStream inStream)
Constructs a new command console with configurable input and output streams. |
|
ConsoleThread(CommandHandler handler,
String greetingMsg,
String prompt)
Constructs a new command console with stdin and stdout as the default input and output streams. |
Method Summary | |
---|---|
InputStream |
getInputStream()
Returns the input stream from which the user's input is read from. |
OutputStream |
getOutputStream()
Returns the output stream where the console's output is written to. |
Object |
getPrompt()
Returns the object that represents the console prompt. |
void |
run()
|
void |
setInputStream(InputStream inStream)
Sets the input stream from which the user's input is read from. |
void |
setOutputStream(OutputStream outStream)
Sets the output stream where the console's output is written to. |
void |
setPrompt(Object newPrompt)
Changes the console's prompt to a new prompt object. |
void |
shutdown()
Closes the console and stops the associated thread. |
private void |
startThread()
Starts the console thread. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, 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, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static Logger sLogger
private boolean mShutdownRequested
private CommandHandler mCommandHandler
private String mGreetingMsg
private Object mPrompt
private BufferedReader mReader
private InputStream mInputStream
private PrintStream mOutput
Constructor Detail |
---|
private ConsoleThread()
public ConsoleThread(CommandHandler handler, String greetingMsg, Object prompt, OutputStream outStream, InputStream inStream)
handler
- Class that gets passed the user input to process it further.greetingMsg
- A greeting message that is shown when the console starts up.prompt
- The command prompt. Can be something like '$' or '>' or a mutable
object. The toString() method of the prompt-object is
used to determine the string to be used as command prompt. For
example, use a date object here that will return the current date
and time in its toString() method.outStream
- Output stream that will be used to write the command prompt to.
Note that the output of specific commands will not be written to
this output stream if this is not configured by the respective
command objects. See org.pi4.simplesim.util.CommandObject for
further information.inStream
- Input stream that is used to read the user's input from.public ConsoleThread(CommandHandler handler, String greetingMsg, String prompt)
handler
- Class that gets passed the user input to process it further.greetingMsg
- A greeting message that is shown when the console starts up.prompt
- The command prompt. Can be something like '$' or '>' or a mutable
object. The toString() method of the prompt-object is
used to determine the string to be used as command prompt. For
example, use a date object here that will return the current date
and time in its toString() method.Method Detail |
---|
private void startThread()
public void run()
run
in interface Runnable
run
in class Thread
public void setPrompt(Object newPrompt)
newPrompt
- the new command line prompt to be used by this console.public Object getPrompt()
">"
, for example. To
print out the prompt on the console, the prompt object's
toString
method is used.
public void shutdown()
public OutputStream getOutputStream()
public InputStream getInputStream()
public void setOutputStream(OutputStream outStream)
outStream
- the output stream where the console's output is written to.public void setInputStream(InputStream inStream)
inStream
- the input stream from which the user's input is read from.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |