Fixes for shutdown sequence, including prevention of a race condition

* Throw an exception if any events, runnables or messages are posted after shutdown. These were previosuly being silently ignored. We really should know about them.
* Don't exit the connection manager thread until the object manager thread exits. This fixes a race condition where the wakeup time of the conmgr thread would determine if it shutdown before or after the object manager, meaning it would sometimes ignore messages around shutdown time.
* Add a shutdown constraint to make the client manager shutdown before the invoker/event/conmgr threads. This gives a single point in the shutdown sequence that applications can use as a constraint (TODO: shutdown groups?)
* Emit a log message for each shutdown method call. This could be very useful in production.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5491 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2008-11-03 22:20:16 +00:00
parent 0cb3330de7
commit 82d4f36c1a
4 changed files with 43 additions and 5 deletions
@@ -201,6 +201,10 @@ public class PresentsDObjectMgr
// from interface DObjectManager
public void postEvent (DEvent event)
{
if (!_running) {
throw new IllegalStateException("Object manager has been shutdown");
}
// assign the event's id and append it to the queue
event.eventId = getNextEventId(true);
_evqueue.append(event);
@@ -273,6 +277,10 @@ public class PresentsDObjectMgr
*/
public void postRunnable (Runnable unit)
{
if (!_running) {
throw new IllegalStateException("Object manager has been shutdown");
}
// just append it to the queue
_evqueue.append(unit);
}
@@ -563,6 +571,15 @@ public class PresentsDObjectMgr
}
}
/**
* Tests if the event processing thread is still running. This is required by the
* {@link ConnectionManager} to ensure messages posted just before or during shutdown are sent.
*/
public synchronized boolean isRunning ()
{
return _running;
}
/**
* Processes a single unit from the queue.
*/
@@ -790,11 +807,6 @@ public class PresentsDObjectMgr
}
}
protected synchronized boolean isRunning ()
{
return _running;
}
protected int getNextOid ()
{
// look for the next unused oid. in theory if we had two billion objects, this would loop