diff --git a/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java b/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java index 914f8ee63..ee57c4671 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java +++ b/src/java/com/threerings/crowd/chat/server/ChatChannelManager.java @@ -35,6 +35,7 @@ import com.samskivert.util.ArrayIntSet; import com.samskivert.util.IntSet; import com.samskivert.util.Interval; +import com.threerings.util.Lifecycle; import com.threerings.util.Name; import com.threerings.presents.annotation.AnyThread; @@ -43,7 +44,6 @@ import com.threerings.presents.peer.data.ClientInfo; import com.threerings.presents.peer.data.NodeObject; import com.threerings.presents.peer.server.PeerManager; import com.threerings.presents.server.InvocationManager; -import com.threerings.presents.server.LifecycleManager; import com.threerings.presents.server.PresentsDObjectMgr; import com.threerings.crowd.chat.data.ChatChannel; @@ -62,7 +62,7 @@ import static com.threerings.crowd.Log.log; */ @Singleton public abstract class ChatChannelManager - implements ChannelSpeakProvider, LifecycleManager.ShutdownComponent + implements ChannelSpeakProvider, Lifecycle.ShutdownComponent { /** * When a body becomes a member of a channel, this method should be called so that any server @@ -114,7 +114,7 @@ public abstract class ChatChannelManager }); } - // from interface LifecycleManager.Shutdowner + // from interface Lifecycle.Shutdowner public void shutdown () { // stop our channel closer; always be closing... except now @@ -126,10 +126,10 @@ public abstract class ChatChannelManager * Creates our singleton manager and registers our invocation service. */ @Inject protected ChatChannelManager (PresentsDObjectMgr omgr, InvocationManager invmgr, - LifecycleManager lifemgr) + Lifecycle cycle) { invmgr.registerDispatcher(new ChannelSpeakDispatcher(this), CrowdCodes.CROWD_GROUP); - lifemgr.addComponent(this); + cycle.addComponent(this); // create and start our idle channel closer (always be closing) _closer = new Interval(omgr) { diff --git a/src/java/com/threerings/crowd/peer/server/CrowdPeerManager.java b/src/java/com/threerings/crowd/peer/server/CrowdPeerManager.java index a854ff102..80dde0c9a 100644 --- a/src/java/com/threerings/crowd/peer/server/CrowdPeerManager.java +++ b/src/java/com/threerings/crowd/peer/server/CrowdPeerManager.java @@ -23,6 +23,7 @@ package com.threerings.crowd.peer.server; import com.google.inject.Inject; +import com.threerings.util.Lifecycle; import com.threerings.util.Name; import com.threerings.presents.data.ClientObject; @@ -32,7 +33,6 @@ import com.threerings.presents.peer.server.PeerManager; import com.threerings.presents.peer.server.PeerNode; import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationManager; -import com.threerings.presents.server.LifecycleManager; import com.threerings.presents.server.PresentsSession; import com.threerings.crowd.chat.client.ChatService; @@ -51,9 +51,9 @@ public abstract class CrowdPeerManager extends PeerManager /** * Creates an uninitialized peer manager. */ - @Inject public CrowdPeerManager (LifecycleManager lifeMgr) + @Inject public CrowdPeerManager (Lifecycle cycle) { - super(lifeMgr); + super(cycle); } // from interface CrowdPeerProvider diff --git a/src/java/com/threerings/crowd/server/PlaceRegistry.java b/src/java/com/threerings/crowd/server/PlaceRegistry.java index 3d559645d..6fb4d5e48 100644 --- a/src/java/com/threerings/crowd/server/PlaceRegistry.java +++ b/src/java/com/threerings/crowd/server/PlaceRegistry.java @@ -30,11 +30,11 @@ import com.google.inject.Singleton; import com.samskivert.util.IntMap; import com.samskivert.util.IntMaps; +import com.threerings.util.Lifecycle; import com.threerings.presents.dobj.RootDObjectManager; import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationManager; -import com.threerings.presents.server.LifecycleManager; import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.data.PlaceObject; @@ -48,7 +48,7 @@ import static com.threerings.crowd.Log.log; */ @Singleton public class PlaceRegistry - implements LifecycleManager.ShutdownComponent + implements Lifecycle.ShutdownComponent { /** Used in conjunction with {@link PlaceRegistry#createPlace(PlaceConfig,PreStartupHook)}. */ public static interface PreStartupHook @@ -60,9 +60,9 @@ public class PlaceRegistry * Creates and initializes the place registry. This is called by the server during its * initialization phase. */ - @Inject public PlaceRegistry (LifecycleManager lifemgr) + @Inject public PlaceRegistry (Lifecycle cycle) { - lifemgr.addComponent(this); + cycle.addComponent(this); } /** @@ -155,7 +155,7 @@ public class PlaceRegistry return _pmgrs.values().iterator(); } - // from interface LifecycleManager.ShutdownComponent + // from interface Lifecycle.ShutdownComponent public void shutdown () { // shut down all active places diff --git a/src/java/com/threerings/presents/peer/server/PeerManager.java b/src/java/com/threerings/presents/peer/server/PeerManager.java index 535059723..71b390d39 100644 --- a/src/java/com/threerings/presents/peer/server/PeerManager.java +++ b/src/java/com/threerings/presents/peer/server/PeerManager.java @@ -49,6 +49,7 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.io.Streamable; +import com.threerings.util.Lifecycle; import com.threerings.util.Name; import com.threerings.presents.dobj.DObject; @@ -65,7 +66,6 @@ import com.threerings.presents.data.ClientObject; import com.threerings.presents.server.ClientManager; import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationManager; -import com.threerings.presents.server.LifecycleManager; import com.threerings.presents.server.PresentsDObjectMgr; import com.threerings.presents.server.PresentsSession; import com.threerings.presents.server.ReportManager; @@ -86,7 +86,7 @@ import static com.threerings.presents.Log.log; * servers and uses those objects to communicate cross-node information. */ public abstract class PeerManager - implements PeerProvider, ClientManager.ClientObserver, LifecycleManager.ShutdownComponent + implements PeerProvider, ClientManager.ClientObserver, Lifecycle.ShutdownComponent { /** * Used by entities that wish to know when cached data has become stale due to a change on @@ -198,9 +198,9 @@ public abstract class PeerManager /** * Creates an uninitialized peer manager. */ - @Inject public PeerManager (LifecycleManager lifeMgr) + @Inject public PeerManager (Lifecycle cycle) { - lifeMgr.addComponent(this); + cycle.addComponent(this); } /** @@ -753,7 +753,7 @@ public abstract class PeerManager return _stats.clone(); } - // from interface LifecycleManager.ShutdownComponent + // from interface Lifecycle.ShutdownComponent public void shutdown () { if (_nodeName == null) { // sanity check diff --git a/src/java/com/threerings/presents/server/AbstractSignalHandler.java b/src/java/com/threerings/presents/server/AbstractSignalHandler.java index 843353500..19cdad01d 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."); - _lifemgr.queueShutdown(); + _server.queueShutdown(); } /** @@ -61,7 +61,7 @@ public abstract class AbstractSignalHandler protected void intReceived () { log.info("Shutdown initiated by INT signal."); - _lifemgr.queueShutdown(); + _server.queueShutdown(); } /** @@ -72,6 +72,6 @@ public abstract class AbstractSignalHandler log.info(_repmgr.generateReport(ReportManager.DEFAULT_TYPE)); } - @Inject protected LifecycleManager _lifemgr; + @Inject protected PresentsServer _server; @Inject protected ReportManager _repmgr; } diff --git a/src/java/com/threerings/presents/server/ClientManager.java b/src/java/com/threerings/presents/server/ClientManager.java index aabcf71fd..1b887a36b 100644 --- a/src/java/com/threerings/presents/server/ClientManager.java +++ b/src/java/com/threerings/presents/server/ClientManager.java @@ -39,6 +39,7 @@ import com.samskivert.util.Interval; import com.samskivert.util.ObserverList; import com.samskivert.util.StringUtil; +import com.threerings.util.Lifecycle; import com.threerings.util.Name; import com.threerings.presents.annotation.EventThread; @@ -62,7 +63,7 @@ import static com.threerings.presents.Log.log; */ @Singleton public class ClientManager - implements ClientResolutionListener, ReportManager.Reporter, LifecycleManager.Component + implements ClientResolutionListener, ReportManager.Reporter, Lifecycle.Component { /** * Used by {@link ClientManager#applyToClient}. @@ -100,10 +101,10 @@ public class ClientManager /** * Constructs a client manager that will interact with the supplied connection manager. */ - @Inject public ClientManager (ReportManager repmgr, LifecycleManager lifemgr) + @Inject public ClientManager (ReportManager repmgr, Lifecycle cycle) { repmgr.registerReporter(this); - lifemgr.addComponent(this); + cycle.addComponent(this); } /** @@ -323,7 +324,7 @@ public class ClientManager _omgr.destroyObject(clobj.getOid()); } - // from interface LifecycleManager.Component + // from interface Lifecycle.Component public void init () { // start up an interval that will check for and flush expired clients @@ -335,7 +336,7 @@ public class ClientManager _flushClients.schedule(CLIENT_FLUSH_INTERVAL, true); } - // from interface LifecycleManager.Component + // from interface Lifecycle.Component public void shutdown () { log.info("Client manager shutting down", "ccount", _usermap.size()); diff --git a/src/java/com/threerings/presents/server/PresentsInvoker.java b/src/java/com/threerings/presents/server/PresentsInvoker.java index 7f8a6b923..1a408affd 100644 --- a/src/java/com/threerings/presents/server/PresentsInvoker.java +++ b/src/java/com/threerings/presents/server/PresentsInvoker.java @@ -25,6 +25,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.samskivert.util.Invoker; +import com.threerings.util.Lifecycle; import static com.threerings.presents.Log.log; @@ -33,17 +34,16 @@ import static com.threerings.presents.Log.log; */ @Singleton public class PresentsInvoker extends ReportingInvoker - implements LifecycleManager.ShutdownComponent + implements Lifecycle.ShutdownComponent { - @Inject public PresentsInvoker (PresentsDObjectMgr omgr, LifecycleManager lifemgr, - ReportManager repmgr) + @Inject public PresentsInvoker (PresentsDObjectMgr omgr, Lifecycle cycle, ReportManager repmgr) { super("presents.Invoker", omgr, repmgr); + cycle.addComponent(this); _omgr = omgr; - lifemgr.addComponent(this); } - @Override // from Invoker, LifecycleManager.ShutdownComponent + @Override // from Invoker, Lifecycle.ShutdownComponent public void shutdown () { // this will do a sophisticated shutdown of both ourself and the dobjmgr; note: we diff --git a/src/java/com/threerings/presents/server/PresentsServer.java b/src/java/com/threerings/presents/server/PresentsServer.java index 9a2d1437b..f8707b7a2 100644 --- a/src/java/com/threerings/presents/server/PresentsServer.java +++ b/src/java/com/threerings/presents/server/PresentsServer.java @@ -30,6 +30,7 @@ import com.google.inject.Singleton; import com.samskivert.util.Invoker; import com.samskivert.util.RunQueue; import com.samskivert.util.SystemInfo; +import com.threerings.util.Lifecycle; import com.threerings.presents.annotation.AuthInvoker; import com.threerings.presents.annotation.EventQueue; @@ -161,11 +162,11 @@ public class PresentsServer // make the client manager shut down before the invoker and dobj threads; this helps // application code to avoid long chains of shutdown constraints - _lifemgr.addShutdownConstraint( - _clmgr, LifecycleManager.Constraint.RUNS_BEFORE, (PresentsInvoker)_invoker); + _lifecycle.addShutdownConstraint( + _clmgr, Lifecycle.Constraint.RUNS_BEFORE, (PresentsInvoker)_invoker); // initialize all of our registered components - _lifemgr.init(); + _lifecycle.init(); } /** @@ -185,6 +186,19 @@ public class PresentsServer _omgr.run(); } + /** + * Queues up a request to shutdown on the event thread. This method may be safely called from + * any thread. + */ + public void queueShutdown () + { + _omgr.postRunnable(new PresentsDObjectMgr.LongRunnable() { + public void run () { + _lifecycle.shutdown(); + } + }); + } + /** * Defines the default object access policy for all {@link DObject} instances. The default * default policy is to allow all subscribers but reject all modifications by the client. @@ -242,7 +256,7 @@ public class PresentsServer @Inject protected InvocationManager _invmgr; /** Handles orderly initialization and shutdown of our managers, etc. */ - @Inject protected LifecycleManager _lifemgr; + @Inject protected Lifecycle _lifecycle; /** Handles generation of state of the server reports. */ @Inject protected ReportManager _repmgr; diff --git a/src/java/com/threerings/presents/server/RebootManager.java b/src/java/com/threerings/presents/server/RebootManager.java index 37b488b4b..3e219034e 100644 --- a/src/java/com/threerings/presents/server/RebootManager.java +++ b/src/java/com/threerings/presents/server/RebootManager.java @@ -188,9 +188,9 @@ public abstract class RebootManager /** * Provides us with our dependencies. */ - protected RebootManager (LifecycleManager lmgr, RootDObjectManager omgr) + protected RebootManager (PresentsServer server, RootDObjectManager omgr) { - _lmgr = lmgr; + _server = server; _omgr = omgr; } @@ -257,12 +257,7 @@ public abstract class RebootManager // wait 1 second, then do it new Interval() { // Note: This interval does not run on the dobj thread @Override public void expired () { - // ...but we then post a LongRunnable... - _omgr.postRunnable(new PresentsDObjectMgr.LongRunnable() { - public void run () { - _lmgr.shutdown(); - } - }); + _server.queueShutdown(); // this posts a LongRunnable } }.schedule(1000); return; @@ -321,8 +316,8 @@ public abstract class RebootManager }); } - /** Our lifecycle manager, which is how we will reboot. */ - protected LifecycleManager _lmgr; + /** The server that we're going to reboot. */ + protected PresentsServer _server; /** Our distributed object manager. */ protected RootDObjectManager _omgr; diff --git a/src/java/com/threerings/presents/server/ShutdownManager.java b/src/java/com/threerings/presents/server/ShutdownManager.java index a418e4607..d95b5df2f 100644 --- a/src/java/com/threerings/presents/server/ShutdownManager.java +++ b/src/java/com/threerings/presents/server/ShutdownManager.java @@ -24,16 +24,18 @@ package com.threerings.presents.server; import com.google.inject.Inject; import com.google.inject.Singleton; +import com.threerings.util.Lifecycle; + /** * Handles the orderly shutdown of all server services. * - * @Deprecated use LifecycleManager + * @Deprecated use Lifecycle */ @Singleton public class ShutdownManager { /** Implementers of this interface will be notified when the server is shutting down. */ - public static interface Shutdowner extends LifecycleManager.ShutdownComponent + public static interface Shutdowner extends Lifecycle.ShutdownComponent { } @@ -45,7 +47,7 @@ public class ShutdownManager */ public void registerShutdowner (Shutdowner downer) { - _lifeMgr.addComponent(downer); + _cycle.addComponent(downer); } /** @@ -53,7 +55,7 @@ public class ShutdownManager */ public void unregisterShutdowner (Shutdowner downer) { - _lifeMgr.removeComponent(downer); + _cycle.removeComponent(downer); } /** @@ -63,10 +65,10 @@ public class ShutdownManager { switch (constraint) { case RUNS_BEFORE: - _lifeMgr.addShutdownConstraint(lhs, LifecycleManager.Constraint.RUNS_BEFORE, rhs); + _cycle.addShutdownConstraint(lhs, Lifecycle.Constraint.RUNS_BEFORE, rhs); break; case RUNS_AFTER: - _lifeMgr.addShutdownConstraint(lhs, LifecycleManager.Constraint.RUNS_AFTER, rhs); + _cycle.addShutdownConstraint(lhs, Lifecycle.Constraint.RUNS_AFTER, rhs); break; } } @@ -77,7 +79,7 @@ public class ShutdownManager */ public void queueShutdown () { - _lifeMgr.queueShutdown(); + _server.queueShutdown(); } /** @@ -85,8 +87,9 @@ public class ShutdownManager */ public boolean isShuttingDown () { - return _lifeMgr.isShuttingDown(); + return _cycle.isShuttingDown(); } - @Inject protected LifecycleManager _lifeMgr; + @Inject protected Lifecycle _cycle; + @Inject protected PresentsServer _server; } diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index 15b681c05..cd3462dda 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -56,6 +56,7 @@ import com.threerings.io.FramingOutputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.io.UnreliableObjectInputStream; import com.threerings.io.UnreliableObjectOutputStream; +import com.threerings.util.Lifecycle; import com.threerings.presents.annotation.AuthInvoker; import com.threerings.presents.client.Client; @@ -67,8 +68,8 @@ import com.threerings.presents.server.Authenticator; import com.threerings.presents.server.ChainedAuthenticator; import com.threerings.presents.server.ClientManager; import com.threerings.presents.server.DummyAuthenticator; -import com.threerings.presents.server.LifecycleManager; import com.threerings.presents.server.PresentsDObjectMgr; +import com.threerings.presents.server.PresentsServer; import com.threerings.presents.server.ReportManager; import com.threerings.presents.util.DatagramSequencer; @@ -82,15 +83,15 @@ import static com.threerings.presents.Log.log; */ @Singleton public class ConnectionManager extends LoopingThread - implements LifecycleManager.ShutdownComponent, ReportManager.Reporter + implements Lifecycle.ShutdownComponent, ReportManager.Reporter { /** * Creates a connection manager instance. Don't call this, Guice will do it for you. */ - @Inject public ConnectionManager (LifecycleManager lifemgr, ReportManager repmgr) + @Inject public ConnectionManager (Lifecycle cycle, ReportManager repmgr) { super("ConnectionManager"); - lifemgr.addComponent(this); + cycle.addComponent(this); repmgr.registerReporter(this); } @@ -391,7 +392,7 @@ public class ConnectionManager extends LoopingThread // if we failed to listen on at least one port, give up the ghost if (successes == 0) { log.warning("ConnectionManager failed to bind to any ports. Shutting down."); - _lifemgr.queueShutdown(); + _server.queueShutdown(); return; } @@ -1230,9 +1231,9 @@ public class ConnectionManager extends LoopingThread // some dependencies @Inject @AuthInvoker protected Invoker _authInvoker; - @Inject protected PresentsDObjectMgr _omgr; @Inject protected ClientManager _clmgr; - @Inject protected LifecycleManager _lifemgr; + @Inject protected PresentsDObjectMgr _omgr; + @Inject protected PresentsServer _server; /** How long we wait for network events before checking our running flag to see if we should * still be running. We don't want to loop too tightly, but we need to make sure we don't sit diff --git a/src/java/com/threerings/presents/server/LifecycleManager.java b/src/java/com/threerings/presents/util/Lifecycle.java similarity index 85% rename from src/java/com/threerings/presents/server/LifecycleManager.java rename to src/java/com/threerings/presents/util/Lifecycle.java index 506b0f07e..63bde75f6 100644 --- a/src/java/com/threerings/presents/server/LifecycleManager.java +++ b/src/java/com/threerings/presents/util/Lifecycle.java @@ -19,23 +19,19 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -package com.threerings.presents.server; +package com.threerings.util; import com.google.inject.Inject; import com.samskivert.util.ObserverList; -import com.samskivert.util.RunQueue; import com.threerings.util.DependencyGraph; -import com.threerings.presents.annotation.EventQueue; - import static com.threerings.presents.Log.log; /** - * Manages the lifecycle (initialization and shutdown) of our various server managers and other - * entities. + * Manages the lifecycle (initialization and shutdown) of a collection of components. */ -public class LifecycleManager +public class Lifecycle { /** An interface implemented by components which wish to participate in the lifecycle. */ public interface BaseComponent @@ -65,8 +61,8 @@ public class LifecycleManager public static enum Constraint { RUNS_BEFORE, RUNS_AFTER }; /** - * Registers a component with the manager. This should be done during the dependency resolution - * phase by injecting the LifecycleManager into your constructor and calling this method there. + * Registers a component with the lifecycle. This should be done during dependency resolution + * by injecting the Lifecycle into your constructor and calling this method there. */ public void addComponent (BaseComponent comp) { @@ -82,7 +78,7 @@ public class LifecycleManager } /** - * Removes a component from the manager. This is generally not used. + * Removes a component from the lifecycle. This is generally not used. */ public void removeComponent (BaseComponent comp) { @@ -121,19 +117,6 @@ public class LifecycleManager _downers.addDependency(after, before); } - /** - * Queues up a request to shutdown on the event thread. This method may be safely called from - * any thread. - */ - public void queueShutdown () - { - _eventQueue.postRunnable(new Runnable() { - public void run () { - shutdown(); - } - }); - } - /** * Returns true if we're in the process of shutting down. */ @@ -184,9 +167,6 @@ public class LifecycleManager }); } - /** The queue we'll use to get onto the event thread before shutting down. */ - @Inject @EventQueue protected RunQueue _eventQueue; - /** A dependency graph of our components arranged by initialization dependencies. */ protected DependencyGraph _initers = new DependencyGraph();