diff --git a/src/java/com/threerings/crowd/server/CrowdServer.java b/src/java/com/threerings/crowd/server/CrowdServer.java index aca83484e..146a7d73d 100644 --- a/src/java/com/threerings/crowd/server/CrowdServer.java +++ b/src/java/com/threerings/crowd/server/CrowdServer.java @@ -54,7 +54,7 @@ public class CrowdServer extends PresentsServer { @Override protected void configure () { super.configure(); - bind(PresentsServer.class).to(CrowdServer.class); + // nada (yet) } } diff --git a/src/java/com/threerings/presents/server/AbstractSignalHandler.java b/src/java/com/threerings/presents/server/AbstractSignalHandler.java index 7af3eb62a..8a7d0692e 100644 --- a/src/java/com/threerings/presents/server/AbstractSignalHandler.java +++ b/src/java/com/threerings/presents/server/AbstractSignalHandler.java @@ -52,7 +52,7 @@ public abstract class AbstractSignalHandler protected void termReceived () { log.info("Shutdown initiated by TERM signal."); - _server.queueShutdown(); + _shutmgr.queueShutdown(); } /** @@ -61,7 +61,7 @@ public abstract class AbstractSignalHandler protected void intReceived () { log.info("Shutdown initiated by INT signal."); - _server.queueShutdown(); + _shutmgr.queueShutdown(); } /** @@ -72,6 +72,6 @@ public abstract class AbstractSignalHandler log.info(_repmgr.generateReport()); } - @Inject protected PresentsServer _server; + @Inject protected ShutdownManager _shutmgr; @Inject protected ReportManager _repmgr; } diff --git a/src/java/com/threerings/presents/server/PresentsInvoker.java b/src/java/com/threerings/presents/server/PresentsInvoker.java index 6be89e1fa..162dbd965 100644 --- a/src/java/com/threerings/presents/server/PresentsInvoker.java +++ b/src/java/com/threerings/presents/server/PresentsInvoker.java @@ -34,16 +34,14 @@ import static com.threerings.presents.Log.log; * Extends the generic {@link Invoker} and integrates it a bit more into the Presents system. */ public class PresentsInvoker extends Invoker - implements ReportManager.Reporter + implements ShutdownManager.Shutdowner, ReportManager.Reporter { - /** - * Creates an invoker that will post results to the supplied - * distributed object manager. - */ - @Inject public PresentsInvoker (PresentsDObjectMgr omgr, ReportManager repmgr) + @Inject public PresentsInvoker (PresentsDObjectMgr omgr, ShutdownManager shutmgr, + ReportManager repmgr) { super("presents.Invoker", omgr); _omgr = omgr; + shutmgr.registerShutdowner(this); if (PERF_TRACK) { repmgr.registerReporter(this); } diff --git a/src/java/com/threerings/presents/server/PresentsServer.java b/src/java/com/threerings/presents/server/PresentsServer.java index 411caab4a..edf0ef830 100644 --- a/src/java/com/threerings/presents/server/PresentsServer.java +++ b/src/java/com/threerings/presents/server/PresentsServer.java @@ -51,6 +51,7 @@ import static com.threerings.presents.Log.log; */ @Singleton public class PresentsServer + implements ShutdownManager.Shutdowner { /** Configures dependencies needed by the Presents services. */ public static class Module extends AbstractModule @@ -141,6 +142,9 @@ public class PresentsServer injector.getInstance(NativeSignalHandler.class).init(); } + // register with the shutdown manager to provide legacy centralized shutdown support + _shutmgr.registerShutdowner(this); + // configure the dobject manager with our access controller _omgr.setDefaultAccessController(createDefaultObjectAccessController()); @@ -221,36 +225,9 @@ public class PresentsServer omgr.run(); } - /** - * Requests that the server shut down. All registered shutdown participants will be shut down, - * following which the server process will be terminated. - */ + // from interface ShutdownManager.Shutdowner public void shutdown () { - // shutdown all registered shutdowners - _shutmgr.shutdown(); - - // shut down the connection manager (this will cease all network activity but not actually - // close the connections) - if (_conmgr.isRunning()) { - _conmgr.shutdown(); - } - - // finally shut down the invoker and dobj manager (The invoker does both for us.) - invoker.shutdown(); - } - - /** - * Queues up a request to shutdown on the dobjmgr thread. This method may be safely called from - * any thread. - */ - public void queueShutdown () - { - omgr.postRunnable(new Runnable() { - public void run () { - shutdown(); - } - }); } /** diff --git a/src/java/com/threerings/presents/server/ShutdownManager.java b/src/java/com/threerings/presents/server/ShutdownManager.java index 95e8334f6..2c6857576 100644 --- a/src/java/com/threerings/presents/server/ShutdownManager.java +++ b/src/java/com/threerings/presents/server/ShutdownManager.java @@ -21,9 +21,13 @@ package com.threerings.presents.server; +import com.google.inject.Inject; import com.google.inject.Singleton; import com.samskivert.util.ObserverList; +import com.samskivert.util.RunQueue; + +import com.threerings.presents.annotation.EventQueue; import static com.threerings.presents.Log.log; @@ -42,6 +46,11 @@ public class ShutdownManager public void shutdown (); } + @Inject ShutdownManager (@EventQueue RunQueue dobjq) + { + _dobjq = dobjq; + } + /** * Registers an entity that will be notified when the server is shutting down. */ @@ -58,6 +67,22 @@ public class ShutdownManager _downers.remove(downer); } + /** + * Queues up a request to shutdown on the dobjmgr thread. This method may be safely called from + * any thread. + */ + public void queueShutdown () + { + _dobjq.postRunnable(new Runnable() { + public void run () { + shutdown(); + } + }); + } + + /** + * Shuts down all shutdowners immediately on the caller's thread. + */ public void shutdown () { ObserverList downers = _downers; @@ -76,6 +101,9 @@ public class ShutdownManager }); } + /** The queue we'll use to get onto the dobjmgr thread before shutting down. */ + protected RunQueue _dobjq; + /** A list of shutdown participants. */ protected static ObserverList _downers = ObserverList.newSafeInOrder(); } diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index 55d194719..ca70c5434 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -67,6 +67,7 @@ import com.threerings.presents.util.DatagramSequencer; import com.threerings.presents.server.Authenticator; import com.threerings.presents.server.PresentsDObjectMgr; import com.threerings.presents.server.ReportManager; +import com.threerings.presents.server.ShutdownManager; import static com.threerings.presents.Log.log; @@ -78,14 +79,15 @@ import static com.threerings.presents.Log.log; */ @Singleton public class ConnectionManager extends LoopingThread - implements ReportManager.Reporter + implements ShutdownManager.Shutdowner, ReportManager.Reporter { /** * Creates a connection manager instance. Don't call this, Guice will do it for you. */ - @Inject public ConnectionManager (ReportManager repmgr) + @Inject public ConnectionManager (ShutdownManager shutmgr, ReportManager repmgr) { super("ConnectionManager"); + shutmgr.registerShutdowner(this); repmgr.registerReporter(this); }