Merge the ServerInvoker stuff into PresentsInvoker because the PresentsInvoker

is only ever used by the PresentsServer. Also determined that we need to
explicitly let Guice know that CrowdServer provides the PresentsServer
"interface" and so on down the line.

I also think that each concrete class needs to be marked as @Singleton though I
need to confirm that. Based on how annotations work, that's how it would be
easiest to implement, so we'll assume they're not doing extra work on the
backend to make our life easier.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5154 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-06-07 18:39:19 +00:00
parent 3aefc93838
commit c568204bbb
5 changed files with 45 additions and 36 deletions
@@ -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);
}
}
@@ -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
{
/**
@@ -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;
@@ -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 <code>PresentsServer</code> 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;
@@ -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<PendingShutdownObserver> _observers =
new ObserverList<PendingShutdownObserver>(
ObserverList.FAST_UNSAFE_NOTIFY);
protected ObserverList<PendingShutdownObserver> _observers = ObserverList.newFastUnsafe();
/** The next reboot lock id. */
protected int _nextRebootLockId = 0;