t3.remotehrd.server
Class RemoteHRDServer

java.lang.Object
  extended by t3.remotehrd.server.RemoteHRDServer

public class RemoteHRDServer
extends java.lang.Object

This class represents a RemoteHRD server. It has a HRD StateManager, and changes to the state are broadcast to any connected RemoteHRDClients.

You can use its StateManager as usual but with some restrictions: you must synchronize on it before you use it, or its Tiles, Cursors or Links; and you must call endOfBurst to ensure that changes get sent on to the clients.

We have one listener thread that listens for new connections. It does:

We have one thread per client that receives and processes messages from that client. * It does:

Processing is therefore multithreaded and uses locks on StateManager. You need to be careful with this. If you use the StateManager, or one of its Tiles, Links or Cursors then you will need to synchronize on StateManager first.

To send a message to all clients you call the manager's addToSendQueue method. If you perform operations on the StateManager or one if its Tiles, Links or Cursors then a message will automatically be generated and the addToSendQueue method invoked.

When you call addToSendQueue, the message is not sent immediately; instead it is added to a queue and might not be sent until you call endOfBurst. Messages within a burst might be amalgamated to save processing time and network bandwidth.

There are two modes for sending:

Author:
pjt40

Field Summary
 java.util.Map<java.lang.Integer,Client> allClientsClientIdToClientsImmutable
           
 RemoteHRDServerCallBacks callBacks
           
 StateManager stateManager
          See notes above.
 
Constructor Summary
RemoteHRDServer(java.net.ServerSocket serverSocket, java.net.ServerSocket inputSourceServerSocket, RemoteHRDServerCallBacks callBacks, boolean alwaysServerPush)
          Creates a RemoteHRDServer and starts the listening thread.
 
Method Summary
 void addToSendQueue(java.io.Serializable msg)
          Add a message to the send queue.
 void endOfUpdateFrame()
          Indicates that queued messages can be sent through to the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allClientsClientIdToClientsImmutable

public final java.util.Map<java.lang.Integer,Client> allClientsClientIdToClientsImmutable

callBacks

public final RemoteHRDServerCallBacks callBacks

stateManager

public final StateManager stateManager
See notes above.

Constructor Detail

RemoteHRDServer

public RemoteHRDServer(java.net.ServerSocket serverSocket,
                       java.net.ServerSocket inputSourceServerSocket,
                       RemoteHRDServerCallBacks callBacks,
                       boolean alwaysServerPush)
Creates a RemoteHRDServer and starts the listening thread. This constructor returns immediately.

Parameters:
serverSocket -
callBacks -
alwaysServerPush -
Method Detail

addToSendQueue

public void addToSendQueue(java.io.Serializable msg)
Add a message to the send queue. The message might not be sent until you call endOfBurst(). See notes above for more details. This method is thead-safe; it can be called from any thread.

Parameters:
msg -

endOfUpdateFrame

public void endOfUpdateFrame()
Indicates that queued messages can be sent through to the client. This method is thead-safe; it can be called from any thread.