Extracted the simulator server services out into an implementable

interface so that we can replace the server with a more sophisticated one
when running the simulator.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@938 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-02-05 22:12:42 +00:00
parent 8dd6ac2b32
commit 9e6e07ea61
4 changed files with 60 additions and 49 deletions
@@ -1,5 +1,5 @@
//
// $Id: SimulatorApp.java,v 1.2 2002/01/16 02:59:08 mdb Exp $
// $Id: SimulatorApp.java,v 1.3 2002/02/05 22:12:42 mdb Exp $
package com.threerings.micasa.simulator.client;
@@ -15,6 +15,7 @@ import com.threerings.presents.net.UsernamePasswordCreds;
import com.threerings.micasa.Log;
import com.threerings.micasa.simulator.data.SimulatorInfo;
import com.threerings.micasa.simulator.server.SimpleServer;
import com.threerings.micasa.simulator.server.SimulatorServer;
/**
@@ -26,7 +27,7 @@ public class SimulatorApp
public void init (String[] args) throws Exception
{
// create the server
SimulatorServer server = new SimulatorServer();
SimulatorServer server = createSimulatorServer();
server.init();
_serverThread = new ServerThread(server);
@@ -49,6 +50,11 @@ public class SimulatorApp
_frame.setController(ctrl);
}
protected SimulatorServer createSimulatorServer ()
{
return new SimpleServer();
}
protected SimulatorFrame createSimulatorFrame ()
{
return new SimpleFrame();
@@ -0,0 +1,30 @@
//
// $Id: SimpleServer.java,v 1.1 2002/02/05 22:12:42 mdb Exp $
package com.threerings.micasa.simulator.server;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.CrowdServer;
/**
* A simple simulator server implementation that extends the crowd server
* and provides no special functionality.
*/
public class SimpleServer extends CrowdServer
implements SimulatorServer
{
/**
* Called by the simulator manager to map a username to a particular
* body object. This should only be called from the dobjmgr thread.
*
* <p> This is copied from {@link CrowdServer#mapBody} as that
* implementation is protected and cannot be referenced by classes in
* the simulator package, but we know what we're doing and so we
* knowingly expose this functionality to other classes in our
* package.
*/
public void fakeBodyMapping (String username, BodyObject bodobj)
{
_bodymap.put(username, bodobj);
}
}
@@ -1,5 +1,5 @@
//
// $Id: SimulatorManager.java,v 1.5 2002/02/05 20:27:07 mdb Exp $
// $Id: SimulatorManager.java,v 1.6 2002/02/05 22:12:42 mdb Exp $
package com.threerings.micasa.simulator.server;
@@ -49,7 +49,7 @@ public class SimulatorManager
*/
public void init (Config config, InvocationManager invmgr,
PlaceRegistry plreg, ClientManager clmgr,
RootDObjectManager omgr)
RootDObjectManager omgr, SimulatorServer simserv)
{
// register our simulator provider
SimulatorProvider sprov = new SimulatorProvider(this);
@@ -59,6 +59,7 @@ public class SimulatorManager
_plreg = plreg;
_clmgr = clmgr;
_omgr = omgr;
_simserv = simserv;
}
/**
@@ -125,7 +126,7 @@ public class SimulatorManager
bobj.username = "simulant" + (_sims.size() + 1);
// map the simulant into the server body set
SimulatorServer.mapBody(bobj.username, bobj);
_simserv.fakeBodyMapping(bobj.username, bobj);
// hold onto it for later game creation
_sims.add(bobj);
@@ -171,7 +172,7 @@ public class SimulatorManager
// give the simulant its body
BodyObject bobj = (BodyObject)_sims.get(ii - 1);
sim.init(bobj, _config);
sim.init(bobj, _config, _omgr);
// give the simulant a chance to engage in place antics
sim.willEnterPlace(_gobj);
@@ -214,4 +215,5 @@ public class SimulatorManager
protected PlaceRegistry _plreg;
protected ClientManager _clmgr;
protected RootDObjectManager _omgr;
protected SimulatorServer _simserv;
}
@@ -1,61 +1,34 @@
//
// $Id: SimulatorServer.java,v 1.4 2002/02/05 20:27:07 mdb Exp $
// $Id: SimulatorServer.java,v 1.5 2002/02/05 22:12:42 mdb Exp $
package com.threerings.micasa.simulator.server;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.micasa.Log;
/**
* This class is the main entry point and general organizer of everything
* that goes on in the Simulator game server process.
* The simulator manager needs a mechanism for faking body object
* registrations, which is provided by implementations of this interface.
*/
public class SimulatorServer extends CrowdServer
public interface SimulatorServer
{
/** The simulator manager in operation on this server. */
public static SimulatorManager simmgr = new SimulatorManager();
/**
* Called to initialize this server instance.
*
* @exception Exception thrown if anything goes wrong initializing the
* server.
*/
public void init () throws Exception;
/**
* Initializes all of the server services and prepares for operation.
* 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 init ()
throws Exception
{
// do the base server initialization
super.init();
// initialize the manager
simmgr.init(config, invmgr, plreg, clmgr, omgr);
Log.info("Simulator server initialized.");
}
public void run ();
/**
* Called by the simulator manager to map a username to a particular
* body object. This should only be called from the dobjmgr thread.
*
* <p> This is copied from {@link CrowdServer#mapBody} as that
* implementation is protected and cannot be referenced by classes in
* the simulator package, but we know what we're doing and so we
* knowingly expose this functionality to other classes in our
* package.
*/
protected static void mapBody (String username, BodyObject bodobj)
{
_bodymap.put(username, bodobj);
}
public static void main (String[] args)
{
SimulatorServer server = new SimulatorServer();
try {
server.init();
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
}
public void fakeBodyMapping (String username, BodyObject bodobj);
}