com.threerings.presents.server
Class ClientResolver

java.lang.Object
  extended by com.samskivert.util.Invoker.Unit
      extended by com.threerings.presents.server.ClientResolver
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
BureauClientResolver, CrowdClientResolver, PeerClientResolver

public class ClientResolver
extends Invoker.Unit

Used to resolve client data when a user starts a session (or when some other entity needs access to a client object). Implementations will want to extend this class and override resolveClientData(com.threerings.presents.data.ClientObject), making the necessary database calls and populating the client object appropriately.


Nested Class Summary
static class ClientResolver.ClientDisconnectedException
          Thrown during resolution if the client disconnects.
 
Field Summary
protected  ClientManager _clmgr
           
protected  ClientObject _clobj
          The resolving client object.
protected  Exception _failure
          A place to keep an exception around for a moment.
protected  Invoker _invoker
           
protected  List<ClientResolutionListener> _listeners
          The entities to notify of success or failure.
protected  RootDObjectManager _omgr
           
protected  Name _username
          The name of the user whose client object is being resolved.
 
Fields inherited from class com.samskivert.util.Invoker.Unit
_name, queueStamp
 
Constructor Summary
ClientResolver()
           
 
Method Summary
 void addResolutionListener(ClientResolutionListener listener)
          Adds a resolution listener to this active resolver.
 ClientObject createClientObject()
          Creates the ClientObject derived class that should be created to kick off the resolution process.
 ClientLocal createLocalAttribute()
          Creates a record that will be maintained only on the server to track client related bits.
protected  void enforceConnected()
          Throws an exception if the client being resolved is no longer connected.
protected  void finishResolution(ClientObject clobj)
          This method is called on the dobj thread after resolveClientData returns normally, it should finish populating the client object with any data that is NOT loaded from a database.
 void handleResult()
           
 void init(Name username)
          Initializes this instance.
 boolean invoke()
           
 void objectAvailable(ClientObject object)
          Called once our client object is registered with the distributed object system.
protected  void reportFailure(Exception cause)
          Reports failure to our resolution listeners.
protected  void reportSuccess()
          Reports success to our resolution listeners.
protected  void resolveClientData(ClientObject clobj)
          This method is called on the invoker thread which means that it can do things like blocking database requests and generally whatever is necessary to load up all the client data that is desired by the implentation system.
 String toString()
           
 
Methods inherited from class com.samskivert.util.Invoker.Unit
getDetail, getLongThreshold, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_username

protected Name _username
The name of the user whose client object is being resolved.


_listeners

protected List<ClientResolutionListener> _listeners
The entities to notify of success or failure.


_clobj

protected ClientObject _clobj
The resolving client object.


_failure

protected Exception _failure
A place to keep an exception around for a moment.


_invoker

@Inject
protected Invoker _invoker

_omgr

@Inject
protected RootDObjectManager _omgr

_clmgr

@Inject
protected ClientManager _clmgr
Constructor Detail

ClientResolver

public ClientResolver()
Method Detail

init

public void init(Name username)
Initializes this instance.

Parameters:
username - the username of the user to be resolved.

addResolutionListener

public void addResolutionListener(ClientResolutionListener listener)
Adds a resolution listener to this active resolver.


createClientObject

public ClientObject createClientObject()
Creates the ClientObject derived class that should be created to kick off the resolution process.


createLocalAttribute

public ClientLocal createLocalAttribute()
Creates a record that will be maintained only on the server to track client related bits.


objectAvailable

public void objectAvailable(ClientObject object)
Called once our client object is registered with the distributed object system.


invoke

public boolean invoke()
Specified by:
invoke in class Invoker.Unit

handleResult

public void handleResult()
Overrides:
handleResult in class Invoker.Unit

toString

public String toString()
Overrides:
toString in class Invoker.Unit

resolveClientData

protected void resolveClientData(ClientObject clobj)
                          throws Exception
This method is called on the invoker thread which means that it can do things like blocking database requests and generally whatever is necessary to load up all the client data that is desired by the implentation system. Any exceptions that are thrown will be caught and reported as a failure to the client resolution listener.

Throws:
Exception

finishResolution

protected void finishResolution(ClientObject clobj)
This method is called on the dobj thread after resolveClientData returns normally, it should finish populating the client object with any data that is NOT loaded from a database.


reportSuccess

protected void reportSuccess()
Reports success to our resolution listeners.


reportFailure

protected void reportFailure(Exception cause)
Reports failure to our resolution listeners.


enforceConnected

protected void enforceConnected()
                         throws ClientResolver.ClientDisconnectedException
Throws an exception if the client being resolved is no longer connected.

Throws:
ClientResolver.ClientDisconnectedException