arlut.csd.ganymede
Class serverClientProxy

java.lang.Object
  |
  +--arlut.csd.ganymede.serverClientProxy
All Implemented Interfaces:
java.lang.Runnable

public class serverClientProxy
extends java.lang.Object
implements java.lang.Runnable

serverClientProxy is a partial server-side Client proxy object which buffers async client updates, coalescing update events as needed to maximize server efficiency. Each serverClientProxy object has a background thread which communicates with a remote Client in the background, allowing the Ganymede server's operations to be asynchronous with respect to Client messages.

See Also:
clientEvent

Field Summary
private  Client client
          Our remote reference to the Client
private  java.lang.Thread commThread
          Our background communications thread, which is responsible for calling the remote Client via RMI.
private  boolean done
          If true, we have been told to shut down, and our background commThread will exit as soon as it can clear its event queue.
private  java.lang.String errorCondition
          If our commThread receives a remote exception when communicating with a remote Client, this field will become non-null, and no more communications will be attempted with that client.
private  java.util.Vector eventBuffer
          Our queue of clientEvent objects.
private  clientEvent[] lookUp
          Handy direct look-up table for events in eventBuffer
private  int maxBufferSize
          How many events we'll queue up before deciding that the Client isn't responding.
 
Constructor Summary
serverClientProxy(Client client)
           
 
Method Summary
private  void addEvent(clientEvent newEvent)
          private helper method in serverClientProxy, used to add an event to the proxy's event buffer.
 boolean isAlive()
          Returns true if we are successfully in communications with the attached Client.
private  void replaceEvent(clientEvent newEvent)
          private helper method in serverClientProxy, used to add an event to the proxy's event buffer.
 void run()
          The serverClientProxy's background thread's run() method.
 void sendMessage(int type, java.lang.String message)
          This method is used to submit a message to be sent to the client.
 void shutdown()
          This method shuts down the background thread.
private  void throwOverflow()
          This method throws a remoteException which describes the state of the event buffer.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

commThread

private java.lang.Thread commThread

Our background communications thread, which is responsible for calling the remote Client via RMI.


eventBuffer

private java.util.Vector eventBuffer

Our queue of clientEvent objects.


maxBufferSize

private int maxBufferSize

How many events we'll queue up before deciding that the Client isn't responding.


client

private Client client

Our remote reference to the Client


done

private boolean done

If true, we have been told to shut down, and our background commThread will exit as soon as it can clear its event queue.

.


errorCondition

private java.lang.String errorCondition

If our commThread receives a remote exception when communicating with a remote Client, this field will become non-null, and no more communications will be attempted with that client.


lookUp

private clientEvent[] lookUp

Handy direct look-up table for events in eventBuffer

Constructor Detail

serverClientProxy

public serverClientProxy(Client client)
Method Detail

isAlive

public boolean isAlive()

Returns true if we are successfully in communications with the attached Client.


shutdown

public void shutdown()

This method shuts down the background thread.


sendMessage

public void sendMessage(int type,
                        java.lang.String message)
                 throws java.rmi.RemoteException

This method is used to submit a message to be sent to the client. If the serverClientProxy has already had its shutdown() method called, sendMessage() will silently fail, and the message will not be queued.


run

public void run()

The serverClientProxy's background thread's run() method. This method runs in the Client proxy thread to read events from this console's serverClientProxy eventBuffer and send them down to the Client.

Specified by:
run in interface java.lang.Runnable

addEvent

private void addEvent(clientEvent newEvent)
               throws java.rmi.RemoteException

private helper method in serverClientProxy, used to add an event to the proxy's event buffer. If the buffer already contains an event of the same type as newEvent, both events will be sent to the Client, in chronological order.


replaceEvent

private void replaceEvent(clientEvent newEvent)
                   throws java.rmi.RemoteException

private helper method in serverClientProxy, used to add an event to the proxy's event buffer. If the buffer already contains an event of the same type as newEvent, the old event's contents will be replaced with the new, and the remote client will never be notified of the old event's contents.


throwOverflow

private void throwOverflow()
                    throws java.rmi.RemoteException

This method throws a remoteException which describes the state of the event buffer. This is called from addEvent and replaceEvent.