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