Let's make the Lifecycle a bit more abstract and decouple it from all the

server business. I'd move the whole kit and kaboodle to samskivert but that
would mean moving the DependencyGraph as well...


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5804 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2009-05-27 19:09:47 +00:00
parent d855eb184a
commit e87c86dc2c
12 changed files with 81 additions and 87 deletions
@@ -35,6 +35,7 @@ import com.samskivert.util.ArrayIntSet;
import com.samskivert.util.IntSet; import com.samskivert.util.IntSet;
import com.samskivert.util.Interval; import com.samskivert.util.Interval;
import com.threerings.util.Lifecycle;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.annotation.AnyThread; 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.data.NodeObject;
import com.threerings.presents.peer.server.PeerManager; import com.threerings.presents.peer.server.PeerManager;
import com.threerings.presents.server.InvocationManager; import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.LifecycleManager;
import com.threerings.presents.server.PresentsDObjectMgr; import com.threerings.presents.server.PresentsDObjectMgr;
import com.threerings.crowd.chat.data.ChatChannel; import com.threerings.crowd.chat.data.ChatChannel;
@@ -62,7 +62,7 @@ import static com.threerings.crowd.Log.log;
*/ */
@Singleton @Singleton
public abstract class ChatChannelManager 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 * 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 () public void shutdown ()
{ {
// stop our channel closer; always be closing... except now // 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. * Creates our singleton manager and registers our invocation service.
*/ */
@Inject protected ChatChannelManager (PresentsDObjectMgr omgr, InvocationManager invmgr, @Inject protected ChatChannelManager (PresentsDObjectMgr omgr, InvocationManager invmgr,
LifecycleManager lifemgr) Lifecycle cycle)
{ {
invmgr.registerDispatcher(new ChannelSpeakDispatcher(this), CrowdCodes.CROWD_GROUP); invmgr.registerDispatcher(new ChannelSpeakDispatcher(this), CrowdCodes.CROWD_GROUP);
lifemgr.addComponent(this); cycle.addComponent(this);
// create and start our idle channel closer (always be closing) // create and start our idle channel closer (always be closing)
_closer = new Interval(omgr) { _closer = new Interval(omgr) {
@@ -23,6 +23,7 @@ package com.threerings.crowd.peer.server;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.threerings.util.Lifecycle;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject; 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.peer.server.PeerNode;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationManager; import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.LifecycleManager;
import com.threerings.presents.server.PresentsSession; import com.threerings.presents.server.PresentsSession;
import com.threerings.crowd.chat.client.ChatService; import com.threerings.crowd.chat.client.ChatService;
@@ -51,9 +51,9 @@ public abstract class CrowdPeerManager extends PeerManager
/** /**
* Creates an uninitialized peer manager. * Creates an uninitialized peer manager.
*/ */
@Inject public CrowdPeerManager (LifecycleManager lifeMgr) @Inject public CrowdPeerManager (Lifecycle cycle)
{ {
super(lifeMgr); super(cycle);
} }
// from interface CrowdPeerProvider // from interface CrowdPeerProvider
@@ -30,11 +30,11 @@ import com.google.inject.Singleton;
import com.samskivert.util.IntMap; import com.samskivert.util.IntMap;
import com.samskivert.util.IntMaps; import com.samskivert.util.IntMaps;
import com.threerings.util.Lifecycle;
import com.threerings.presents.dobj.RootDObjectManager; import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationManager; import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.LifecycleManager;
import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.data.PlaceObject;
@@ -48,7 +48,7 @@ import static com.threerings.crowd.Log.log;
*/ */
@Singleton @Singleton
public class PlaceRegistry public class PlaceRegistry
implements LifecycleManager.ShutdownComponent implements Lifecycle.ShutdownComponent
{ {
/** Used in conjunction with {@link PlaceRegistry#createPlace(PlaceConfig,PreStartupHook)}. */ /** Used in conjunction with {@link PlaceRegistry#createPlace(PlaceConfig,PreStartupHook)}. */
public static interface 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 * Creates and initializes the place registry. This is called by the server during its
* initialization phase. * 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(); return _pmgrs.values().iterator();
} }
// from interface LifecycleManager.ShutdownComponent // from interface Lifecycle.ShutdownComponent
public void shutdown () public void shutdown ()
{ {
// shut down all active places // shut down all active places
@@ -49,6 +49,7 @@ import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.util.Lifecycle;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.dobj.DObject; 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.ClientManager;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationManager; import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.LifecycleManager;
import com.threerings.presents.server.PresentsDObjectMgr; import com.threerings.presents.server.PresentsDObjectMgr;
import com.threerings.presents.server.PresentsSession; import com.threerings.presents.server.PresentsSession;
import com.threerings.presents.server.ReportManager; 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. * servers and uses those objects to communicate cross-node information.
*/ */
public abstract class PeerManager 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 * 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. * 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(); return _stats.clone();
} }
// from interface LifecycleManager.ShutdownComponent // from interface Lifecycle.ShutdownComponent
public void shutdown () public void shutdown ()
{ {
if (_nodeName == null) { // sanity check if (_nodeName == null) { // sanity check
@@ -52,7 +52,7 @@ public abstract class AbstractSignalHandler
protected void termReceived () protected void termReceived ()
{ {
log.info("Shutdown initiated by TERM signal."); log.info("Shutdown initiated by TERM signal.");
_lifemgr.queueShutdown(); _server.queueShutdown();
} }
/** /**
@@ -61,7 +61,7 @@ public abstract class AbstractSignalHandler
protected void intReceived () protected void intReceived ()
{ {
log.info("Shutdown initiated by INT signal."); 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)); log.info(_repmgr.generateReport(ReportManager.DEFAULT_TYPE));
} }
@Inject protected LifecycleManager _lifemgr; @Inject protected PresentsServer _server;
@Inject protected ReportManager _repmgr; @Inject protected ReportManager _repmgr;
} }
@@ -39,6 +39,7 @@ import com.samskivert.util.Interval;
import com.samskivert.util.ObserverList; import com.samskivert.util.ObserverList;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.util.Lifecycle;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.annotation.EventThread; import com.threerings.presents.annotation.EventThread;
@@ -62,7 +63,7 @@ import static com.threerings.presents.Log.log;
*/ */
@Singleton @Singleton
public class ClientManager public class ClientManager
implements ClientResolutionListener, ReportManager.Reporter, LifecycleManager.Component implements ClientResolutionListener, ReportManager.Reporter, Lifecycle.Component
{ {
/** /**
* Used by {@link ClientManager#applyToClient}. * Used by {@link ClientManager#applyToClient}.
@@ -100,10 +101,10 @@ public class ClientManager
/** /**
* Constructs a client manager that will interact with the supplied connection manager. * 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); repmgr.registerReporter(this);
lifemgr.addComponent(this); cycle.addComponent(this);
} }
/** /**
@@ -323,7 +324,7 @@ public class ClientManager
_omgr.destroyObject(clobj.getOid()); _omgr.destroyObject(clobj.getOid());
} }
// from interface LifecycleManager.Component // from interface Lifecycle.Component
public void init () public void init ()
{ {
// start up an interval that will check for and flush expired clients // 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); _flushClients.schedule(CLIENT_FLUSH_INTERVAL, true);
} }
// from interface LifecycleManager.Component // from interface Lifecycle.Component
public void shutdown () public void shutdown ()
{ {
log.info("Client manager shutting down", "ccount", _usermap.size()); log.info("Client manager shutting down", "ccount", _usermap.size());
@@ -25,6 +25,7 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.samskivert.util.Invoker; import com.samskivert.util.Invoker;
import com.threerings.util.Lifecycle;
import static com.threerings.presents.Log.log; import static com.threerings.presents.Log.log;
@@ -33,17 +34,16 @@ import static com.threerings.presents.Log.log;
*/ */
@Singleton @Singleton
public class PresentsInvoker extends ReportingInvoker public class PresentsInvoker extends ReportingInvoker
implements LifecycleManager.ShutdownComponent implements Lifecycle.ShutdownComponent
{ {
@Inject public PresentsInvoker (PresentsDObjectMgr omgr, LifecycleManager lifemgr, @Inject public PresentsInvoker (PresentsDObjectMgr omgr, Lifecycle cycle, ReportManager repmgr)
ReportManager repmgr)
{ {
super("presents.Invoker", omgr, repmgr); super("presents.Invoker", omgr, repmgr);
cycle.addComponent(this);
_omgr = omgr; _omgr = omgr;
lifemgr.addComponent(this);
} }
@Override // from Invoker, LifecycleManager.ShutdownComponent @Override // from Invoker, Lifecycle.ShutdownComponent
public void shutdown () public void shutdown ()
{ {
// this will do a sophisticated shutdown of both ourself and the dobjmgr; note: we // this will do a sophisticated shutdown of both ourself and the dobjmgr; note: we
@@ -30,6 +30,7 @@ import com.google.inject.Singleton;
import com.samskivert.util.Invoker; import com.samskivert.util.Invoker;
import com.samskivert.util.RunQueue; import com.samskivert.util.RunQueue;
import com.samskivert.util.SystemInfo; import com.samskivert.util.SystemInfo;
import com.threerings.util.Lifecycle;
import com.threerings.presents.annotation.AuthInvoker; import com.threerings.presents.annotation.AuthInvoker;
import com.threerings.presents.annotation.EventQueue; 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 // make the client manager shut down before the invoker and dobj threads; this helps
// application code to avoid long chains of shutdown constraints // application code to avoid long chains of shutdown constraints
_lifemgr.addShutdownConstraint( _lifecycle.addShutdownConstraint(
_clmgr, LifecycleManager.Constraint.RUNS_BEFORE, (PresentsInvoker)_invoker); _clmgr, Lifecycle.Constraint.RUNS_BEFORE, (PresentsInvoker)_invoker);
// initialize all of our registered components // initialize all of our registered components
_lifemgr.init(); _lifecycle.init();
} }
/** /**
@@ -185,6 +186,19 @@ public class PresentsServer
_omgr.run(); _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 * 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. * 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; @Inject protected InvocationManager _invmgr;
/** Handles orderly initialization and shutdown of our managers, etc. */ /** 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. */ /** Handles generation of state of the server reports. */
@Inject protected ReportManager _repmgr; @Inject protected ReportManager _repmgr;
@@ -188,9 +188,9 @@ public abstract class RebootManager
/** /**
* Provides us with our dependencies. * Provides us with our dependencies.
*/ */
protected RebootManager (LifecycleManager lmgr, RootDObjectManager omgr) protected RebootManager (PresentsServer server, RootDObjectManager omgr)
{ {
_lmgr = lmgr; _server = server;
_omgr = omgr; _omgr = omgr;
} }
@@ -257,12 +257,7 @@ public abstract class RebootManager
// wait 1 second, then do it // wait 1 second, then do it
new Interval() { // Note: This interval does not run on the dobj thread new Interval() { // Note: This interval does not run on the dobj thread
@Override public void expired () { @Override public void expired () {
// ...but we then post a LongRunnable... _server.queueShutdown(); // this posts a LongRunnable
_omgr.postRunnable(new PresentsDObjectMgr.LongRunnable() {
public void run () {
_lmgr.shutdown();
}
});
} }
}.schedule(1000); }.schedule(1000);
return; return;
@@ -321,8 +316,8 @@ public abstract class RebootManager
}); });
} }
/** Our lifecycle manager, which is how we will reboot. */ /** The server that we're going to reboot. */
protected LifecycleManager _lmgr; protected PresentsServer _server;
/** Our distributed object manager. */ /** Our distributed object manager. */
protected RootDObjectManager _omgr; protected RootDObjectManager _omgr;
@@ -24,16 +24,18 @@ package com.threerings.presents.server;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.threerings.util.Lifecycle;
/** /**
* Handles the orderly shutdown of all server services. * Handles the orderly shutdown of all server services.
* *
* @Deprecated use LifecycleManager * @Deprecated use Lifecycle
*/ */
@Singleton @Singleton
public class ShutdownManager public class ShutdownManager
{ {
/** Implementers of this interface will be notified when the server is shutting down. */ /** 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) public void registerShutdowner (Shutdowner downer)
{ {
_lifeMgr.addComponent(downer); _cycle.addComponent(downer);
} }
/** /**
@@ -53,7 +55,7 @@ public class ShutdownManager
*/ */
public void unregisterShutdowner (Shutdowner downer) public void unregisterShutdowner (Shutdowner downer)
{ {
_lifeMgr.removeComponent(downer); _cycle.removeComponent(downer);
} }
/** /**
@@ -63,10 +65,10 @@ public class ShutdownManager
{ {
switch (constraint) { switch (constraint) {
case RUNS_BEFORE: case RUNS_BEFORE:
_lifeMgr.addShutdownConstraint(lhs, LifecycleManager.Constraint.RUNS_BEFORE, rhs); _cycle.addShutdownConstraint(lhs, Lifecycle.Constraint.RUNS_BEFORE, rhs);
break; break;
case RUNS_AFTER: case RUNS_AFTER:
_lifeMgr.addShutdownConstraint(lhs, LifecycleManager.Constraint.RUNS_AFTER, rhs); _cycle.addShutdownConstraint(lhs, Lifecycle.Constraint.RUNS_AFTER, rhs);
break; break;
} }
} }
@@ -77,7 +79,7 @@ public class ShutdownManager
*/ */
public void queueShutdown () public void queueShutdown ()
{ {
_lifeMgr.queueShutdown(); _server.queueShutdown();
} }
/** /**
@@ -85,8 +87,9 @@ public class ShutdownManager
*/ */
public boolean isShuttingDown () public boolean isShuttingDown ()
{ {
return _lifeMgr.isShuttingDown(); return _cycle.isShuttingDown();
} }
@Inject protected LifecycleManager _lifeMgr; @Inject protected Lifecycle _cycle;
@Inject protected PresentsServer _server;
} }
@@ -56,6 +56,7 @@ import com.threerings.io.FramingOutputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.UnreliableObjectInputStream; import com.threerings.io.UnreliableObjectInputStream;
import com.threerings.io.UnreliableObjectOutputStream; import com.threerings.io.UnreliableObjectOutputStream;
import com.threerings.util.Lifecycle;
import com.threerings.presents.annotation.AuthInvoker; import com.threerings.presents.annotation.AuthInvoker;
import com.threerings.presents.client.Client; 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.ChainedAuthenticator;
import com.threerings.presents.server.ClientManager; import com.threerings.presents.server.ClientManager;
import com.threerings.presents.server.DummyAuthenticator; import com.threerings.presents.server.DummyAuthenticator;
import com.threerings.presents.server.LifecycleManager;
import com.threerings.presents.server.PresentsDObjectMgr; import com.threerings.presents.server.PresentsDObjectMgr;
import com.threerings.presents.server.PresentsServer;
import com.threerings.presents.server.ReportManager; import com.threerings.presents.server.ReportManager;
import com.threerings.presents.util.DatagramSequencer; import com.threerings.presents.util.DatagramSequencer;
@@ -82,15 +83,15 @@ import static com.threerings.presents.Log.log;
*/ */
@Singleton @Singleton
public class ConnectionManager extends LoopingThread 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. * 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"); super("ConnectionManager");
lifemgr.addComponent(this); cycle.addComponent(this);
repmgr.registerReporter(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 we failed to listen on at least one port, give up the ghost
if (successes == 0) { if (successes == 0) {
log.warning("ConnectionManager failed to bind to any ports. Shutting down."); log.warning("ConnectionManager failed to bind to any ports. Shutting down.");
_lifemgr.queueShutdown(); _server.queueShutdown();
return; return;
} }
@@ -1230,9 +1231,9 @@ public class ConnectionManager extends LoopingThread
// some dependencies // some dependencies
@Inject @AuthInvoker protected Invoker _authInvoker; @Inject @AuthInvoker protected Invoker _authInvoker;
@Inject protected PresentsDObjectMgr _omgr;
@Inject protected ClientManager _clmgr; @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 /** 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 * still be running. We don't want to loop too tightly, but we need to make sure we don't sit
@@ -19,23 +19,19 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // 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.google.inject.Inject;
import com.samskivert.util.ObserverList; import com.samskivert.util.ObserverList;
import com.samskivert.util.RunQueue;
import com.threerings.util.DependencyGraph; import com.threerings.util.DependencyGraph;
import com.threerings.presents.annotation.EventQueue;
import static com.threerings.presents.Log.log; import static com.threerings.presents.Log.log;
/** /**
* Manages the lifecycle (initialization and shutdown) of our various server managers and other * Manages the lifecycle (initialization and shutdown) of a collection of components.
* entities.
*/ */
public class LifecycleManager public class Lifecycle
{ {
/** An interface implemented by components which wish to participate in the lifecycle. */ /** An interface implemented by components which wish to participate in the lifecycle. */
public interface BaseComponent public interface BaseComponent
@@ -65,8 +61,8 @@ public class LifecycleManager
public static enum Constraint { RUNS_BEFORE, RUNS_AFTER }; public static enum Constraint { RUNS_BEFORE, RUNS_AFTER };
/** /**
* Registers a component with the manager. This should be done during the dependency resolution * Registers a component with the lifecycle. This should be done during dependency resolution
* phase by injecting the LifecycleManager into your constructor and calling this method there. * by injecting the Lifecycle into your constructor and calling this method there.
*/ */
public void addComponent (BaseComponent comp) 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) public void removeComponent (BaseComponent comp)
{ {
@@ -121,19 +117,6 @@ public class LifecycleManager
_downers.addDependency(after, before); _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. * 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. */ /** A dependency graph of our components arranged by initialization dependencies. */
protected DependencyGraph<InitComponent> _initers = new DependencyGraph<InitComponent>(); protected DependencyGraph<InitComponent> _initers = new DependencyGraph<InitComponent>();