|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.server.PresentsDObjectMgr
public class PresentsDObjectMgr
The presents distributed object manager implements the DObjectManager interface,
providing an object manager that runs on the server. By virtue of running on the server, it
manages its objects directly rather than managing proxies of objects which is what is done on
the client. Thus it simply queues up events and dispatches them to listeners.
The server object manager is meant to run on the main thread of the server application and thus provides a method to be invoked by the application main thread which won't return until the manager has been requested to shut down.
| Nested Class Summary | |
|---|---|
protected class |
PresentsDObjectMgr.AccessObjectEvent<T extends DObject>
Used to make an object available to a subscriber (with or without the associated subscription). |
protected static interface |
PresentsDObjectMgr.EventHelper
Does some helpy bits for certain events. |
static interface |
PresentsDObjectMgr.LongRunnable
Post instances of these if you know you're going to tie up the distributed object thread for a long time and don't want a spurious warning. |
protected static class |
PresentsDObjectMgr.ProxyReference
Tracks necessary information on a proxy distributed object. |
protected static class |
PresentsDObjectMgr.Reference
Used to track references of objects in oid lists. |
static class |
PresentsDObjectMgr.Stats
Returned by getStats(boolean). |
protected static class |
PresentsDObjectMgr.UnitProfile
Used to profile time spent invoking units and processing events if such profiling is enabled. |
| Nested classes/interfaces inherited from interface com.samskivert.util.RunQueue |
|---|
RunQueue.AsExecutor |
| Field Summary | |
|---|---|
protected PresentsDObjectMgr.Stats |
_current
Used to track runtime statistics. |
protected AccessController |
_defaultController
The default access controller to use when creating distributed objects. |
protected Thread |
_dobjThread
keeps Track of which thread is executing the event loop so that other services can enforce restrictions on code that should or should not be called from the event dispatch thread. |
protected long |
_eventCount
Used to track the number of events dispatched over time. |
protected Queue<Object> |
_evqueue
The event queue via which all events are processed. |
protected Throttle |
_fatalThrottle
Track fatal errors so that we can stick a fork in ourselves if things get too far out of hand. |
protected Map<Class<?>,PresentsDObjectMgr.EventHelper> |
_helpers
Maps event classes to helpers that perform additional processing for particular events. |
protected InvocationManager |
_invmgr
Used to resolve unit names when profiling. |
protected long |
_nextEventId
A monotonically increasing counter used to assign an id to all dispatched events. |
protected int |
_nextOid
Used to assign a unique oid to each distributed object. |
protected IntMap<DObject> |
_objects
The managed distributed objects table. |
protected Map<String,PresentsDObjectMgr.UnitProfile> |
_profiles
Used to profile our events and runnable units. |
protected IntMap<PresentsDObjectMgr.ProxyReference> |
_proxies
Maintains proxy information for any proxied distributed objects. |
protected PresentsDObjectMgr.Stats |
_recent
Used to track runtime statistics. |
protected IntMap<PresentsDObjectMgr.Reference[]> |
_refs
Used to track oid list references of distributed objects. |
protected boolean |
_running
A flag indicating that the event dispatcher is still running. |
protected int |
_unitProfInterval
The frequency at which we take a profiling sample. |
protected static int |
DEFREFVEC_SIZE
The default size of an oid list refs vector. |
protected static int |
DUMMY_OID
The oid of the DOject created during object manager startup that isn't actually distributed. |
protected static boolean |
UNIT_PROF_ENABLED
Whether or not unit profiling is enabled. |
| Fields inherited from interface com.samskivert.util.RunQueue |
|---|
AWT |
| Constructor Summary | |
|---|---|
PresentsDObjectMgr(ReportManager repmgr)
Creates the dobjmgr and prepares it for operation. |
|
| Method Summary | ||
|---|---|---|
void |
clearProxyObject(int origObjectId,
DObject object)
Clears a proxy object reference from our local distributed object space. |
|
protected void |
clearReference(DObject reffer,
String field,
int reffedOid)
Called by objectDestroyed; clears out the tracking info for a reference by the
supplied object to the specified oid via the specified field. |
|
void |
clearUnitProfiles()
Clears the current set of unit profiles. |
|
void |
destroyObject(int oid)
Requests that the specified object be destroyed. |
|
protected boolean |
dispatchEvent(DEvent event,
DObject target)
Dispatches an event after the target object has been resolved and the permissions have been checked. |
|
void |
dumpUnitProfiles()
Dumps collected profiling information to the system log. |
|
void |
execute(Runnable command)
|
|
long |
getNextEventId(boolean increment)
Returns the id to be assigned to the next event posted to the event queue. |
|
protected int |
getNextOid()
|
|
DObject |
getObject(int oid)
Returns the object in the object table with the specified oid or null if no object has that oid. |
|
PresentsDObjectMgr.Stats |
getStats(boolean snapshot)
Returns a recent snapshot of runtime statistics tracked by the distributed object manager. |
|
int |
getUnitProfInterval()
Returns the profiling sample frequency. |
|
protected void |
handleFatalError(Object causer,
Error error)
Attempts to recover from fatal errors but rethrows if things are freaking out too frequently. |
|
void |
harshShutdown()
Requests that the dobjmgr shut itself down directly. |
|
protected static
|
informObjectAvailable(Subscriber<T> sub,
T obj)
Calls Subscriber.objectAvailable(T) and catches and logs any exception thrown by the
subscriber during the call. |
|
boolean |
isDispatchThread()
Returns true if the thread invoking this method is the same thread that is doing distributed object event dispatch. |
|
boolean |
isManager(DObject object)
Returns true if this distributed object manager is the authoritative manager for the specified distributed object, or false if we are only providing a proxy to the object. |
|
boolean |
isRunning()
Tests if the event processing thread is still running. |
|
Interval |
newInterval(Runnable action)
Creates an Interval that runs the supplied runnable. |
|
boolean |
objectAdded(DEvent event,
DObject target)
Called as a helper for ObjectAddedEvent events. |
|
boolean |
objectDestroyed(DEvent event,
DObject target)
Called as a helper for ObjectDestroyedEvent events. |
|
boolean |
objectRemoved(DEvent event,
DObject target)
Called as a helper for ObjectRemovedEvent events. |
|
void |
postEvent(DEvent event)
Posts a distributed object event into the system. |
|
void |
postRunnable(Runnable unit)
Posts a self-contained unit of code that should be run on the distributed object manager thread at the next available opportunity. |
|
protected void |
processCompoundEvent(CompoundEvent event)
Performs the processing associated with a compound event, notifying listeners and the like. |
|
protected void |
processEvent(DEvent event)
Performs the processing associated with an event, notifying listeners and the like. |
|
protected void |
processUnit(Object unit)
Processes a single unit from the queue. |
|
boolean |
queueIsEmpty()
Should not need to be called except by the invoker during shutdown to ensure that things are proceeding smoothly. |
|
void |
refuseEventThread()
Ensures that the calling thread is not the distributed object event dispatch thread, throwing an IllegalStateException if it is. |
|
protected void |
registerEventHelpers()
Registers our event helper methods. |
|
|
registerObject(T object)
Registers a distributed object instance of the supplied class with the system and assigns it an oid. |
|
void |
registerProxyObject(DObject object,
DObjectManager omgr)
Registers an object managed by another distributed object manager (probably on another server). |
|
void |
removedLastSubscriber(DObject obj,
boolean deathWish)
When a distributed object removes its last subscriber, it will call this function to let the object manager know. |
|
void |
requireEventThread()
Ensures that the calling thread is the distributed object event dispatch thread, throwing an IllegalStateException if it is not. |
|
void |
run()
Runs the dobjmgr event loop until it is requested to exit. |
|
void |
setDefaultAccessController(AccessController controller)
Sets up an access controller that will be provided to any distributed objects created on the server. |
|
void |
setUnitProfInterval(int interval)
Sets the frequency at which we take profiling samples. |
|
|
subscribeToObject(int oid,
Subscriber<T> target)
Requests that the specified subscriber be subscribed to the object identified by the supplied object id. |
|
|
unsubscribeFromObject(int oid,
Subscriber<T> target)
Requests that the specified subscriber be unsubscribed from the object identified by the supplied object id. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean _running
protected Queue<Object> _evqueue
protected IntMap<DObject> _objects
protected int _nextOid
protected long _eventCount
protected Throttle _fatalThrottle
protected IntMap<PresentsDObjectMgr.Reference[]> _refs
protected AccessController _defaultController
protected IntMap<PresentsDObjectMgr.ProxyReference> _proxies
protected Thread _dobjThread
protected long _nextEventId
protected Map<String,PresentsDObjectMgr.UnitProfile> _profiles
protected PresentsDObjectMgr.Stats _recent
protected PresentsDObjectMgr.Stats _current
protected Map<Class<?>,PresentsDObjectMgr.EventHelper> _helpers
protected InvocationManager _invmgr
protected int _unitProfInterval
protected static final boolean UNIT_PROF_ENABLED
protected static final int DEFREFVEC_SIZE
protected static final int DUMMY_OID
| Constructor Detail |
|---|
@Inject public PresentsDObjectMgr(ReportManager repmgr)
| Method Detail |
|---|
public long getNextEventId(boolean increment)
increment - if true, the event id will be incremented so that the caller can "claim"
the returned event id.public void setDefaultAccessController(AccessController controller)
public void registerProxyObject(DObject object,
DObjectManager omgr)
public void clearProxyObject(int origObjectId,
DObject object)
public boolean isManager(DObject object)
DObjectManager
isManager in interface DObjectManager
public <T extends DObject> void subscribeToObject(int oid,
Subscriber<T> target)
DObjectManager
subscribeToObject in interface DObjectManageroid - The object id of the distributed object to which subscription is desired.target - The subscriber to be subscribed.Subscriber.objectAvailable(T),
Subscriber.requestFailed(int, com.threerings.presents.dobj.ObjectAccessException)
public <T extends DObject> void unsubscribeFromObject(int oid,
Subscriber<T> target)
DObjectManager
unsubscribeFromObject in interface DObjectManageroid - The object id of the distributed object from which unsubscription is desired.target - The subscriber to be unsubscribed.public void postEvent(DEvent event)
DObjectManagerAttributeChangedEvent can be constructed and posted directly. This
is true for all event types and is useful for situations where one doesn't have access to
the object in question, but needs to affect some event.
This event will be forwarded to the ultimate manager of the object (on the client, this means it will be forwarded to the server) where it will be checked for validity and then applied to the object and dispatched to all its subscribers.
postEvent in interface DObjectManagerevent - The event to be dispatched.
public void removedLastSubscriber(DObject obj,
boolean deathWish)
DObjectManager
removedLastSubscriber in interface DObjectManagerpublic <T extends DObject> T registerObject(T object)
RootDObjectManager
registerObject in interface RootDObjectManagerpublic void destroyObject(int oid)
RootDObjectManager
destroyObject in interface RootDObjectManageroid - The object id of the distributed object to be destroyed.public Interval newInterval(Runnable action)
RootDObjectManagerInterval that runs the supplied runnable. If the root omgr is shutdown
before the interval expires (or if the interval is scheduled to repeat), it will be
automatically cancelled. This makes it easy to schedule fire-and-forget intervals:
_omgr.newInterval(someRunnable).schedule(500); // one shot Interval ival = _omgr.newInterval(someRunnable).schedule(500, true); // repeater
newInterval in interface Interval.FactorynewInterval in interface RootDObjectManagerpublic DObject getObject(int oid)
subscribeToObject(int, com.threerings.presents.dobj.Subscriber) .
getObject in interface RootDObjectManagerpublic PresentsDObjectMgr.Stats getStats(boolean snapshot)
snapshot - if true, the current stats will be snapshotted and reset and the new
snapshot will be returned. If false, the previous snapshot will be returned. If no snapshot
has ever been taken, the current stats that have been accumulting since the JVM start will
be returned.public void execute(Runnable command)
execute in interface Executorpublic void postRunnable(Runnable unit)
postRunnable in interface RunQueuepublic boolean isDispatchThread()
isDispatchThread in interface RunQueuepublic void requireEventThread()
IllegalStateException if it is not. Note: before the manager is started up,
all calls to this method will succeed, as things that take place during server
initialization are considered safe and only after the distributed object manager is started
(and the event thread is established) will we require it.
public void refuseEventThread()
IllegalStateException if it is.
public void run()
public void harshShutdown()
PresentsInvoker.shutdown() which will make sure that both the Invoker and DObjectMgr are
empty and then shut them both down.
public void setUnitProfInterval(int interval)
public int getUnitProfInterval()
public void dumpUnitProfiles()
public void clearUnitProfiles()
public boolean objectDestroyed(DEvent event,
DObject target)
ObjectDestroyedEvent events. It removes the object from
the object table.
public boolean objectAdded(DEvent event,
DObject target)
ObjectAddedEvent events. It updates the object/oid list
tracking structures.
public boolean objectRemoved(DEvent event,
DObject target)
ObjectRemovedEvent events. It updates the object/oid
list tracking structures.
public boolean queueIsEmpty()
public boolean isRunning()
isRunning in interface RunQueueprotected void processUnit(Object unit)
protected void processCompoundEvent(CompoundEvent event)
protected void processEvent(DEvent event)
protected boolean dispatchEvent(DEvent event,
DObject target)
processEvent(com.threerings.presents.dobj.DEvent) and processCompoundEvent(com.threerings.presents.dobj.CompoundEvent).
DEvent.applyToObject(com.threerings.presents.dobj.DObject).
protected void handleFatalError(Object causer,
Error error)
protected void clearReference(DObject reffer,
String field,
int reffedOid)
objectDestroyed; clears out the tracking info for a reference by the
supplied object to the specified oid via the specified field.
protected int getNextOid()
protected void registerEventHelpers()
protected static <T extends DObject> void informObjectAvailable(Subscriber<T> sub,
T obj)
Subscriber.objectAvailable(T) and catches and logs any exception thrown by the
subscriber during the call.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||