dasher.net
Class NetDasherListener

java.lang.Object
  extended by dasher.net.NetDasherListener

public class NetDasherListener
extends java.lang.Object

Main class powering NetDasher. This class listens for connections and, whenever one is received, spawns a NetDasherCommandInterpreterThread to determine what the client wants, and action their request.

Alphabet and Colour XML files are also read on startup to produce central AlphIO and ColourIO objects, which are passed in to every created Dasher; this way we avoid the tedious work of repeatedly parsing the same data for each instance of Dasher we create.

Essentially the goal is to create an instance of Dasher, attached to a NetScreen, for each client, and to pass the user's clicks and other requests to the appropriate instance of Dasher as connections come in.

Since connections are conducted by HTTP for most clients and forwarded by a simple PHP script, there are no persistent connections -- there is only one connection per request and vice versa.


Field Summary
private static java.util.concurrent.ConcurrentHashMap<java.lang.Integer,NetDashConnectionHandler> Dashers
          HashMap of session identifiers to instances of Dasher, passed to each CommandInterpreterThread.
private static java.lang.String dataLocation
          Location to look for alphabet and colour XML files, as well as training texts.
private static javax.xml.parsers.DocumentBuilderFactory dbf
          DOM parser factory for XML.
private static java.util.Timer GCScheduler
          Timer which runs a NetDashGC thread every 60 seconds
private static idWrapper nextID
          Next free session identifier
 
Constructor Summary
NetDasherListener()
           
 
Method Summary
static void main(java.lang.String[] args)
          Creates our listening socket, schedules the garbage collector thread to run every 60 seconds, creates instances of CAlphIO and CColourIO to read in the appropriate XML data, and finally enters a tight loop of accepting connections and spawning NetDasherCommandInterpreterThreads to deal with them.
static void ScanAlphabetFiles(java.util.ArrayList<java.lang.String> vFileList)
           
static void ScanColourFiles(java.util.ArrayList<java.lang.String> vFileList)
           
static void ScanFilesByRegex(java.util.ArrayList<java.lang.String> vFileList, java.lang.String regex)
          Delegate method used by both ScanAlphabetFiles and ScanColourFiles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Dashers

private static java.util.concurrent.ConcurrentHashMap<java.lang.Integer,NetDashConnectionHandler> Dashers
HashMap of session identifiers to instances of Dasher, passed to each CommandInterpreterThread.


dataLocation

private static java.lang.String dataLocation
Location to look for alphabet and colour XML files, as well as training texts.


dbf

private static javax.xml.parsers.DocumentBuilderFactory dbf
DOM parser factory for XML.


GCScheduler

private static java.util.Timer GCScheduler
Timer which runs a NetDashGC thread every 60 seconds


nextID

private static idWrapper nextID
Next free session identifier

Constructor Detail

NetDasherListener

public NetDasherListener()
Method Detail

ScanAlphabetFiles

public static void ScanAlphabetFiles(java.util.ArrayList<java.lang.String> vFileList)

ScanColourFiles

public static void ScanColourFiles(java.util.ArrayList<java.lang.String> vFileList)

ScanFilesByRegex

public static void ScanFilesByRegex(java.util.ArrayList<java.lang.String> vFileList,
                                    java.lang.String regex)
Delegate method used by both ScanAlphabetFiles and ScanColourFiles.

Fills its first parameter with all files in our systemLocation which match the given regex.

Parameters:
vFileList - List to fill with matching files
regex - Regular expression determining what to add

main

public static void main(java.lang.String[] args)
Creates our listening socket, schedules the garbage collector thread to run every 60 seconds, creates instances of CAlphIO and CColourIO to read in the appropriate XML data, and finally enters a tight loop of accepting connections and spawning NetDasherCommandInterpreterThreads to deal with them.

The first argument is taken as the data location where XML files and training texts may be found.