From 7ad883b4f66f2fe4403238607ff6969b1b06ef22 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 11 Aug 2001 01:00:26 +0000 Subject: [PATCH] Added the ability to post runnable units of executable code onto the distributed object manager thread. These are slipped into the normal event processing loop. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@222 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsDObjectMgr.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java index 5d99cca95..7e28fcb36 100644 --- a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java +++ b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java @@ -1,5 +1,5 @@ // -// $Id: PresentsDObjectMgr.java,v 1.13 2001/08/08 21:56:47 mdb Exp $ +// $Id: PresentsDObjectMgr.java,v 1.14 2001/08/11 01:00:26 mdb Exp $ package com.threerings.cocktail.cher.server; @@ -84,6 +84,19 @@ public class CherDObjectMgr implements DObjectManager // nothing to do here, our objects live forever! } + /** + * Posts a self-contained unit of code that should be run on the + * distributed object manager thread at the next available + * opportunity. The code will be queued up with the rest of the events + * and invoked in turn. Like event processing code, the code should + * not take long to complete and should definitely not block. + */ + public void postUnit (Runnable unit) + { + // just append it to the queue + _evqueue.append(unit); + } + /** * Returns the object in the object table with the specified oid or * null if no object has that oid. Be sure only to call this function @@ -107,8 +120,24 @@ public class CherDObjectMgr implements DObjectManager Log.info("DOMGR running."); while (isRunning()) { - // pop the next event off the queue - DEvent event = (DEvent)_evqueue.get(); + // pop the next unit off the queue + Object unit = _evqueue.get(); + + // if this is a runnable, it's just an executable unit that + // should be invoked + if (unit instanceof Runnable) { + try { + ((Runnable)unit).run(); + } catch (Exception e) { + Log.warning("Execution unit failed [unit=" + unit + "]."); + Log.logStackTrace(e); + } + continue; + } + + // otherwise it's an event, so we do more complicated + // processing + DEvent event = (DEvent)unit; // look up the target object DObject target = (DObject)_objects.get(event.getTargetOid());