diff --git a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java index 12c45a95d..831fffe66 100644 --- a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java +++ b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java @@ -45,29 +45,24 @@ import com.threerings.presents.dobj.*; import static com.threerings.presents.Log.log; /** - * The presents distributed object manager implements the {@link - * 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 presents distributed object manager implements the {@link 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. + *
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.
*/
public class PresentsDObjectMgr
implements RootDObjectManager, RunQueue, PresentsServer.Reporter
{
- /** Contains operational statistics that are tracked by the distributed
- * object manager between {@link PresentsServer#Reporter} intervals. The
- * snapshot for the most recently completed period can be requested via
- * {@link #getStats()}. . */
+ /** Contains operational statistics that are tracked by the distributed object manager between
+ * {@link PresentsServer#Reporter} intervals. The snapshot for the most recently completed
+ * period can be requested via {@link #getStats()}. . */
public static class Stats
{
- /** The largest size of the distributed object queue during the
- * period. */
+ /** The largest size of the distributed object queue during the period. */
public int maxQueueSize;
/** The number of events dispatched during the period. */
@@ -79,8 +74,8 @@ public class PresentsDObjectMgr
*/
public PresentsDObjectMgr ()
{
- // we create a dummy object to live as oid zero and we'll use that
- // for some internal event trickery
+ // we create a dummy object to live as oid zero and we'll use that for some internal event
+ // trickery
DObject dummy = new DObject();
dummy.setOid(0);
dummy.setManager(this);
@@ -91,18 +86,16 @@ public class PresentsDObjectMgr
}
/**
- * Sets up an access controller that will be provided to any
- * distributed objects created on the server. The controllers can
- * subsequently be overridden if desired, but a default controller is
- * useful for implementing basic access control policies.
+ * Sets up an access controller that will be provided to any distributed objects created on the
+ * server. The controllers can subsequently be overridden if desired, but a default controller
+ * is useful for implementing basic access control policies.
*/
public void setDefaultAccessController (AccessController controller)
{
AccessController oldDefault = _defaultController;
_defaultController = controller;
- // switch all objects from the old default (null, usually)
- // to the new default.
+ // switch all objects from the old default (null, usually) to the new default.
for (Iterator itr = _objects.elements(); itr.hasNext(); ) {
DObject obj = (DObject) itr.next();
if (oldDefault == obj.getAccessController()) {
@@ -123,12 +116,10 @@ public class PresentsDObjectMgr
int oid, SubscriberObjectDestroyedEvent events. It
- * removes the object from the object table.
+ * Called as a helper for ObjectDestroyedEvent events. It removes the object from
+ * the object table.
*
- * @return true if the event should be dispatched, false if it should
- * be aborted.
+ * @return true if the event should be dispatched, false if it should be aborted.
*/
public boolean objectDestroyed (DEvent event, DObject target)
{
int oid = target.getOid();
-// log.info("Removing destroyed object from table " +
-// "[oid=" + oid + "].");
+// log.info("Removing destroyed object from table [oid=" + oid + "].");
// remove the object from the table
_objects.remove(oid);
@@ -503,20 +478,17 @@ public class PresentsDObjectMgr
// ensure that the referencing object is still around
if (reffer != null) {
// post an object removed event to clear the reference
- postEvent(new ObjectRemovedEvent(
- ref.reffingOid, ref.field, oid));
-// log.info("Forcing removal " + ref + ".");
+ postEvent(new ObjectRemovedEvent(ref.reffingOid, ref.field, oid));
+// log.info("Forcing removal " + ref + ".");
} else {
- log.info("Dangling reference from inactive object " +
- ref + ".");
+ log.info("Dangling reference from inactive object " + ref + ".");
}
}
}
- // if this object has any oid list fields that are still
- // referencing other objects, we need to clear out those
- // references
+ // if this object has any oid list fields that are still referencing other objects, we need
+ // to clear out those references
Class oclass = target.getClass();
Field[] fields = oclass.getFields();
for (int f = 0; f < fields.length; f++) {
@@ -524,8 +496,7 @@ public class PresentsDObjectMgr
// ignore static and non-public fields
int mods = field.getModifiers();
- if ((mods & Modifier.STATIC) != 0 ||
- (mods & Modifier.PUBLIC) == 0) {
+ if ((mods & Modifier.STATIC) != 0 || (mods & Modifier.PUBLIC) == 0) {
continue;
}
@@ -541,8 +512,8 @@ public class PresentsDObjectMgr
}
} catch (Exception e) {
- log.warning("Unable to clean up after oid list field " +
- "[target=" + target + ", field=" + field + "].");
+ log.warning("Unable to clean up after oid list field [target=" + target +
+ ", field=" + field + "].");
}
}
@@ -550,12 +521,10 @@ public class PresentsDObjectMgr
}
/**
- * Called by objectDestroyed; clears out the tracking
- * info for a reference by the supplied object to the specified oid
- * via the specified field.
+ * Called by objectDestroyed; clears out the tracking info for a reference by the
+ * supplied object to the specified oid via the specified field.
*/
- protected void clearReference (
- DObject reffer, String field, int reffedOid)
+ protected void clearReference (DObject reffer, String field, int reffedOid)
{
// look up the reference vector for the referenced object
Reference[] refs = _refs.get(reffedOid);
@@ -571,16 +540,14 @@ public class PresentsDObjectMgr
}
}
- // if a referred object and referring object are both destroyed without
- // allowing the referred object destruction to process the ObjectRemoved
- // event which is auto-generated, the subsequent destruction of the
- // referring object will attempt to clear the reference to the referred
- // object which no longer exists; so we don't complain about non-
- // existent references if the referree is already destroyed
+ // if a referred object and referring object are both destroyed without allowing the
+ // referred object destruction to process the ObjectRemoved event which is auto-generated,
+ // the subsequent destruction of the referring object will attempt to clear the reference
+ // to the referred object which no longer exists; so we don't complain about non- existent
+ // references if the referree is already destroyed
if (ref == null && _objects.containsKey(reffedOid)) {
log.warning("Requested to clear out non-existent reference " +
- "[refferOid=" + reffer.getOid() +
- ", field=" + field +
+ "[refferOid=" + reffer.getOid() + ", field=" + field +
", reffedOid=" + reffedOid + "].");
// } else {
@@ -589,11 +556,10 @@ public class PresentsDObjectMgr
}
/**
- * Called as a helper for ObjectAddedEvent events. It
- * updates the object/oid list tracking structures.
+ * Called as a helper for ObjectAddedEvent events. It updates the object/oid list
+ * tracking structures.
*
- * @return true if the event should be dispatched, false if it should
- * be aborted.
+ * @return true if the event should be dispatched, false if it should be aborted.
*/
public boolean objectAdded (DEvent event, DObject target)
{
@@ -603,14 +569,13 @@ public class PresentsDObjectMgr
// ensure that the target object exists
if (!_objects.containsKey(oid)) {
log.info("Rejecting object added event of non-existent object " +
- "[refferOid=" + target.getOid() +
- ", reffedOid=" + oid + "].");
+ "[refferOid=" + target.getOid() + ", reffedOid=" + oid + "].");
return false;
}
- // get the reference vector for the referenced object. we use bare
- // arrays rather than something like an array list to conserve
- // memory. there will be many objects and references
+ // get the reference vector for the referenced object. we use bare arrays rather than
+ // something like an array list to conserve memory. there will be many objects and
+ // references
Reference[] refs = _refs.get(oid);
if (refs == null) {
refs = new Reference[DEFREFVEC_SIZE];
@@ -622,8 +587,7 @@ public class PresentsDObjectMgr
int rpos = -1;
for (int i = 0; i < refs.length; i++) {
if (ref.equals(refs[i])) {
- log.warning("Ignoring request to track existing " +
- "reference " + ref + ".");
+ log.warning("Ignoring request to track existing reference " + ref + ".");
return true;
} else if (refs[i] == null && rpos == -1) {
rpos = i;
@@ -646,11 +610,10 @@ public class PresentsDObjectMgr
}
/**
- * Called as a helper for ObjectRemovedEvent events. It
- * updates the object/oid list tracking structures.
+ * Called as a helper for ObjectRemovedEvent events. It updates the object/oid
+ * list tracking structures.
*
- * @return true if the event should be dispatched, false if it should
- * be aborted.
+ * @return true if the event should be dispatched, false if it should be aborted.
*/
public boolean objectRemoved (DEvent event, DObject target)
{
@@ -659,20 +622,17 @@ public class PresentsDObjectMgr
int toid = target.getOid();
int oid = ore.getOid();
-// log.info("Processing object removed [from=" + toid +
-// ", roid=" + toid + "].");
+// log.info("Processing object removed [from=" + toid + ", roid=" + toid + "].");
// get the reference vector for the referenced object
Reference[] refs = _refs.get(oid);
if (refs == null) {
- // this can happen normally when an object is destroyed. it
- // will remove itself from the reference system and then
- // generate object removed events for all of its referencees.
+ // this can happen normally when an object is destroyed. it will remove itself from the
+ // reference system and then generate object removed events for all of its referencees.
// so we opt not to log anything in this case
-// log.info("Object removed without reference to track it " +
-// "[toid=" + toid + ", field=" + field +
-// ", oid=" + oid + "].");
+// log.info("Object removed without reference to track it [toid=" + toid +
+// ", field=" + field + ", oid=" + oid + "].");
return true;
}
@@ -686,15 +646,14 @@ public class PresentsDObjectMgr
}
}
- log.warning("Unable to locate reference for removal " +
- "[reffingOid=" + toid + ", field=" + field +
- ", reffedOid=" + oid + "].");
+ log.warning("Unable to locate reference for removal [reffingOid=" + toid +
+ ", field=" + field + ", reffedOid=" + oid + "].");
return true;
}
/**
- * Should not need to be called except by the invoker during shutdown
- * to ensure that things are proceeding smoothly.
+ * Should not need to be called except by the invoker during shutdown to ensure that things are
+ * proceeding smoothly.
*/
public boolean queueIsEmpty ()
{
@@ -708,35 +667,28 @@ public class PresentsDObjectMgr
protected int getNextOid ()
{
- // look for the next unused oid. in theory if we had two billion
- // objects, this would loop infinitely, but the world would have
- // come to an end long before we had two billion objects
+ // look for the next unused oid. in theory if we had two billion objects, this would loop
+ // infinitely, but the world will come to an end long before we have two billion objects
do {
_nextOid = (_nextOid + 1) % Integer.MAX_VALUE;
} while (_objects.containsKey(_nextOid));
-
return _nextOid;
}
// from interface PresentsServer.Reporter
- public void appendReport (
- StringBuilder report, long now, long sinceLast, boolean reset)
+ public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset)
{
report.append("* presents.PresentsDObjectMgr:\n");
int queueSize = _evqueue.size();
report.append("- Queue size: ").append(queueSize).append("\n");
- report.append("- Max queue size: ").append(_current.maxQueueSize);
- report.append("\n");
- report.append("- Units executed: ").append(_current.eventCount);
- report.append("\n");
+ report.append("- Max queue size: ").append(_current.maxQueueSize).append("\n");
+ report.append("- Units executed: ").append(_current.eventCount).append("\n");
if (UNIT_PROF_ENABLED) {
- report.append("- Unit profiles: ").append(_profiles.size());
- report.append("\n");
+ report.append("- Unit profiles: ").append(_profiles.size()).append("\n");
for (Map.Entry