|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.crowd.server.PlaceManager
public class PlaceManager
The place manager is the server-side entity that handles all place-related interaction. It subscribes to the place object and reacts to message and other events. Behavior specific to a place (or class of places) should live in the place manager. An intelligently constructed hierarchy of place manager classes working in concert with invocation services should provide the majority of the server-side functionality of an application built on the Presents platform.
The base place manager class takes care of the necessary interactions with the place registry to manage place registration. It handles the place-related component of chatting. It also provides the basis for place-based access control.
A derived class is expected to handle initialization, cleanup and operational functionality
via the calldown functions didInit(), didStartup(), and didShutdown() as
well as through event listeners.
| Nested Class Summary | |
|---|---|
static class |
PlaceManager.DelegateOp
Used to call methods on this place manager's delegates. |
static interface |
PlaceManager.MessageHandler
Deprecated. Use dynamically bound methods instead. See DynamicListener. |
| Field Summary | |
|---|---|
protected SetAdapter<OccupantInfo> |
_bodyUpdater
Listens for occupant updates. |
protected PlaceConfig |
_config
A reference to the configuration for our place. |
protected ObjectDeathListener |
_deathListener
Listens for death of our place object. |
protected List<PlaceManagerDelegate> |
_delegates
A list of the delegates in use by this manager. |
protected DynamicListener<?> |
_dispatcher
Used to do method lookup magic when we receive message events. |
protected static Map<Class<?>,MethodFinder> |
_dispatcherFinders
Maps from a PlaceManager subclass to a MethodFinder for it. |
protected com.google.inject.Injector |
_injector
We use this to inject dependencies into our access controller. |
protected InvocationManager |
_invmgr
The invocation manager with whom we register our game invocation services. |
protected BodyLocator |
_locator
Used to look up body objects by name. |
protected List<InvocationMarshaller<?>> |
_marshallers
A list of services registered with addProvider(com.threerings.presents.server.InvocationProvider, java.lang.Class which will be automatically
cleared when this manager shuts down. |
protected Map<String,PlaceManager.MessageHandler> |
_msghandlers
Message handlers are used to process message events. |
protected HashIntMap<OccupantInfo> |
_occInfo
Used to keep a canonical copy of the occupant info records. |
protected OidListListener |
_occListener
Listens for body entry and departure. |
protected RootDObjectManager |
_omgr
A distributed object manager for doing dobj stuff. |
protected PlaceObject |
_plobj
A reference to the place object that we manage. |
protected PlaceRegistry |
_registry
A reference to the place registry with which we're registered. |
protected Interval |
_shutdownInterval
The interval currently registered to shut this place down after a certain period of idility, or null if no interval is currently registered. |
| Constructor Summary | |
|---|---|
PlaceManager()
|
|
| Method Summary | ||
|---|---|---|
void |
addDelegate(PlaceManagerDelegate delegate)
Adds the supplied delegate to the list for this manager. |
|
protected
|
addDispatcher(InvocationDispatcher<T> disp)
Registers an invocation dispatcher and notes the registration such that it will be automatically cleared when this manager shuts down. |
|
protected void |
addOccupantInfo(BodyObject body,
OccupantInfo info)
Adds this occupant's info to the PlaceObject. |
|
protected
|
addProvider(InvocationProvider prov,
Class<T> mclass)
Registers an invocation provider and notes the registration such that it will be automatically cleared when this manager shuts down. |
|
void |
applyToDelegates(PlaceManager.DelegateOp op)
Applies the supplied operation to this manager's registered delegates. |
|
void |
applyToOccupants(OccupantOp op)
Applies the supplied occupant operation to each occupant currently present in this place. |
|
protected void |
bodyEntered(int bodyOid)
Called when a body object enters this place. |
|
protected void |
bodyLeft(int bodyOid)
Called when a body object leaves this place. |
|
protected void |
bodyUpdated(OccupantInfo info)
Called when a body's occupant info is updated. |
|
void |
bodyWillEnter(BodyObject body)
This is called to inform the manager that a body is on the way in. |
|
void |
bodyWillLeave(BodyObject body)
Called to inform a manager that a body is about to leave this place. |
|
protected void |
cancelShutdowner()
Cancels any registered shutdown interval. |
|
String |
checkPermissions()
Provides an opportunity for place managers to ratify the creation of a place based on whatever criterion they may require (based on information available to the manager at this post-init() but pre-startup() phase of initialization). |
|
protected void |
checkShutdownInterval()
Called on startup and when the place is empty. |
|
protected PlaceObject |
createPlaceObject()
Derived classes will generally override this method to create a custom PlaceObject
derivation that contains extra information. |
|
protected SpeakHandler |
createSpeakHandler(PlaceObject plobj)
Creates the speak handler for this place. |
|
protected void |
didInit()
Called after this place manager has been initialized with its configuration information but before it has been started up with its place object reference. |
|
protected void |
didShutdown()
Called when this place has been destroyed and the place manager has shut down (via a call to shutdown()). |
|
protected void |
didStartup()
Derived classes should override this (and be sure to call super.didStartup())
to perform any startup time initialization. |
|
protected AccessController |
getAccessController()
Creates an access controller for this place's distributed object, which by default is CrowdObjectAccess.PlaceAccessController. |
|
PlaceConfig |
getConfig()
Returns a reference to our place configuration object. |
|
Place |
getLocation()
Returns a Place instance that identifies this place. |
|
PlaceObject |
getPlaceObject()
Returns the place object managed by this place manager. |
|
protected Class<? extends PlaceObject> |
getPlaceObjectClass()
Deprecated. Use createPlaceObject(). |
|
protected long |
idleUnloadPeriod()
Returns the period (in milliseconds) of emptiness after which this place manager will unload itself and shutdown. |
|
void |
init(PlaceRegistry registry,
InvocationManager invmgr,
RootDObjectManager omgr,
BodyLocator locator,
PlaceConfig config)
Called by the place registry after creating this place manager. |
|
boolean |
isValidSpeaker(DObject speakObj,
ClientObject speaker,
byte mode)
Should return true if the supplied speaker is allowed to speak via the speak provider with which this validator was registered. |
|
void |
messageReceived(MessageEvent event)
Called when an message event has been dispatched on an object. |
|
protected void |
permissionsFailed()
Called if the permissions check failed, to give place managers a chance to do any cleanup that might be necessary due to their early initialization or permissions checking code. |
|
protected void |
placeBecameEmpty()
Called when we transition from having bodies in the place to not having any bodies in the place. |
|
String |
ratifyBodyEntry(BodyObject body)
Provides an opportunity for the place manager to prevent bodies from entering. |
|
void |
registerMessageHandler(String name,
PlaceManager.MessageHandler handler)
Deprecated. Use dynamically bound methods instead. See DynamicListener. |
|
protected boolean |
shouldCreateSpeakService()
|
|
protected boolean |
shouldDeclareEmpty(OccupantInfo leaver)
Returns whether the location should be marked as empty and potentially shutdown. |
|
void |
shutdown()
Causes the place object being managed by this place manager to be destroyed and the place manager to shut down. |
|
void |
startup(PlaceObject plobj)
Called by the place manager after the place object has been successfully created. |
|
String |
toString()
Generates a string representation of this manager. |
|
protected void |
toString(StringBuilder buf)
An extensible way to add to the string representation of this class. |
|
|
updateOccupantInfo(int bodyOid,
OccupantInfo.Updater<T> updater)
Calls the supplied updater on the canonical occupant info record for the specified body (which must be an occupant of this place) and broadcasts the update to all other occupants. |
|
String |
where()
Returns a string that can be used in log messages to identify the place as sensibly as possible to the developer who has to puzzle over log output trying to figure out what's going on. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected SetAdapter<OccupantInfo> _bodyUpdater
protected OidListListener _occListener
protected ObjectDeathListener _deathListener
@Inject protected com.google.inject.Injector _injector
protected PlaceRegistry _registry
protected InvocationManager _invmgr
protected RootDObjectManager _omgr
protected BodyLocator _locator
protected PlaceObject _plobj
protected PlaceConfig _config
protected Map<String,PlaceManager.MessageHandler> _msghandlers
protected List<PlaceManagerDelegate> _delegates
protected List<InvocationMarshaller<?>> _marshallers
addProvider(com.threerings.presents.server.InvocationProvider, java.lang.Class) which will be automatically
cleared when this manager shuts down.
protected HashIntMap<OccupantInfo> _occInfo
protected Interval _shutdownInterval
protected DynamicListener<?> _dispatcher
protected static Map<Class<?>,MethodFinder> _dispatcherFinders
| Constructor Detail |
|---|
public PlaceManager()
| Method Detail |
|---|
public PlaceConfig getConfig()
public Place getLocation()
Place instance that identifies this place.
public PlaceObject getPlaceObject()
public void applyToOccupants(OccupantOp op)
public <T extends OccupantInfo> boolean updateOccupantInfo(int bodyOid,
OccupantInfo.Updater<T> updater)
ClassCastException - thrown if the type of the supplied updater does not match the
type of OccupantInfo record used for the occupant. Caveat utilitor.
public void init(PlaceRegistry registry,
InvocationManager invmgr,
RootDObjectManager omgr,
BodyLocator locator,
PlaceConfig config)
public void addDelegate(PlaceManagerDelegate delegate)
public void applyToDelegates(PlaceManager.DelegateOp op)
public String checkPermissions()
null should be returned if initialization is to be
allowed to proceed.public void startup(PlaceObject plobj)
public void shutdown()
public String ratifyBodyEntry(BodyObject body)
null if the body can enter, otherwise a translatable message explaining
the reason the body is blocked from enteringpublic void bodyWillEnter(BodyObject body)
bodyEntered(int) once all events relating to
body entry have been processed.
public void bodyWillLeave(BodyObject body)
bodyLeft(int) once all events relating to body entry have been processed.
@Deprecated
public void registerMessageHandler(String name,
PlaceManager.MessageHandler handler)
DynamicListener.
name - the message name of the message events that should be handled by this handler.handler - the handler to be registered.public void messageReceived(MessageEvent event)
MessageListener
messageReceived in interface MessageListenerevent - The event that was dispatched on the object.
public boolean isValidSpeaker(DObject speakObj,
ClientObject speaker,
byte mode)
SpeakHandler.SpeakerValidator
isValidSpeaker in interface SpeakHandler.SpeakerValidatorpublic String where()
public String toString()
toString in class ObjecttoString(StringBuilder)protected PlaceObject createPlaceObject()
PlaceObject
derivation that contains extra information.
@Deprecated protected Class<? extends PlaceObject> getPlaceObjectClass()
createPlaceObject().
protected void didInit()
super.didInit().
protected void permissionsFailed()
protected boolean shouldCreateSpeakService()
protected AccessController getAccessController()
CrowdObjectAccess.PlaceAccessController.
protected void didStartup()
super.didStartup())
to perform any startup time initialization. The place object will be available by the time
this method is executed.
protected void didShutdown()
shutdown()). Derived classes can override this method and perform any necessary
shutdown time processing.
protected <T extends InvocationMarshaller<?>> T addProvider(InvocationProvider prov,
Class<T> mclass)
protected <T extends InvocationMarshaller<?>> T addDispatcher(InvocationDispatcher<T> disp)
protected void bodyEntered(int bodyOid)
protected void bodyLeft(int bodyOid)
protected void addOccupantInfo(BodyObject body,
OccupantInfo info)
PlaceObject. This is called in a transaction on the
place object so if a derived class needs to add additional information for an occupant it
should override this method. It may opt to add the information before calling super if it
wishes to rely on its information being configured when bodyEntered(int) is called.
protected boolean shouldDeclareEmpty(OccupantInfo leaver)
protected void bodyUpdated(OccupantInfo info)
protected void placeBecameEmpty()
protected void checkShutdownInterval()
protected void cancelShutdowner()
protected long idleUnloadPeriod()
0 indicates that the place should never be
shutdown.
protected void toString(StringBuilder buf)
protected SpeakHandler createSpeakHandler(PlaceObject plobj)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||