Doris the refactorasaurus. Restructured the whole client object resolution

process so that it can be done by other entities than just the client
management services. Coordination between these parties is managed so that
no toes are stepped on in the course of loading and unloading clients and
everything is generally much nicer.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1086 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-03-05 05:33:25 +00:00
parent 38ca708a4f
commit 9e16e87a69
13 changed files with 456 additions and 228 deletions
@@ -1,45 +1,16 @@
//
// $Id: CrowdClient.java,v 1.7 2002/02/20 23:35:42 mdb Exp $
// $Id: CrowdClient.java,v 1.8 2002/03/05 05:33:25 mdb Exp $
package com.threerings.crowd.server;
import com.threerings.presents.server.PresentsClient;
import com.threerings.crowd.data.BodyObject;
/**
* The crowd client extends the presents client and does some
* initializations necessary for the crowd services.
* The crowd client extends the presents client but doesn't really do
* anything at present. It exists mainly so that implementation systems
* will extend it and ensure that we have the option of adding
* functionality here in the future.
*/
public class CrowdClient extends PresentsClient
{
protected void sessionWillStart (Object authInfo)
{
super.sessionWillStart(authInfo);
// cast our client object to a body object
_bodobj = (BodyObject)_clobj;
// and configure our username
_bodobj.setUsername(_username);
// register our body object mapping
CrowdServer.mapBody(_username, _bodobj);
}
protected void sessionWillResume (Object authInfo)
{
super.sessionWillResume(authInfo);
// nothing to do here presently
}
protected void sessionDidTerminate ()
{
super.sessionDidTerminate();
// unregister our body object mapping
CrowdServer.unmapBody(_username);
}
protected BodyObject _bodobj;
}
@@ -0,0 +1,29 @@
//
// $Id: CrowdClientResolver.java,v 1.1 2002/03/05 05:33:25 mdb Exp $
package com.threerings.crowd.server;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.ClientResolver;
import com.threerings.crowd.data.BodyObject;
/**
* Used to configure crowd-specific client object data.
*/
public class CrowdClientResolver extends ClientResolver
{
// documentation inherited
public Class getClientObjectClass ()
{
return BodyObject.class;
}
// documentation inherited
protected void resolveClientData (ClientObject clobj)
throws Exception
{
// just fill in the username
((BodyObject)clobj).username = _username;
}
}
@@ -1,5 +1,5 @@
//
// $Id: CrowdServer.java,v 1.9 2001/12/04 01:02:59 mdb Exp $
// $Id: CrowdServer.java,v 1.10 2002/03/05 05:33:25 mdb Exp $
package com.threerings.crowd.server;
@@ -34,11 +34,11 @@ public class CrowdServer extends PresentsServer
// bind the crowd server config into the namespace
config.bindProperties(CONFIG_KEY, CONFIG_PATH, true);
// configure the client to use our crowd client
// configure the client manager to use our client
clmgr.setClientClass(CrowdClient.class);
// configure the client to use the body object
clmgr.setClientObjectClass(BodyObject.class);
// configure the client manager to use our resolver
clmgr.setClientResolverClass(CrowdClientResolver.class);
// create our place registry
plreg = new PlaceRegistry(config, invmgr, omgr);
@@ -50,31 +50,13 @@ public class CrowdServer extends PresentsServer
}
/**
* The crowd server maintains a mapping of username to body object for
* all active users on the server. This should only be called from the
* The server maintains a mapping of username to body object for all
* active users on the server. This should only be called from the
* dobjmgr thread.
*/
public static BodyObject lookupBody (String username)
{
return (BodyObject)_bodymap.get(username);
}
/**
* Called by the crowd client to map a username to a particular body
* object. This should only be called from the dobjmgr thread.
*/
protected static void mapBody (String username, BodyObject bodobj)
{
_bodymap.put(username, bodobj);
}
/**
* Called by the crowd client to unmap a username from a particular
* body object. This should only be called from the dobjmgr thread.
*/
protected static void unmapBody (String username)
{
_bodymap.remove(username);
return (BodyObject)clmgr.getClientObject(username);
}
public static void main (String[] args)