Basic Guice compliance.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@614 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2008-06-07 17:45:30 +00:00
parent 2090bcdfeb
commit 0a2b8b8f52
9 changed files with 80 additions and 59 deletions
+1
View File
@@ -9,6 +9,7 @@
<include name="commons-lang.jar"/>
<include name="commons-logging.jar"/>
<include name="google-collect.jar"/>
<include name="guice.jar"/>
<include name="javassist.jar"/>
<include name="junit4.jar"/>
<include name="retroweaver-all-1.2.2.jar"/>
@@ -21,6 +21,9 @@
package com.threerings.micasa.server;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.threerings.util.Name;
import com.threerings.presents.net.AuthRequest;
@@ -48,17 +51,14 @@ public class MiCasaServer extends CrowdServer
/** The lobby registry operating on this server. */
public static LobbyRegistry lobreg = new LobbyRegistry();
/**
* Initializes all of the server services and prepares for operation.
*/
public void init ()
@Override // from CrowdServer
public void init (Injector injector)
throws Exception
{
// do the base server initialization
super.init();
super.init(injector);
// configure the client manager to use our client class
clmgr.setClientFactory(new ClientFactory() {
_clmgr.setClientFactory(new ClientFactory() {
public PresentsClient createClient (AuthRequest areq) {
return new MiCasaClient();
}
@@ -78,9 +78,10 @@ public class MiCasaServer extends CrowdServer
public static void main (String[] args)
{
MiCasaServer server = new MiCasaServer();
Injector injector = Guice.createInjector(new Module());
MiCasaServer server = injector.getInstance(MiCasaServer.class);
try {
server.init();
server.init(injector);
server.run();
} catch (Exception e) {
log.warning("Unable to initialize server.", e);
@@ -23,6 +23,9 @@ package com.threerings.micasa.simulator.client;
import javax.swing.JFrame;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.samskivert.swing.Controller;
import com.samskivert.swing.util.SwingUtil;
import com.samskivert.util.Interval;
@@ -41,8 +44,7 @@ import com.threerings.micasa.simulator.server.SimulatorServer;
import static com.threerings.micasa.Log.log;
/**
* The simulator application is a test harness to facilitate development
* and debugging of games.
* The simulator application is a test harness to facilitate development and debugging of games.
*/
public class SimulatorApp
{
@@ -55,8 +57,7 @@ public class SimulatorApp
SimulatorInfo siminfo = new SimulatorInfo();
siminfo.gameConfigClass = args[0];
siminfo.simClass = args[1];
siminfo.playerCount = getInt(
System.getProperty("playercount"), DEFAULT_PLAYER_COUNT);
siminfo.playerCount = getInt(System.getProperty("playercount"), DEFAULT_PLAYER_COUNT);
// create our client instance
_client = createSimulatorClient(_frame);
@@ -66,14 +67,14 @@ public class SimulatorApp
_frame.setController(ctrl);
// create the server
SimulatorServer server = createSimulatorServer();
server.init(new ResultListener() {
Injector injector = Guice.createInjector(new SimpleServer.Module());
SimulatorServer server = createSimulatorServer(injector);
server.init(injector, new ResultListener() {
public void requestCompleted (Object result) {
try {
run();
} catch (Exception e) {
log.warning("Simulator initialization failed " +
"[e=" + e + "].");
log.warning("Simulator initialization failed [e=" + e + "].");
}
}
public void requestFailed (Exception e) {
@@ -83,14 +84,13 @@ public class SimulatorApp
// run the server on a separate thread
_serverThread = new ServerThread(server);
// start up the server so that we can be notified when
// initialization is complete
// start up the server so that we can be notified when initialization is complete
_serverThread.start();
}
protected SimulatorServer createSimulatorServer ()
protected SimulatorServer createSimulatorServer (Injector injector)
{
return new SimpleServer();
return injector.getInstance(SimpleServer.class);
}
protected SimulatorFrame createSimulatorFrame ()
@@ -21,22 +21,23 @@
package com.threerings.micasa.simulator.server;
import com.google.inject.Injector;
import com.samskivert.util.ResultListener;
import com.threerings.micasa.server.MiCasaServer;
/**
* A simple simulator server implementation that extends the MiCasa server
* and provides no special functionality.
* A simple simulator server implementation that extends the MiCasa server and provides no special
* functionality.
*/
public class SimpleServer extends MiCasaServer
implements SimulatorServer
{
// documentation inherited
public void init (ResultListener obs)
public void init (Injector injector, ResultListener obs)
throws Exception
{
super.init();
init(injector); // do our standard initialization
// create the simulator manager
SimulatorManager simmgr = new SimulatorManager();
@@ -21,29 +21,29 @@
package com.threerings.micasa.simulator.server;
import com.google.inject.Injector;
import com.samskivert.util.ResultListener;
/**
* The simulator manager needs a mechanism for faking body object
* registrations, which is provided by implementations of this interface.
* The simulator manager needs a mechanism for faking body object registrations, which is provided
* by implementations of this interface.
*/
public interface SimulatorServer
{
/**
* Called to initialize this server instance.
*
* @param obs the observer to notify when the server has finished
* starting up, or <code>null</code> if no notification is desired.
* @param obs the observer to notify when the server has finished starting up, or
* <code>null</code> if no notification is desired.
*
* @exception Exception thrown if anything goes wrong initializing the
* server.
* @exception Exception thrown if anything goes wrong initializing the server.
*/
public void init (ResultListener obs) throws Exception;
public void init (Injector injector, ResultListener obs) throws Exception;
/**
* Called to perform the main body of server processing. This is
* called from the server thread and should do the simulator server's
* primary business.
* Called to perform the main body of server processing. This is called from the server thread
* and should do the simulator server's primary business.
*/
public void run ();
}
@@ -38,24 +38,24 @@ import com.threerings.parlor.tourney.data.TourneyConfig;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.PresentsServer;
import com.threerings.presents.server.ShutdownManager;
import com.threerings.presents.data.ClientObject;
/**
* An extensible tournament manager.
*/
public abstract class TourniesManager
implements TourniesProvider, PresentsServer.Shutdowner
implements TourniesProvider, ShutdownManager.Shutdowner
{
public TourniesManager (ConnectionProvider conprov)
/**
* Initializes the tournies manager and starts its periodic update task.
*/
public void init (ConnectionProvider conprov)
throws PersistenceException
{
_tournrep = new TourneyRepository(conprov, getDBIdent());
loadTourneyConfigs();
}
public void init ()
{
_interval = new Interval(getRunQueue()) {
public void expired () {
updateTournies();
@@ -64,13 +64,13 @@ public abstract class TourniesManager
_interval.schedule(getIntervalDelay(), true);
}
// documentation inherited from interface PresentsServer.Shutdowner
// from interface ShutdownManager.Shutdowner
public void shutdown ()
{
_interval.cancel();
}
// documentation inherited from interface TourniesService
// from interface TourniesService
public void createTourney (ClientObject caller, TourneyConfig config,
final InvocationService.ResultListener listener)
throws InvocationException
@@ -78,6 +78,11 @@ public abstract class TourniesManager
makeTourney(config, listener);
}
protected TourniesManager (ShutdownManager shutmgr)
{
shutmgr.registerShutdowner(this);
}
/**
* Called to actually create a tourney once it has been validated and the prize has been
* reserved.
@@ -21,6 +21,8 @@
package com.threerings.stage.server;
import com.google.inject.Injector;
import com.threerings.resource.ResourceManager;
import com.threerings.media.tile.TileManager;
@@ -46,12 +48,11 @@ public abstract class StageServer extends WhirledServer
/** Provides access to our tile repository. */
public static TileManager tilemgr;
// documentation inherited
public void init ()
@Override // from WhirledServer
public void init (Injector injector)
throws Exception
{
// do the base server initialization
super.init();
super.init(injector);
// create the resource manager
rsrcmgr = new ResourceManager("rsrc");
@@ -21,6 +21,8 @@
package com.threerings.whirled.server;
import com.google.inject.Injector;
import com.threerings.util.Name;
import com.threerings.presents.net.AuthRequest;
@@ -41,17 +43,23 @@ import static com.threerings.whirled.Log.log;
*/
public abstract class WhirledServer extends CrowdServer
{
/** Configures dependencies needed by the Whirled server. */
public static class Module extends CrowdServer.Module
{
@Override protected void configure () {
super.configure();
// nada
}
}
/** The scene registry. */
public static SceneRegistry screg;
/**
* Initializes all of the server services and prepares for operation.
*/
public void init ()
@Override // from CrowdServer
public void init (Injector injector)
throws Exception
{
// do the base server initialization
super.init();
super.init(injector);
// configure the client to use our whirled client
clmgr.setClientFactory(new ClientFactory() {
@@ -21,6 +21,9 @@
package com.threerings.parlor;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.parlor.server.ParlorManager;
@@ -35,11 +38,11 @@ public class TestServer extends CrowdServer
/** The parlor manager in operation on this server. */
public static ParlorManager parmgr = new ParlorManager();
/** Initializes the Parlor test server. */
public void init ()
@Override // from CrowdServer
public void init (Injector injector)
throws Exception
{
super.init();
super.init(injector);
// initialize our parlor manager
parmgr.init(invmgr, plreg);
@@ -50,9 +53,10 @@ public class TestServer extends CrowdServer
/** Main entry point for test server. */
public static void main (String[] args)
{
TestServer server = new TestServer();
Injector injector = Guice.createInjector(new Module());
TestServer server = injector.getInstance(TestServer.class);
try {
server.init();
server.init(injector);
server.run();
} catch (Exception e) {
log.warning("Unable to initialize server.", e);