org.starhope.appius.net
Class NetIOThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.starhope.appius.net.NetIOThread
All Implemented Interfaces:
Comparable<Thread>, Runnable, Thread.UncaughtExceptionHandler, NetIOHandlerPeer, AcceptsMetronomeTicks, HasName, CanProcessCommands
Direct Known Subclasses:
ServerThread

public abstract class NetIOThread
extends Thread
implements NetIOHandlerPeer, AcceptsMetronomeTicks, Thread.UncaughtExceptionHandler, CanProcessCommands, Comparable<Thread>

Networking I/O threads, for either client or server using the "Infinity Mode" protocol (or, to a limited extent, the surviving entrails of the SmartFaux mode)

Author:
brpocock@star-hope.org

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean debug
          Boolean flag indicating whether the server is in debugging mode or not.
protected  String dialect
          WRITEME: Document this brpocock@star-hope.org
protected  BufferedReader in
          The buffered input stream from the user.
protected  boolean isDone
          This indicates whether the thread has voluntarily decided to exit, e.g.
protected  String language
          WRITEME: Document this brpocock@star-hope.org
protected  String letsPlayWithFlash
          This is a crazy XML looking string that we have to pump out to make the Flash plug-in happy.
protected  PrintWriter out
          The output stream connected to the pipe
(package private)  boolean parallelMode
          WRITEME
protected  Socket socket
          The socket connected to the other end of the communications
protected  int state
          The state of the conversation that we are having with the other party
private  boolean verboseBugReplies
          WRITEME: Document this brpocock@star-hope.org
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NetIOThread()
          WRITEME
NetIOThread(String string)
          Create a new NetIOThread with the given name
 
Method Summary
protected  void checkInputStream()
          Peek for input.
 int compareTo(Thread other)
          Compare two threads
protected  String doProcessing(String theInput)
           
protected  void dropSocket_socketCore()
          The core code that actually disconnects the socket hard.
protected  void dropSocketConnection()
          Drop the I/O socket for this user.
 boolean equals(NetIOThread other)
          This is an overriding method.
 boolean equals(Object other)
          This is an overriding method.
 String getLanguage_dialect()
          WRITEME: Document this method brpocock@star-hope.org
protected  String getRemoteAddress()
           
protected  Socket getSocket()
          Get the socket connection to the pipe
 boolean getVerboseBugReplies()
           
 int hashCode()
           
 boolean isDebug()
          Determine whether the server is in debugging mode
 boolean isParallelMode()
          WRITEME: Document this method brpocock@star-hope.org
protected abstract  String processInput_Infinity(String theInput)
          Process input received using the JSON-based Infinity mode
 String processInput(String theInput)
          Process and dispatch input from the pipe.
 void sendError_RAW(String errorSource, String message)
          Send a raw error message back to the session as a JSON response
protected abstract  void sendRawMessageLater(String reply)
          Send a message to the user in future
protected  void sendRawMessageNow(String reply)
          Send a raw message packet to the local other party immediately
abstract  void sendResponse(org.json.JSONObject result)
          Send a response as a future (deferred remote) datagram without a room specified
 void setDebug(boolean newDebug)
          Set the server's debugging mode on (true) or off (false)
 void setLanguage(String newLanguage, String newDialect)
          WRITEME: Document this method brpocock@star-hope.org
 void setVerboseBugReplies(boolean really)
          Send the client verbose breakdowns of bug reports
protected  void superVerbose(String string)
          Deprecated. 
 void tattle(String message)
          tattle a non-urgent message
 void tattle(String tattle, boolean urgent)
          Print a log entry to STDERR with a great deal of identifiable detail
protected abstract  String tattlePrefix()
          WRITEME: Document this method brpocock@star-hope.org
protected  void toInfinityAndBeyond()
          engage Infinity-mode protocol
 
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, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.starhope.appius.util.AcceptsMetronomeTicks
tick
 
Methods inherited from interface org.starhope.appius.util.HasName
getName
 
Methods inherited from interface java.lang.Thread.UncaughtExceptionHandler
uncaughtException
 
Methods inherited from interface org.starhope.util.types.CanProcessCommands
getName, setBusyState, setLastInputTime
 

Field Detail

socket

protected Socket socket
The socket connected to the other end of the communications


in

protected BufferedReader in
The buffered input stream from the user.


debug

protected boolean debug
Boolean flag indicating whether the server is in debugging mode or not. True if we are in debugging mode. Defaults to true, until the configuration has been read


isDone

protected boolean isDone
This indicates whether the thread has voluntarily decided to exit, e.g. because the user has properly disconnected and so forth.


letsPlayWithFlash

protected String letsPlayWithFlash
This is a crazy XML looking string that we have to pump out to make the Flash plug-in happy.


state

protected int state
The state of the conversation that we are having with the other party


parallelMode

boolean parallelMode
WRITEME


language

