dasher.net
Class NetDasherCommandInterpreterThread

java.lang.Object
  extended by java.lang.Thread
      extended by dasher.net.NetDasherCommandInterpreterThread
All Implemented Interfaces:
java.lang.Runnable

public class NetDasherCommandInterpreterThread
extends java.lang.Thread

This thread is spawned by NetDasherListener every time a connection is accepted.

The thread is passed references to most of NetDasherListener's internal data, and is responsible for interpreting the incoming request and using these resources to service it appropriately.

Output should also be organised such that the client has received a reply by the time this thread ends.

The input will arrive in XML format; output too should be written as XML.

Input XML

The general format of XML which is expected is:

<command type="message_type">%lt;attribute_1>value%lt;/attribute_1><attribute_2>value</attribute_2>...</command>

Where message_type can be any of:

init -- Starts a new session. Required attributes are width (Client's screen width in pixels) and height (Client's screen height in pixels).

click -- Reports a user mouse click at a given location. Required parameters are x (mouse x co-ordinate) and y (mouse y co-ordinate).

changealphabet -- Changes the alphabet currently in use. Required parameter: name (Name of new alphabet)

changecolours -- Changes the colour scheme currently in use. Required parameter: name (Name of new colour scheme)

Output XML

This class is responsible for producing XML reporting errors in parsing input XML.

For a description of ordinary output returned when the input XML was successfully parsed, see the documentation for NetScreen.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  CAlphIO alphIO
          AlphIO instance to be supplied to any Dashers created
protected  CColourIO colourIO
          ColourIO instance to be supplied to any Dashers created
protected  java.net.Socket DasherConnection
          Socket on which the incoming request arrived, and to which output should eventually be delivered.
protected  java.util.concurrent.ConcurrentHashMap<java.lang.Integer,NetDashConnectionHandler> Dashers
          Map indexing the available NetDasherConnectionHandlers by their associated session identifiers.
protected  java.lang.String dataLocation
          Data location any created Dasher should use to locate training text.
protected  javax.xml.parsers.DocumentBuilderFactory db
          DocumentBuilderFactory to be used in the course of all XML parsing.
protected  idWrapper freeID
          idWrapper class to obtain free session IDs.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NetDasherCommandInterpreterThread(java.net.Socket Connection, java.util.concurrent.ConcurrentHashMap<java.lang.Integer,NetDashConnectionHandler> dashs, idWrapper freeIDs, javax.xml.parsers.DocumentBuilderFactory docbuild, java.lang.String dataloc, CAlphIO alphIO, CColourIO colourIO)
          Creates a new command interpreter and passes in working data.
 
Method Summary
protected  int getFreeID()
          Uses freeID to produce a free ID
 void run()
          Starts the thread.
protected  void writeError(java.lang.String errorString, java.io.OutputStream m_Output)
          Produces an XML document describing a given error and serializes the document to a given OutputStream, typically a network socket.
 
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

freeID

protected idWrapper freeID
idWrapper class to obtain free session IDs.


Dashers

protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,NetDashConnectionHandler> Dashers
Map indexing the available NetDasherConnectionHandlers by their associated session identifiers.


DasherConnection

protected java.net.Socket DasherConnection
Socket on which the incoming request arrived, and to which output should eventually be delivered.


db

protected javax.xml.parsers.DocumentBuilderFactory db
DocumentBuilderFactory to be used in the course of all XML parsing.


dataLocation

protected java.lang.String dataLocation
Data location any created Dasher should use to locate training text.


alphIO

protected CAlphIO alphIO
AlphIO instance to be supplied to any Dashers created


colourIO

protected CColourIO colourIO
ColourIO instance to be supplied to any Dashers created

Constructor Detail

NetDasherCommandInterpreterThread

public NetDasherCommandInterpreterThread(java.net.Socket Connection,
                                         java.util.concurrent.ConcurrentHashMap<java.lang.Integer,NetDashConnectionHandler> dashs,
                                         idWrapper freeIDs,
                                         javax.xml.parsers.DocumentBuilderFactory docbuild,
                                         java.lang.String dataloc,
                                         CAlphIO alphIO,
                                         CColourIO colourIO)
Creates a new command interpreter and passes in working data. Given these, the thread is ready to begin interpreting and servicing the command given on the supplied socket.

The actual interpreting will take place when the thread's start() method is called.

Parameters:
Connection - Socket from which the command should be read and to which the answer should be written.
dashs - Map indexing Dashers by their session ID
freeIDs - Class capable of reliably supplying unique free session identifiers. Must be thread-safe.
docbuild - DocumentBuilderFactory to use for XML reading and writing
dataloc - Data location where Dashers can find training text
alphIO - AlphIO object describing available alphabets
colourIO - ColourIO object describing available colour schemes
Method Detail

run

public void run()
Starts the thread. See the class summary for a description of the input the class accepts, and the output produced.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getFreeID

protected int getFreeID()
Uses freeID to produce a free ID

Returns:
Free (unique) session identifier.

writeError

protected void writeError(java.lang.String errorString,
                          java.io.OutputStream m_Output)
Produces an XML document describing a given error and serializes the document to a given OutputStream, typically a network socket.

This method is for reporting errors encountered whilst trying to parse the client's request document; errors arising in Dasher itself should be dealt with by other means.

Parameters:
errorString - String to report to the user
m_Output - OutputStream to which XML should be serialized