fr.lip6.sma.simulacion.app
Class CLIApplication

java.lang.Object
  extended by java.lang.Thread
      extended by fr.lip6.sma.simulacion.app.CLIApplication
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
HTTPServer

public class CLIApplication
extends Thread

Class for command line applications.

Version:
$Revision: 3 $
Author:
Paul Guyot

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  sun.misc.SignalHandler mDefaultIntHandler
          Default handler for the INT signal.
private  BufferedReader mInputReader
          Input stream.
private  PrintStream mOutputPrinter
          Output stream.
private  boolean mRunning
          Boolean indicating we should exit the main loop.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CLIApplication(String inName)
          Constructor from a string.
 
Method Summary
protected  void displayHelp(String inLine)
          Display the help.
protected  void flush()
          Flush stdout.
protected  void init()
          Method called at the beginning of the application.
protected  void print(String inString)
          Display a string on stdout.
protected  void println(String inLine)
          Display a string on stdout.
protected  void printStackTrace(Throwable inThrowable)
          Display an exception's stack trace.
protected  boolean processCommand(String inCommand, String inLine)
          Method called to process commands.
private  void prompt()
          Display the prompt.
protected  void quit()
          Method called to quit the application.
 void run()
          Main loop of the thread.
private  void signalHandler(sun.misc.Signal inSignal)
          Handler for the INT signal.
 
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

mDefaultIntHandler

private final sun.misc.SignalHandler mDefaultIntHandler
Default handler for the INT signal.


mInputReader

private final BufferedReader mInputReader
Input stream.


mOutputPrinter

private final PrintStream mOutputPrinter
Output stream.


mRunning

private boolean mRunning
Boolean indicating we should exit the main loop.

Constructor Detail

CLIApplication

public CLIApplication(String inName)
Constructor from a string.

Parameters:
inName - name for the thread.
Method Detail

run

public final void run()
Main loop of the thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

init

protected void init()
Method called at the beginning of the application. By default, it doesn't do anything.


quit

protected void quit()
Method called to quit the application. This method is invoked from the INT handler and from the QUIT command. By default, it doesn't do anything.


processCommand

protected boolean processCommand(String inCommand,
                                 String inLine)
Method called to process commands. The default implementation handles the QUIT and the HELP commands. This method is typically overriden as follows: protected boolean processCommand(String inCommand, String inLine) { boolean theResult = super.processCommand(inCommand, inLine); if (!theResult) { theResult = true; if ("FOO".equals(inCommand)) { ... } else if ("BAR".equals(inCommand)) { ... } else { // Unknown command. theResult = false; } } return theResult; }

Parameters:
inCommand - command to parse (in uppercase).
inLine - the full line.
Returns:
false if the command was unknown, true otherwise.

displayHelp

protected void displayHelp(String inLine)
Display the help. By default shows the help for the HELP and the QUIT commands.

Parameters:
inLine - line for the help command (unused).

println

protected final void println(String inLine)
Display a string on stdout. The string is followed by a new line char.

Parameters:
inLine - line to display.

print

protected final void print(String inString)
Display a string on stdout.

Parameters:
inString - string to display.

flush

protected final void flush()
Flush stdout.


printStackTrace

protected final void printStackTrace(Throwable inThrowable)
Display an exception's stack trace.

Parameters:
inThrowable - throwable which stack trace to display.

signalHandler

private void signalHandler(sun.misc.Signal inSignal)
Handler for the INT signal.

Parameters:
inSignal - received signal (INT).

prompt

private void prompt()
Display the prompt.