dasher.net
Class NetDashConnectionHandler

java.lang.Object
  extended by dasher.net.NetDashConnectionHandler
All Implemented Interfaces:
DasherEditListener

public class NetDashConnectionHandler
extends java.lang.Object
implements DasherEditListener

Wraps an instance of NetDasher and passes commands to it when asked to by a DasherCommandInterpreterThread.


Field Summary
private  NetDasher Dasher
          Dasher we are wrapping
private  boolean destroyed
          Flag indicating if this Dasher has been destroyed by the GC thread.
private  long lastUsed
          System time when this Dasher was last accessed; used to determine if this session is idle by NetDashGC
private  java.util.concurrent.locks.Lock myLock
          Lock which is set when a thread is operating on this Dasher in some way.
private  NetScreen Screen
          Screen attached to this Dasher
private  int sessID
          Session identifier associated with this instance
 
Constructor Summary
NetDashConnectionHandler(int sessID, int width, int height, java.lang.String dataLocation, CAlphIO alphIO, CColourIO colIO)
          Creates and wraps a new instance of NetDasher and creates and registers our helper classes including a NetScreen for output and a NetInput for input.
 
Method Summary
 void changeAlphabet(java.lang.String alph)
          Changes the alphabet used by our wrapped Dasher.
 void changeColours(java.lang.String col)
          Changes the colour scheme used by our wrapped Dasher.
 void Clicked(int x, int y, java.io.OutputStream output)
          Reports a mouse click to our hosted Dasher; this should be called by the command interpreter when the client sends a document reporting a click.
 void destroy()
          Invoked by the garbage collector thread to destory the Interface of our wrapped NetDasher, freeing the vast majority of memory used.
 void Draw(java.io.OutputStream output)
          Forces Dasher to draw a frame to a given output stream immediately.
 java.util.concurrent.locks.Lock getLock()
          Retrieves a reference to the Lock used to prevent concurrent modification of this instance of NetDasher.
 int getSessID()
          Gets the session ID associated with this instance
 void HandleEvent(CEditEvent event)
          Called by the wrapped NetDasher instance to report an EditEvent because the user has entered or left a node.
 boolean isDestroyed()
          Reports whether this session has in fact been destroyed by the garbage collector thread; this is to guard against situations where a reference to a collected object has somehow been held.
 boolean isIdle()
          Uses the lastUsed timestamp held internally to determine whether this session has been idle for 5 minutes or more.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Dasher

private NetDasher Dasher
Dasher we are wrapping


Screen

private NetScreen Screen
Screen attached to this Dasher


lastUsed

private long lastUsed
System time when this Dasher was last accessed; used to determine if this session is idle by NetDashGC


sessID

private int sessID
Session identifier associated with this instance


destroyed

private boolean destroyed
Flag indicating if this Dasher has been destroyed by the GC thread.


myLock

private java.util.concurrent.locks.Lock myLock
Lock which is set when a thread is operating on this Dasher in some way.

Constructor Detail

NetDashConnectionHandler

public NetDashConnectionHandler(int sessID,
                                int width,
                                int height,
                                java.lang.String dataLocation,
                                CAlphIO alphIO,
                                CColourIO colIO)
Creates and wraps a new instance of NetDasher and creates and registers our helper classes including a NetScreen for output and a NetInput for input.

Parameters:
sessID - Session identifer associated with this handler
width - Screen width to draw for
height - Screen height to draw for
dataLocation - Where to look for alphabet and colour XML files
alphIO - AlphIO object holding alphabet data
colIO - ColourIO object holding colour data
Method Detail

Clicked

public void Clicked(int x,
                    int y,
                    java.io.OutputStream output)
Reports a mouse click to our hosted Dasher; this should be called by the command interpreter when the client sends a document reporting a click.

Internally we pass the co-ordinates on using NetDasher's setCoordinates method, call KeyDown to report a click, set the Screen's OutputStream, and finally calls NewFrame so that a frame is drawn to NetScreen and passes out through the given OutputStream.

Finally, our internal lastUsed field is updated to note the time when the user last interacted with this session.

Parameters:
x - Mouse x co-ordinate
y - Mouse y co-ordinate
output - Stream to which drawn XML will be output

Draw

public void Draw(java.io.OutputStream output)
Forces Dasher to draw a frame to a given output stream immediately.

There is no need to call this when reporting a mouse-click as a frame will automatically be drawn as part of the process.

Finally, our internal lastUsed field is updated to note the time when the user last interacted with this session.

Parameters:
output - OutputStream to which we should output XML

HandleEvent

public void HandleEvent(CEditEvent event)
Called by the wrapped NetDasher instance to report an EditEvent because the user has entered or left a node.

This method just passes it on to the Screen to incorporate into the next frame -- given the timing of EditEvents during the drawing cycle, this will almost certainly be the same as the frame emitted in response to the user interaction which spawned the edit event in the first place, producing the illusion of almost-instantaneous response.

Specified by:
HandleEvent in interface DasherEditListener
Parameters:
event - Event being reported

isIdle

public boolean isIdle()
Uses the lastUsed timestamp held internally to determine whether this session has been idle for 5 minutes or more.

Returns:
True if idle

isDestroyed

public boolean isDestroyed()
Reports whether this session has in fact been destroyed by the garbage collector thread; this is to guard against situations where a reference to a collected object has somehow been held.

Any class which finds itself holding a destroyed reference should behave as if it failed to get the reference in the first place; typically it indicates a session expired whilst a thread was waiting on a lock.

Returns:
True if destroyed

destroy

public void destroy()
Invoked by the garbage collector thread to destory the Interface of our wrapped NetDasher, freeing the vast majority of memory used.

After destroying an instance, all references to it should be nulled to permit the Java garbage collector to reclaim this wrapper.


getSessID

public int getSessID()
Gets the session ID associated with this instance

Returns:
SessID

getLock

public java.util.concurrent.locks.Lock getLock()
Retrieves a reference to the Lock used to prevent concurrent modification of this instance of NetDasher.

Returns:
myLock

changeAlphabet

public void changeAlphabet(java.lang.String alph)
Changes the alphabet used by our wrapped Dasher.

This does not cause drawing automatically; Draw should be called afterwards if this is desired.

Parameters:
alph - Name of new alphabet

changeColours

public void changeColours(java.lang.String col)
Changes the colour scheme used by our wrapped Dasher.

This does not cause drawing automatically; Draw should be called afterwards if this is desired.

Parameters:
col - Name of new colour scheme