Actually instead of doing the necessary jiggery pokery to make PresentsServer
subclasses provide PresentsServer "services" we'll just have no PresentsServer services. All services will be provided by components and the server will disappear in a puff of inversion of control. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5155 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -54,7 +54,7 @@ public class CrowdServer extends PresentsServer
|
||||
{
|
||||
@Override protected void configure () {
|
||||
super.configure();
|
||||
bind(PresentsServer.class).to(CrowdServer.class);
|
||||
// nada (yet)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Shutdowner> 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<Shutdowner> _downers = ObserverList.newSafeInOrder();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user