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
@@ -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 ();
}