Modified simulator server interface to allow initializing the server with
asynchronous notification when initialization is complete. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1431 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SimulatorApp.java,v 1.7 2002/05/09 04:39:12 shaper Exp $
|
||||
// $Id: SimulatorApp.java,v 1.8 2002/06/10 19:16:41 shaper Exp $
|
||||
|
||||
package com.threerings.micasa.simulator.client;
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.swing.JFrame;
|
||||
|
||||
import com.samskivert.swing.Controller;
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.ClientAdapter;
|
||||
@@ -24,13 +25,8 @@ import com.threerings.micasa.simulator.server.SimulatorServer;
|
||||
*/
|
||||
public class SimulatorApp
|
||||
{
|
||||
public void init (String[] args) throws Exception
|
||||
public void start (final String[] args) throws Exception
|
||||
{
|
||||
// create the server
|
||||
SimulatorServer server = createSimulatorServer();
|
||||
server.init();
|
||||
_serverThread = new ServerThread(server);
|
||||
|
||||
// create a frame
|
||||
_frame = createSimulatorFrame();
|
||||
|
||||
@@ -48,6 +44,28 @@ public class SimulatorApp
|
||||
Controller ctrl = new ClientController(
|
||||
_client.getParlorContext(), _frame, siminfo);
|
||||
_frame.setController(ctrl);
|
||||
|
||||
// create the server
|
||||
SimulatorServer server = createSimulatorServer();
|
||||
server.init(new ResultListener() {
|
||||
public void requestCompleted (Object result) {
|
||||
try {
|
||||
run();
|
||||
} catch (Exception e) {
|
||||
Log.warning("Simulator initialization failed " +
|
||||
"[e=" + e + "].");
|
||||
}
|
||||
}
|
||||
public void requestFailed (Exception e) {
|
||||
Log.warning("Simulator initialization failed [e=" + e + "].");
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
_serverThread.start();
|
||||
}
|
||||
|
||||
protected SimulatorServer createSimulatorServer ()
|
||||
@@ -74,9 +92,6 @@ public class SimulatorApp
|
||||
SwingUtil.centerWindow(frame);
|
||||
frame.show();
|
||||
|
||||
// start up the server
|
||||
_serverThread.start();
|
||||
|
||||
// start up the client
|
||||
Client client = _client.getParlorContext().getClient();
|
||||
|
||||
@@ -118,13 +133,11 @@ public class SimulatorApp
|
||||
|
||||
SimulatorApp app = new SimulatorApp();
|
||||
try {
|
||||
app.init(args);
|
||||
app.start(args);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Error initializing application.");
|
||||
Log.warning("Error starting up application.");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
protected static boolean checkArgs (String[] args)
|
||||
@@ -169,10 +182,10 @@ public class SimulatorApp
|
||||
protected SimulatorServer _server;
|
||||
}
|
||||
|
||||
/** The default number of players in the game. */
|
||||
protected static final int DEFAULT_PLAYER_COUNT = 2;
|
||||
|
||||
protected SimulatorClient _client;
|
||||
protected SimulatorFrame _frame;
|
||||
protected ServerThread _serverThread;
|
||||
|
||||
/** The default number of players in the game. */
|
||||
protected static final int DEFAULT_PLAYER_COUNT = 2;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
//
|
||||
// $Id: SimpleServer.java,v 1.4 2002/03/28 22:32:32 mdb Exp $
|
||||
// $Id: SimpleServer.java,v 1.5 2002/06/10 19:16:41 shaper Exp $
|
||||
|
||||
package com.threerings.micasa.simulator.server;
|
||||
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
|
||||
@@ -14,7 +16,7 @@ public class SimpleServer extends CrowdServer
|
||||
implements SimulatorServer
|
||||
{
|
||||
// documentation inherited
|
||||
public void init ()
|
||||
public void init (ResultListener obs)
|
||||
throws Exception
|
||||
{
|
||||
super.init();
|
||||
@@ -22,5 +24,10 @@ public class SimpleServer extends CrowdServer
|
||||
// create the simulator manager
|
||||
SimulatorManager simmgr = new SimulatorManager();
|
||||
simmgr.init(invmgr, plreg, clmgr, omgr, this);
|
||||
|
||||
if (obs != null) {
|
||||
// let the initialization observer know that we've started up
|
||||
obs.requestCompleted(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
//
|
||||
// $Id: SimulatorServer.java,v 1.6 2002/03/05 05:33:25 mdb Exp $
|
||||
// $Id: SimulatorServer.java,v 1.7 2002/06/10 19:16:41 shaper Exp $
|
||||
|
||||
package com.threerings.micasa.simulator.server;
|
||||
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
|
||||
/**
|
||||
@@ -14,10 +16,13 @@ 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.
|
||||
*
|
||||
* @exception Exception thrown if anything goes wrong initializing the
|
||||
* server.
|
||||
*/
|
||||
public void init () throws Exception;
|
||||
public void init (ResultListener obs) throws Exception;
|
||||
|
||||
/**
|
||||
* Called to perform the main body of server processing. This is
|
||||
|
||||
Reference in New Issue
Block a user