public class PresentsDObjectMgr extends Object implements RootDObjectManager
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.
| Modifier and Type | Class and Description |
|---|---|
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.
|
static class |
PresentsDObjectMgr.Stats
Returned by
getStats(boolean). |
RunQueue.AsExecutor| Constructor and Description |
|---|
PresentsDObjectMgr(ReportManager repmgr)
Creates the dobjmgr and prepares it for operation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearProxyObject(int origObjectId,
DObject object)
Clears a proxy object reference from our local distributed object space.
|
void |
clearUnitProfiles()
Clears the current set of unit profiles.
|
void |
destroyObject(int oid)
Requests that the specified object be destroyed.
|
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.
|
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.
|
void |
harshShutdown()
Requests that the dobjmgr shut itself down directly.
|
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.
|
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. |
<T extends DObject> |
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.
|
<T extends DObject> |
subscribeToObject(int oid,
Subscriber<T> target)
Requests that the specified subscriber be subscribed to the object identified by the
supplied object id.
|
<T extends DObject> |
unsubscribeFromObject(int oid,
Subscriber<T> target)
Requests that the specified subscriber be unsubscribed from the object identified by the
supplied object id.
|
@Inject public PresentsDObjectMgr(ReportManager repmgr)
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)
DObjectManagerisManager in interface DObjectManagerpublic <T extends DObject> void subscribeToObject(int oid, Subscriber<T> target)
DObjectManagersubscribeToObject 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)
DObjectManagerunsubscribeFromObject 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)
DObjectManagerremovedLastSubscriber in interface DObjectManagerpublic <T extends DObject> T registerObject(T object)
RootDObjectManagerregisterObject in interface RootDObjectManagerpublic void destroyObject(int oid)
RootDObjectManagerdestroyObject 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<T>).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 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()
Copyright © 2015. All rights reserved.