protected String language
WRITEME: Document this brpocock@star-hope.org


dialect

protected String dialect
WRITEME: Document this brpocock@star-hope.org


out

protected PrintWriter out
The output stream connected to the pipe


verboseBugReplies

private boolean verboseBugReplies
WRITEME: Document this brpocock@star-hope.org

Constructor Detail

NetIOThread

public NetIOThread()
WRITEME


NetIOThread

public NetIOThread(String string)
Create a new NetIOThread with the given name

Parameters:
string - WRITEME
Method Detail

checkInputStream

protected void checkInputStream()
                         throws UserDeadException
Peek for input. Try to throw an I/O exception.

Throws:
UserDeadException - if the remote user has disconnected

compareTo

public int compareTo(Thread other)
Compare two threads

Specified by:
compareTo in interface Comparable<Thread>
Parameters:
other - another server thread
See Also:
Comparable.compareTo(java.lang.Object)

doProcessing

protected String doProcessing(String theInput)
Parameters:
theInput - to be processed
Returns:
any response

dropSocket_socketCore

protected void dropSocket_socketCore()
The core code that actually disconnects the socket hard.


dropSocketConnection

protected void dropSocketConnection()
Drop the I/O socket for this user.


equals

public boolean equals(NetIOThread other)
This is an overriding method.

Parameters:
other - the other thread against which to compare
Returns:
true, if these are the same thread
See Also:
Object.equals(java.lang.Object)

equals

public boolean equals(Object other)
This is an overriding method.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getLanguage_dialect

public String getLanguage_dialect()
WRITEME: Document this method brpocock@star-hope.org

Returns:
the language and dialect separated with an "_"

getRemoteAddress

protected String getRemoteAddress()
Returns:
the string form of the remote address

getSocket

protected Socket getSocket()
Get the socket connection to the pipe

Returns:
the socket connection to the pipe

getVerboseBugReplies

public boolean getVerboseBugReplies()
Returns:
whether to include backtraces in exception reports to the client

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

isDebug

public boolean isDebug()
Determine whether the server is in debugging mode

Returns:
true, if the server is in debug mode

isParallelMode

public boolean isParallelMode()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

processInput

public String processInput(String theInput)
Process and dispatch input from the pipe.

Parameters:
theInput - The input packet from the pipe
Returns:
An output packet for the pipe, or a zero-length string if there is no input; or, a null pointer if the pipe should be disconnected.

processInput_Infinity

protected abstract String processInput_Infinity(String theInput)
Process input received using the JSON-based Infinity mode

Parameters:
theInput - the input string identified as being Infinity-mode data
Returns:
a response for the other party in the communication

sendError_RAW

public void sendError_RAW(String errorSource,
                          String message)
Send a raw error message back to the session as a JSON response

Specified by:
sendError_RAW in interface CanProcessCommands
Parameters:
errorSource - The method that is the source of the error
message - The error message to be returned

sendRawMessageLater

protected abstract void sendRawMessageLater(String reply)
                                     throws UserDeadException
Send a message to the user in future

Parameters:
reply - The message to be sent in future
Throws:
UserDeadException - if the user is already gone

sendRawMessageNow

protected void sendRawMessageNow(String reply)
                          throws UserDeadException
Send a raw message packet to the local other party immediately

Parameters:
reply - The string to be transmitted to this thread's user
Throws:
UserDeadException - if the user has been disconnected

sendResponse

public abstract void sendResponse(org.json.JSONObject result)
                           throws UserDeadException
Send a response as a future (deferred remote) datagram without a room specified

Specified by:
sendResponse in interface CanProcessCommands
Parameters:
result - a JSON-encoded response
Throws:
UserDeadException - if the user disconnects
See Also:
CanProcessCommands.sendResponse(org.json.JSONObject)

setDebug

public void setDebug(boolean newDebug)
Set the server's debugging mode on (true) or off (false)

Parameters:
newDebug - True, if the server should be in debug mode; else, false

setLanguage

public void setLanguage(String newLanguage,
                        String newDialect)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
newLanguage - new language
newDialect - new dialect

setVerboseBugReplies

public void setVerboseBugReplies(boolean really)
Send the client verbose breakdowns of bug reports

Parameters:
really - whether to enable this mode, or actually to disable it.

superVerbose

@Deprecated
protected void superVerbose(String string)
Deprecated. 

dump some immensely, nanosecond-stamped verbose logging

Parameters:
string - verbose debugging BS

tattle

public void tattle(String message)
tattle a non-urgent message

Parameters:
message - message

tattle

public void tattle(String tattle,
                   boolean urgent)
Print a log entry to STDERR with a great deal of identifiable detail

Parameters:
tattle - the log entry to be printed
urgent - Display this message even in non-debug mode (in logs)

tattlePrefix

protected abstract String tattlePrefix()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

toInfinityAndBeyond

protected void toInfinityAndBeyond()
engage Infinity-mode protocol