com.threerings.presents.util
Class SafeSubscriber<T extends DObject>

java.lang.Object
  extended by com.threerings.presents.util.SafeSubscriber<T>
Type Parameters:
T - the type of object to which we are subscribing.
All Implemented Interfaces:
Subscriber<T>

public class SafeSubscriber<T extends DObject>
extends Object
implements Subscriber<T>

A class that safely handles the asynchronous subscription to a distributed object when it is not know if the subscription will complete before the subscriber decides they no longer wish to be subscribed.


Field Summary
protected  boolean _active
           
protected  ChangeListener[] _listeners
           
protected  T _object
           
protected  int _oid
           
protected  boolean _pending
           
protected  Subscriber<T> _subscriber
           
 
Constructor Summary
SafeSubscriber(int oid, Subscriber<T> subscriber, ChangeListener... listeners)
          Creates a safe subscriber for the specified distributed object which will interact with the specified subscriber.
 
Method Summary
 boolean isActive()
          Returns true if we are currently subscribed to our object (or in the process of obtaining a subscription).
 void objectAvailable(T object)
          Called when a subscription request has succeeded and the object is available.
 void requestFailed(int oid, ObjectAccessException cause)
          Called when a subscription request has failed.
 void subscribe(DObjectManager omgr)
          Initiates the subscription process.
 String toString()
           
 void unsubscribe(DObjectManager omgr)
          Terminates the object subscription.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_listeners

protected ChangeListener[] _listeners

_oid

protected int _oid

_subscriber

protected Subscriber<T extends DObject> _subscriber

_object

protected T extends DObject _object

_active

protected boolean _active

_pending

protected boolean _pending
Constructor Detail

SafeSubscriber

public SafeSubscriber(int oid,
                      Subscriber<T> subscriber,
                      ChangeListener... listeners)
Creates a safe subscriber for the specified distributed object which will interact with the specified subscriber. If any listeners are given, they'll be added as listeners to the distributed object after the subscriber is told it's available, and will be removed when unsubscribing from the object.

Method Detail

isActive

public boolean isActive()
Returns true if we are currently subscribed to our object (or in the process of obtaining a subscription).


subscribe

public void subscribe(DObjectManager omgr)
Initiates the subscription process.


unsubscribe

public void unsubscribe(DObjectManager omgr)
Terminates the object subscription. If the initial subscription has not yet completed, the desire to terminate will be noted and the subscription will be terminated as soon as it completes.


objectAvailable

public void objectAvailable(T object)
Description copied from interface: Subscriber
Called when a subscription request has succeeded and the object is available. If the object was requested for subscription, the subscriber can subsequently receive notifications by registering itself as a listener of some sort (see DObject.addListener(com.threerings.presents.dobj.ChangeListener)).

Specified by:
objectAvailable in interface Subscriber<T extends DObject>
See Also:
DObjectManager.subscribeToObject(int, com.threerings.presents.dobj.Subscriber)

requestFailed

public void requestFailed(int oid,
                          ObjectAccessException cause)
Description copied from interface: Subscriber
Called when a subscription request has failed. The nature of the failure will be communicated via the supplied ObjectAccessException.

Specified by:
requestFailed in interface Subscriber<T extends DObject>
See Also:
DObjectManager.subscribeToObject(int, com.threerings.presents.dobj.Subscriber)

toString

public String toString()
Overrides:
toString in class Object