com.threerings.nexus.client
Class NexusClient

java.lang.Object
  extended by com.threerings.nexus.client.NexusClient

public abstract class NexusClient
extends Object

Manages connections to Nexus servers. Provides access to distributed objects and services.


Constructor Summary
NexusClient()
           
 
Method Summary
<T extends NexusObject>
void
subscribe(Address<T> addr, Callback<T> callback)
          Requests to subscribe to the object identified by the supplied address.
<T extends NexusObject>
Callback<Address<T>>
subscriber(Callback<T> callback)
          Creates a callback that will subscribe to an object of the specified address and pass the successfully subscribed object through to the supplied callback.
 void unsubscribe(NexusObject object)
          Unsubscribes from the specified object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NexusClient

public NexusClient()
Method Detail

subscribe

public <T extends NexusObject> void subscribe(Address<T> addr,
                                              Callback<T> callback)
Requests to subscribe to the object identified by the supplied address.


unsubscribe

public void unsubscribe(NexusObject object)
Unsubscribes from the specified object. Any events in-flight will be sent to the server, and any events generated after this unsubscription request will be dropped.


subscriber

public <T extends NexusObject> Callback<Address<T>> subscriber(Callback<T> callback)
Creates a callback that will subscribe to an object of the specified address and pass the successfully subscribed object through to the supplied callback. All failures will be propagated through to the supplied callback as well. This simplifies the handling of a common pattern, which is to make a service request, receive an object address in response and immediately subscribe to the object in question. One can write code like so:
// assume RoomService.joinRoom (String roomId, Callback<Address<RoomObject>> callback);
 obj.joinRoom(roomId, client.subscriber(new Callback<RoomObject>() {
     public void onSuccess (RoomObject obj) { ... }
     public void onFailure (Throwable cause) { ... }
 }));
 



Copyright © 2013. All Rights Reserved.