diff --git a/src/java/com/threerings/crowd/server/CrowdServer.java b/src/java/com/threerings/crowd/server/CrowdServer.java index 2593ef5a2..aca83484e 100644 --- a/src/java/com/threerings/crowd/server/CrowdServer.java +++ b/src/java/com/threerings/crowd/server/CrowdServer.java @@ -25,6 +25,7 @@ import java.util.Iterator; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.Singleton; import com.threerings.util.Name; @@ -45,6 +46,7 @@ import static com.threerings.crowd.Log.log; * The crowd server extends the presents server by configuring it to use the * extensions provided by the crowd layer to support crowd services. */ +@Singleton public class CrowdServer extends PresentsServer { /** Configures dependencies needed by the Crowd services. */ @@ -52,7 +54,7 @@ public class CrowdServer extends PresentsServer { @Override protected void configure () { super.configure(); - // nada + bind(PresentsServer.class).to(CrowdServer.class); } } diff --git a/src/java/com/threerings/presents/server/LocalDObjectMgr.java b/src/java/com/threerings/presents/server/LocalDObjectMgr.java index 006dca4e6..32d7aa091 100644 --- a/src/java/com/threerings/presents/server/LocalDObjectMgr.java +++ b/src/java/com/threerings/presents/server/LocalDObjectMgr.java @@ -24,6 +24,8 @@ package com.threerings.presents.server; import java.awt.EventQueue; import com.google.inject.Inject; +import com.google.inject.Singleton; + import com.threerings.presents.dobj.DEvent; import com.threerings.presents.dobj.DObject; import com.threerings.presents.dobj.DObjectManager; @@ -34,6 +36,7 @@ import com.threerings.presents.dobj.Subscriber; * that it can run in a client with a GUI and provide a "light" server for local operation of a * normally distributed application. */ +@Singleton public class LocalDObjectMgr extends PresentsDObjectMgr { /** diff --git a/src/java/com/threerings/presents/server/PresentsInvoker.java b/src/java/com/threerings/presents/server/PresentsInvoker.java index f3d615e67..6be89e1fa 100644 --- a/src/java/com/threerings/presents/server/PresentsInvoker.java +++ b/src/java/com/threerings/presents/server/PresentsInvoker.java @@ -121,6 +121,12 @@ public class PresentsInvoker extends Invoker } } + @Override // from Invoker + protected void didShutdown () + { + _server.invokerDidShutdown(); + } + /** * This gets posted back and forth between the invoker and DObjectMgr until both of their * queues are empty and they can both be safely shutdown. @@ -223,6 +229,9 @@ public class PresentsInvoker extends Invoker /** The distributed object manager with which we interoperate. */ protected PresentsDObjectMgr _omgr; + /** The server we're working for. */ + @Inject protected PresentsServer _server; + /** The largest queue size since our last report. */ protected long _maxQueueSize; diff --git a/src/java/com/threerings/presents/server/PresentsServer.java b/src/java/com/threerings/presents/server/PresentsServer.java index addcbf75e..411caab4a 100644 --- a/src/java/com/threerings/presents/server/PresentsServer.java +++ b/src/java/com/threerings/presents/server/PresentsServer.java @@ -25,6 +25,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; +import com.google.inject.Singleton; import com.samskivert.util.Invoker; import com.samskivert.util.RunQueue; @@ -34,6 +35,8 @@ import com.threerings.presents.annotation.EventQueue; import com.threerings.presents.annotation.MainInvoker; import com.threerings.presents.client.Client; import com.threerings.presents.dobj.AccessController; +import com.threerings.presents.dobj.DObjectManager; +import com.threerings.presents.dobj.RootDObjectManager; import com.threerings.presents.server.net.ConnectionManager; import static com.threerings.presents.Log.log; @@ -46,14 +49,17 @@ import static com.threerings.presents.Log.log; * available in the PresentsServer class. These will be configured when the singleton * instance is initialized. */ +@Singleton public class PresentsServer { /** Configures dependencies needed by the Presents services. */ public static class Module extends AbstractModule { @Override protected void configure () { - bind(Invoker.class).annotatedWith(MainInvoker.class).to(ServerInvoker.class); + bind(Invoker.class).annotatedWith(MainInvoker.class).to(PresentsInvoker.class); bind(RunQueue.class).annotatedWith(EventQueue.class).to(PresentsDObjectMgr.class); + bind(DObjectManager.class).to(PresentsDObjectMgr.class); + bind(RootDObjectManager.class).to(PresentsDObjectMgr.class); } } @@ -257,20 +263,6 @@ public class PresentsServer { } - /** Integrates the main invoker thread with the distributed object thread so that they can - * coordinate the shutdown process to ensure that all (barring infinite loops) invoker units - * and distributed object events are processed before the server shuts down. */ - protected static class ServerInvoker extends PresentsInvoker - { - @Inject public ServerInvoker (PresentsDObjectMgr omgr, ReportManager repmgr) { - super(omgr, repmgr); - } - @Override protected void didShutdown () { - _server.invokerDidShutdown(); - } - @Inject protected PresentsServer _server; - } - /** The manager of distributed objects. */ @Inject protected PresentsDObjectMgr _omgr; diff --git a/src/java/com/threerings/presents/server/RebootManager.java b/src/java/com/threerings/presents/server/RebootManager.java index 9527abb93..9e2b6d1ac 100644 --- a/src/java/com/threerings/presents/server/RebootManager.java +++ b/src/java/com/threerings/presents/server/RebootManager.java @@ -30,13 +30,15 @@ import com.samskivert.util.StringUtil; import com.threerings.util.MessageBundle; +import com.threerings.presents.dobj.RootDObjectManager; + import static com.threerings.presents.Log.log; /** - * Handles scheduling and execution of automated server reboots. Note that this - * service simply shuts down the server and assumes it will be automatically - * restarted by some external entity. It is generally useful to run a server - * from a script that automatically restarts it when it terminates. + * Handles scheduling and execution of automated server reboots. Note that this service simply + * shuts down the server and assumes it will be automatically restarted by some external entity. It + * is generally useful to run a server from a script that automatically restarts it when it + * terminates. */ public abstract class RebootManager { @@ -60,15 +62,6 @@ public abstract class RebootManager public void shutdownPlanned (int warningsLeft, long msLeft); } - /** - * Creates a reboot manager that will shutdown the supplied server when the - * time comes. - */ - public RebootManager (PresentsServer server) - { - _server = server; - } - /** * Finish initialization of the manager. */ @@ -154,7 +147,7 @@ public abstract class RebootManager // should issue the first pre-reboot warning _rebootSoon = false; long firstWarnTime = (_nextReboot - (WARNINGS[0] * 60 * 1000)) - now; - _interval = new Interval(PresentsServer.omgr) { + _interval = new Interval(_omgr) { public void expired () { doWarning(0); } @@ -187,6 +180,15 @@ public abstract class RebootManager } } + /** + * Provides us with our dependencies. + */ + protected RebootManager (PresentsServer server, RootDObjectManager omgr) + { + _server = server; + _omgr = omgr; + } + /** * Broadcasts a message to everyone on the server. The following * messages will be broadcast: @@ -239,7 +241,7 @@ public abstract class RebootManager new Interval() { // Note: This interval does not run on the dobj thread public void expired () { // ...but we then post a LongRunnable... - PresentsServer.omgr.postRunnable(new PresentsDObjectMgr.LongRunnable() { + _omgr.postRunnable(new PresentsDObjectMgr.LongRunnable() { public void run () { _server.shutdown(); } @@ -263,7 +265,7 @@ public abstract class RebootManager } // schedule the next warning - _interval = new Interval(PresentsServer.omgr) { + _interval = new Interval(_omgr) { public void expired () { doWarning(level + 1); } @@ -285,7 +287,7 @@ public abstract class RebootManager log.info("Reboot delayed due to outstanding locks: " + StringUtil.toString(_rebootLocks.elements())); broadcast("m.reboot_delayed"); - _interval = new Interval(PresentsServer.omgr) { + _interval = new Interval(_omgr) { public void expired () { doWarning(WARNINGS.length); } @@ -313,6 +315,9 @@ public abstract class RebootManager /** The server we will reboot. */ protected PresentsServer _server; + /** Our distributed object manager. */ + protected RootDObjectManager _omgr; + /** The time at which our next reboot is scheduled or 0L. */ protected long _nextReboot; @@ -326,9 +331,7 @@ public abstract class RebootManager protected Interval _interval; /** A list of PendingShutdownObservers. */ - protected ObserverList _observers = - new ObserverList( - ObserverList.FAST_UNSAFE_NOTIFY); + protected ObserverList _observers = ObserverList.newFastUnsafe(); /** The next reboot lock id. */ protected int _nextRebootLockId = 0;