* Add a static method to init and run a PresentsServer given guice modules with its configuration.
* Rename PrefixServer.Module classes to PrefixModule. They all implement guice's Module, and it's hard to pass a class around as its interface if they share a name. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6303 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
|
||||
package com.threerings.crowd.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -36,8 +35,6 @@ import com.threerings.presents.server.PresentsServer;
|
||||
|
||||
import com.threerings.crowd.chat.server.ChatProvider;
|
||||
|
||||
import static com.threerings.crowd.Log.log;
|
||||
|
||||
/**
|
||||
* Extends the Presents server configuring extensions for Crowd services.
|
||||
*/
|
||||
@@ -45,7 +42,7 @@ import static com.threerings.crowd.Log.log;
|
||||
public class CrowdServer extends PresentsServer
|
||||
{
|
||||
/** Configures dependencies needed by the Crowd services. */
|
||||
public static class Module extends PresentsServer.Module
|
||||
public static class CrowdModule extends PresentsModule
|
||||
{
|
||||
@Override protected void configure () {
|
||||
super.configure();
|
||||
@@ -77,14 +74,7 @@ public class CrowdServer extends PresentsServer
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
CrowdServer server = injector.getInstance(CrowdServer.class);
|
||||
try {
|
||||
server.init(injector);
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
runServer(new CrowdModule(), new PresentsServerModule(CrowdServer.class));
|
||||
}
|
||||
|
||||
/** Handles the creation and tracking of place managers. */
|
||||
|
||||
@@ -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.Module;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import com.samskivert.util.Invoker;
|
||||
@@ -63,7 +64,7 @@ import static com.threerings.presents.Log.log;
|
||||
public class PresentsServer
|
||||
{
|
||||
/** Configures dependencies needed by the Presents services. */
|
||||
public static class Module extends AbstractModule
|
||||
public static class PresentsModule extends AbstractModule
|
||||
{
|
||||
@Override protected void configure () {
|
||||
bindInvokers();
|
||||
@@ -77,18 +78,35 @@ public class PresentsServer
|
||||
/**
|
||||
* Binds just the invokers so this can be overridden if desired.
|
||||
*/
|
||||
protected void bindInvokers() {
|
||||
protected void bindInvokers () {
|
||||
bind(Invoker.class).annotatedWith(MainInvoker.class).to(PresentsInvoker.class);
|
||||
bind(Invoker.class).annotatedWith(AuthInvoker.class).to(PresentsAuthInvoker.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The default entry point for the server.
|
||||
* Binds PresentsServer to a particular class.
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
public static class PresentsServerModule extends AbstractModule
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
public PresentsServerModule (Class<? extends PresentsServer> serverType) {
|
||||
_serverType = serverType;
|
||||
}
|
||||
|
||||
@Override protected void configure () {
|
||||
bind(PresentsServer.class).to(_serverType);
|
||||
}
|
||||
|
||||
protected final Class<? extends PresentsServer> _serverType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits and runs the PresentsServer bound in the given modules. This blocks until the server
|
||||
* is shut down.
|
||||
*/
|
||||
public static void runServer (Module... modules)
|
||||
{
|
||||
Injector injector = Guice.createInjector(modules);
|
||||
PresentsServer server = injector.getInstance(PresentsServer.class);
|
||||
try {
|
||||
// initialize the server
|
||||
@@ -117,6 +135,14 @@ public class PresentsServer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The default entry point for the server.
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
runServer(new PresentsModule());
|
||||
}
|
||||
|
||||
/** Legacy static reference to the main distributed object manager. Don't use this. If you're
|
||||
* writing a game, use {@link PlaceManager#_omgr}. */
|
||||
@Deprecated public static PresentsDObjectMgr omgr;
|
||||
@@ -133,7 +159,8 @@ public class PresentsServer
|
||||
{
|
||||
// output general system information
|
||||
SystemInfo si = new SystemInfo();
|
||||
log.info("Starting up server", "os", si.osToString(), "jvm", si.jvmToString());
|
||||
log.info("Starting up", "server", getClass().getSimpleName(), "os", si.osToString(),
|
||||
"jvm", si.jvmToString());
|
||||
|
||||
registerSignalHandlers(injector);
|
||||
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.util.MessageBundle;
|
||||
|
||||
@@ -39,7 +36,7 @@ import static com.threerings.presents.Log.log;
|
||||
public class Rejector extends PresentsServer
|
||||
{
|
||||
/** Configures dependencies needed by the Rejector. */
|
||||
public static class Module extends PresentsServer.Module
|
||||
public static class RejectorModule extends PresentsModule
|
||||
{
|
||||
@Override protected void configure () {
|
||||
super.configure();
|
||||
@@ -68,14 +65,7 @@ public class Rejector extends PresentsServer
|
||||
_errmsg = MessageBundle.tcompose(_errmsg, eargs);
|
||||
}
|
||||
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
Rejector server = injector.getInstance(Rejector.class);
|
||||
try {
|
||||
server.init(injector);
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
runServer(new RejectorModule(), new PresentsServerModule(Rejector.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RegistryTester
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new TestServer.Module());
|
||||
Injector injector = Guice.createInjector(new TestServer.PresentsModule());
|
||||
TestServer server = injector.getInstance(TestServer.class);
|
||||
RegistryTester tester = injector.getInstance(RegistryTester.class);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TestServer extends PresentsServer
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
Injector injector = Guice.createInjector(new PresentsModule());
|
||||
TestServer server = injector.getInstance(TestServer.class);
|
||||
try {
|
||||
server.init(injector);
|
||||
|
||||
@@ -3,13 +3,10 @@
|
||||
|
||||
package com.threerings.crowd.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import com.threerings.crowd.data.JabberConfig;
|
||||
|
||||
import static com.threerings.crowd.Log.log;
|
||||
|
||||
/**
|
||||
* A basic server that creates a single room and sticks everyone in it where they can chat with one
|
||||
* another.
|
||||
@@ -18,15 +15,7 @@ public class JabberServer extends CrowdServer
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
JabberServer server = injector.getInstance(JabberServer.class);
|
||||
|
||||
try {
|
||||
server.init(injector);
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
runServer(new CrowdModule(), new PresentsServerModule(JabberServer.class));
|
||||
}
|
||||
|
||||
@Override // from CrowdServer
|
||||
|
||||
@@ -14,7 +14,7 @@ public class PresentsTestBase
|
||||
protected <T> T getInstance (Class<T> clazz)
|
||||
{
|
||||
if (_injector == null) {
|
||||
_injector = Guice.createInjector(new PresentsServer.Module());
|
||||
_injector = Guice.createInjector(new PresentsServer.PresentsModule());
|
||||
}
|
||||
return _injector.getInstance(clazz);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,10 @@
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import com.threerings.presents.data.TestObject;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
public class TestServer extends PresentsServer
|
||||
{
|
||||
public static TestObject testobj;
|
||||
@@ -52,13 +49,6 @@ public class TestServer extends PresentsServer
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
TestServer server = injector.getInstance(TestServer.class);
|
||||
try {
|
||||
server.init(injector);
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
runServer(new PresentsModule(), new PresentsServerModule(TestServer.class));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user