Added a mechanism to check that we are running on (or not on) the

distributed object event dispatch thread.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2005 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-11-28 22:51:52 +00:00
parent 130d126238
commit f7c27a1afa
@@ -1,5 +1,5 @@
//
// $Id: PresentsDObjectMgr.java,v 1.26 2002/11/05 02:17:56 mdb Exp $
// $Id: PresentsDObjectMgr.java,v 1.27 2002/11/28 22:51:52 mdb Exp $
package com.threerings.presents.server;
@@ -129,6 +129,17 @@ public class PresentsDObjectMgr
return (DObject)_objects.get(oid);
}
/**
* Returns true if the thread invoking this method is the same thread
* that is doing distributed object event dispatch. Code that wishes
* to enforce that it is either always or never called on the event
* dispatch thread will want to make use of this method.
*/
public synchronized boolean isEventDispatchThread ()
{
return Thread.currentThread() == _dobjThread;
}
/**
* Runs the dobjmgr event loop until it is requested to exit. This
* should be called from the main application thread.
@@ -137,6 +148,11 @@ public class PresentsDObjectMgr
{
Log.info("DOMGR running.");
// make a note of the thread that's processing events
synchronized (this) {
_dobjThread = Thread.currentThread();
}
while (isRunning()) {
// pop the next unit off the queue
Object unit = _evqueue.get();
@@ -760,6 +776,11 @@ public class PresentsDObjectMgr
* objects. */
protected AccessController _defaultController;
/** We keep 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 Thread _dobjThread;
/** Check whether we should generate a report every 100 events. */
protected static final long REPORT_CHECK_PERIOD = 100;