com.threerings.crowd.client
Class OccupantDirector

java.lang.Object
  extended by com.threerings.presents.client.BasicDirector
      extended by com.threerings.crowd.client.OccupantDirector
All Implemented Interfaces:
LocationObserver, SessionObserver, ChangeListener, SetListener<OccupantInfo>

public class OccupantDirector
extends BasicDirector
implements LocationObserver, SetListener<OccupantInfo>

The occupant director listens for occupants of places to enter and exit, and dispatches notices to interested parties about these events.

It will eventually provide a framework for keeping track of occupant information in a network efficient manner. The idea being that we want to store as little information about occupants as possible in the place object (probably just body oid and username), but upon entering a place, this will be all we know about the occupants. We then dispatch a request to get information about all of the occupants in the room (things like avatar information for a graphical display or perhaps their ratings in the game that is associated with a place for a gaming site) which we then pass on to the occupant observers when it becomes available.

This information would be cached and we could return cached information for occupants for which we have cached info. We will probably want to still make a request for the occupant info so that we can update non-static occupant data rather than permanently using what's in the cache.


Field Summary
protected  com.samskivert.util.ObserverList<OccupantObserver> _observers
          The occupant observers to keep abreast of occupant antics.
protected  PlaceObject _place
          The user's current location.
 
Fields inherited from class com.threerings.presents.client.BasicDirector
_availableInStandalone, _ctx
 
Constructor Summary
OccupantDirector(CrowdContext ctx)
          Constructs a new occupant director with the supplied context.
 
Method Summary
 void addOccupantObserver(OccupantObserver obs)
          Adds the specified occupant observer to the list.
 void clientDidLogoff(Client client)
          Called after the client has been logged off of the server and has disconnected.
 void entryAdded(EntryAddedEvent<OccupantInfo> event)
          Deals with all of the processing when an occupant shows up.
 void entryRemoved(EntryRemovedEvent<OccupantInfo> event)
          Deals with all of the processing when an occupant leaves.
 void entryUpdated(EntryUpdatedEvent<OccupantInfo> event)
          Deals with all of the processing when an occupant is updated.
 OccupantInfo getOccupantInfo(int bodyOid)
          Returns the occupant info for the user in question if it exists in the currently occupied place.
 OccupantInfo getOccupantInfo(Name username)
          Returns the occupant info for the user in question if it exists in the currently occupied place.
 void locationChangeFailed(int placeId, String reason)
          This is called on all location observers when a location change request is rejected by the server or fails for some other reason.
 void locationDidChange(PlaceObject place)
          Called when we have switched to a new location.
 boolean locationMayChange(int placeId)
          Called when someone has requested that we switch to a new location.
 void removeOccupantObserver(OccupantObserver obs)
          Removes the specified occupant observer from the list.
 
Methods inherited from class com.threerings.presents.client.BasicDirector
assertAvailable, clientDidLogon, clientObjectDidChange, clientObjectUpdated, clientWillLogon, fetchServices, isAvailable, isAvailableInStandalone, registerServices, setAvailableInStandalone
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_observers

protected com.samskivert.util.ObserverList<OccupantObserver> _observers
The occupant observers to keep abreast of occupant antics.


_place

protected PlaceObject _place
The user's current location.

Constructor Detail

OccupantDirector

public OccupantDirector(CrowdContext ctx)
Constructs a new occupant director with the supplied context.

Method Detail

addOccupantObserver

public void addOccupantObserver(OccupantObserver obs)
Adds the specified occupant observer to the list.


removeOccupantObserver

public void removeOccupantObserver(OccupantObserver obs)
Removes the specified occupant observer from the list.


getOccupantInfo

public OccupantInfo getOccupantInfo(int bodyOid)
Returns the occupant info for the user in question if it exists in the currently occupied place. Returns null if no occupant info exists for the specified body.


getOccupantInfo

public OccupantInfo getOccupantInfo(Name username)
Returns the occupant info for the user in question if it exists in the currently occupied place. Returns null if no occupant info exists with the specified username.


clientDidLogoff

public void clientDidLogoff(Client client)
Description copied from interface: SessionObserver
Called after the client has been logged off of the server and has disconnected.

Specified by:
clientDidLogoff in interface SessionObserver
Overrides:
clientDidLogoff in class BasicDirector

locationMayChange

public boolean locationMayChange(int placeId)
Description copied from interface: LocationObserver
Called when someone has requested that we switch to a new location. An observer may choose to veto the location change request for some reason or other.

Specified by:
locationMayChange in interface LocationObserver
Returns:
true if it's OK for the location to change, false if the change request should be aborted.

locationDidChange

public void locationDidChange(PlaceObject place)
Description copied from interface: LocationObserver
Called when we have switched to a new location.

Specified by:
locationDidChange in interface LocationObserver
Parameters:
place - the place object that represents the new location or null if we have switched to no location.

locationChangeFailed

public void locationChangeFailed(int placeId,
                                 String reason)
Description copied from interface: LocationObserver
This is called on all location observers when a location change request is rejected by the server or fails for some other reason.

Specified by:
locationChangeFailed in interface LocationObserver
Parameters:
placeId - the place id to which we attempted to relocate, but failed.
reason - the reason code that explains why the location change request was rejected or otherwise failed.

entryAdded

public void entryAdded(EntryAddedEvent<OccupantInfo> event)
Deals with all of the processing when an occupant shows up.

Specified by:
entryAdded in interface SetListener<OccupantInfo>
Parameters:
event - The event that was dispatched on the object.

entryUpdated

public void entryUpdated(EntryUpdatedEvent<OccupantInfo> event)
Deals with all of the processing when an occupant is updated.

Specified by:
entryUpdated in interface SetListener<OccupantInfo>
Parameters:
event - The event that was dispatched on the object.

entryRemoved

public void entryRemoved(EntryRemovedEvent<OccupantInfo> event)
Deals with all of the processing when an occupant leaves.

Specified by:
entryRemoved in interface SetListener<OccupantInfo>
Parameters:
event - The event that was dispatched on the object.