com.threerings.presents.client
Class InvocationDirector

java.lang.Object
  extended by com.threerings.presents.client.InvocationDirector
All Implemented Interfaces:
ChangeListener, EventListener

public class InvocationDirector
extends Object
implements EventListener

Handles the client side management of the invocation services.


Field Summary
protected  Client _client
          The client for whom we're working.
protected  ClientObject _clobj
          Our client object; invocation responses and notifications are received on this object.
protected  long _lastFlushTime
          The last time we flushed our listeners.
protected  HashIntMap<InvocationMarshaller.ListenerMarshaller> _listeners
          Used to keep track of invocation service listeners which will receive responses from invocation service requests.
protected  DObjectManager _omgr
          The distributed object manager with which we interact.
protected  short _receiverId
          Used to generate monotonically increasing receiver ids.
protected  HashIntMap<InvocationDecoder> _receivers
          Used to keep track of invocation notification receivers.
protected  ArrayList<InvocationDecoder> _reclist
          All registered receivers are maintained in a list so that we can assign receiver ids to them when we go online.
protected  short _requestId
          Used to generate monotonically increasing request ids.
protected static long LISTENER_FLUSH_INTERVAL
          The minimum interval between listener flush attempts.
protected static long LISTENER_MAX_AGE
          Listener mappings older than 90 seconds are reaped.
 
Constructor Summary
InvocationDirector()
           
 
Method Summary
protected  void assignReceiverId(InvocationDecoder decoder)
          Assigns a receiver id to this decoder and publishes it in the ClientObject.receivers field.
protected  void assignReceiverIds()
          Called when we log on; generates mappings for all receivers registered prior to logon.
 void cleanup()
          Clears out our session information.
 void eventReceived(DEvent event)
          Process notification and response events arriving on user object.
protected  void flushListeners(long now)
          Flushes listener mappings that are older than LISTENER_MAX_AGE milliseconds.
protected  void handleClientObjectChanged(int newCloid)
          Called when the server has informed us that our previous client object is going the way of the Dodo because we're changing screen names.
protected  void handleInvocationNotification(int receiverId, int methodId, Object[] args)
          Dispatches an invocation notification.
protected  void handleInvocationResponse(int reqId, int methodId, Object[] args)
          Dispatches an invocation response.
 void init(DObjectManager omgr, int cloid, Client client)
          Initializes the invocation director.
protected  short nextReceiverId()
          Used to generate monotonically increasing invocation receiver ids.
protected  short nextRequestId()
          Used to generate monotonically increasing invocation request ids.
 void registerReceiver(InvocationDecoder decoder)
          Registers an invocation notification receiver by way of its notification event decoder.
 void sendRequest(int invOid, int invCode, int methodId, Object[] args)
          Requests that the specified invocation request be packaged up and sent to the supplied invocation oid.
 void sendRequest(int invOid, int invCode, int methodId, Object[] args, Transport transport)
          Requests that the specified invocation request be packaged up and sent to the supplied invocation oid.
 void unregisterReceiver(String receiverCode)
          Removes a receiver registration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_omgr

protected DObjectManager _omgr
The distributed object manager with which we interact.


_client

protected Client _client
The client for whom we're working.


_clobj

protected ClientObject _clobj
Our client object; invocation responses and notifications are received on this object.


_requestId

protected short _requestId
Used to generate monotonically increasing request ids.


_receiverId

protected short _receiverId
Used to generate monotonically increasing receiver ids.


_listeners

protected HashIntMap<InvocationMarshaller.ListenerMarshaller> _listeners
Used to keep track of invocation service listeners which will receive responses from invocation service requests.


_receivers

protected HashIntMap<InvocationDecoder> _receivers
Used to keep track of invocation notification receivers.


_reclist

protected ArrayList<InvocationDecoder> _reclist
All registered receivers are maintained in a list so that we can assign receiver ids to them when we go online.


_lastFlushTime

protected long _lastFlushTime
The last time we flushed our listeners.


LISTENER_FLUSH_INTERVAL

protected static final long LISTENER_FLUSH_INTERVAL
The minimum interval between listener flush attempts.

See Also:
Constant Field Values

LISTENER_MAX_AGE

protected static final long LISTENER_MAX_AGE
Listener mappings older than 90 seconds are reaped.

See Also:
Constant Field Values
Constructor Detail

InvocationDirector

public InvocationDirector()
Method Detail

init

public void init(DObjectManager omgr,
                 int cloid,
                 Client client)
Initializes the invocation director. This is called when the client establishes a connection with the server.

Parameters:
omgr - the distributed object manager via which the invocation manager will send and receive events.
cloid - the oid of the object on which invocation notifications as well as invocation responses will be received.
client - a reference to the client for whom we're doing our business.

cleanup

public void cleanup()
Clears out our session information. This is called when the client ends its session with the server.


registerReceiver

public void registerReceiver(InvocationDecoder decoder)
Registers an invocation notification receiver by way of its notification event decoder.


unregisterReceiver

public void unregisterReceiver(String receiverCode)
Removes a receiver registration.


assignReceiverIds

protected void assignReceiverIds()
Called when we log on; generates mappings for all receivers registered prior to logon.


assignReceiverId

protected void assignReceiverId(InvocationDecoder decoder)
Assigns a receiver id to this decoder and publishes it in the ClientObject.receivers field.


sendRequest

public void sendRequest(int invOid,
                        int invCode,
                        int methodId,
                        Object[] args)
Requests that the specified invocation request be packaged up and sent to the supplied invocation oid.


sendRequest

public void sendRequest(int invOid,
                        int invCode,
                        int methodId,
                        Object[] args,
                        Transport transport)
Requests that the specified invocation request be packaged up and sent to the supplied invocation oid.


eventReceived

public void eventReceived(DEvent event)
Process notification and response events arriving on user object.

Specified by:
eventReceived in interface EventListener
Parameters:
event - The event that was dispatched on the object.

handleInvocationResponse

protected void handleInvocationResponse(int reqId,
                                        int methodId,
                                        Object[] args)
Dispatches an invocation response.


handleInvocationNotification

protected void handleInvocationNotification(int receiverId,
                                            int methodId,
                                            Object[] args)
Dispatches an invocation notification.


handleClientObjectChanged

protected void handleClientObjectChanged(int newCloid)
Called when the server has informed us that our previous client object is going the way of the Dodo because we're changing screen names. We subscribe to the new object and report to the client once we've got our hands on it.


flushListeners

protected void flushListeners(long now)
Flushes listener mappings that are older than LISTENER_MAX_AGE milliseconds. An alternative to flushing listeners that did not explicitly receive a response within our expiry time period is to have the server's proxy listener send a message to the client when it is finalized. We then know that no server entity will subsequently use that proxy listener to send a response to the client. This involves more network traffic and complexity than seems necessary and if a user of the system does respond after their listener has been flushed, an informative warning will be logged. (Famous last words.)


nextRequestId

protected short nextRequestId()
Used to generate monotonically increasing invocation request ids.


nextReceiverId

protected short nextReceiverId()
Used to generate monotonically increasing invocation receiver ids.