The great invocation services rethink of 2002! Rearchitected the remote

method invocation services and converted everything to the new style.
Could this be my biggest checkin ever?


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1642 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-08-14 19:08:01 +00:00
parent 4481c5f835
commit e54a4d41f4
161 changed files with 6083 additions and 2805 deletions
@@ -1,5 +1,5 @@
//
// $Id: CrowdServer.java,v 1.12 2002/04/18 00:44:50 shaper Exp $
// $Id: CrowdServer.java,v 1.13 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.server;
@@ -8,6 +8,7 @@ import java.util.Iterator;
import com.threerings.presents.server.PresentsServer;
import com.threerings.crowd.Log;
import com.threerings.crowd.chat.ChatProvider;
import com.threerings.crowd.data.BodyObject;
/**
@@ -40,10 +41,13 @@ public class CrowdServer extends PresentsServer
// create our place registry
plreg = new PlaceRegistry(invmgr, omgr);
// register our invocation service providers
String[] providers = null;
providers = CrowdConfig.config.getValue(PROVIDERS_KEY, providers);
registerProviders(providers);
// initialize the chat services
ChatProvider.init(invmgr, omgr);
// // register our invocation service providers
// String[] providers = null;
// providers = CrowdConfig.config.getValue(PROVIDERS_KEY, providers);
// registerProviders(providers);
Log.info("Crowd server initialized.");
}
@@ -0,0 +1,53 @@
//
// $Id: LocationDispatcher.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.server;
import com.threerings.crowd.client.LocationService;
import com.threerings.crowd.client.LocationService.MoveListener;
import com.threerings.crowd.data.LocationMarshaller;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
/**
* Dispatches requests to the {@link LocationProvider}.
*/
public class LocationDispatcher extends InvocationDispatcher
{
/**
* Creates a dispatcher that may be registered to dispatch invocation
* service requests for the specified provider.
*/
public LocationDispatcher (LocationProvider provider)
{
this.provider = provider;
}
// documentation inherited
public InvocationMarshaller createMarshaller ()
{
return new LocationMarshaller();
}
// documentation inherited
public void dispatchRequest (
ClientObject source, int methodId, Object[] args)
throws InvocationException
{
switch (methodId) {
case LocationMarshaller.MOVE_TO:
((LocationProvider)provider).moveTo(
source,
((Integer)args[0]).intValue(), (MoveListener)args[1]
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
}
}
@@ -1,16 +1,19 @@
//
// $Id: LocationProvider.java,v 1.15 2002/06/20 22:38:58 mdb Exp $
// $Id: LocationProvider.java,v 1.16 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.server;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.presents.server.ServiceFailedException;
import com.threerings.crowd.Log;
import com.threerings.crowd.client.LocationService;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.LocationCodes;
import com.threerings.crowd.data.OccupantInfo;
@@ -20,42 +23,38 @@ import com.threerings.crowd.data.PlaceObject;
/**
* This class provides the server end of the location services.
*/
public class LocationProvider extends InvocationProvider
implements LocationCodes
public class LocationProvider
implements LocationCodes, InvocationProvider
{
/**
* Constructs a location provider and registers it with the invocation
* manager to handle location services. This is done automatically by
* the {@link PlaceRegistry}.
* Creates a location provider and prepares it for operation.
*/
public static void init (
InvocationManager invmgr, RootDObjectManager omgr, PlaceRegistry plreg)
public LocationProvider (InvocationManager invmgr, RootDObjectManager omgr,
PlaceRegistry plreg)
{
// we'll need these later
_invmgr = invmgr;
_omgr = omgr;
_plreg = plreg;
// register a location provider instance
invmgr.registerProvider(MODULE_NAME, new LocationProvider());
}
/**
* Processes a request from a client to move to a new place.
* Requests that this client's body be moved to the specified
* location.
*
* @param caller the client object of the client that invoked this
* remotely callable method.
* @param placeId the object id of the place object to which the body
* should be moved.
* @param listener the listener that will be informed of success or
* failure.
*/
public void handleMoveToRequest (
BodyObject source, int invid, int placeId)
public void moveTo (ClientObject caller, int placeId,
LocationService.MoveListener listener)
throws InvocationException
{
try {
// do the move
PlaceConfig config = moveTo(source, placeId);
// and send the response
sendResponse(source, invid, MOVE_SUCCEEDED_RESPONSE, config);
} catch (ServiceFailedException sfe) {
sendResponse(source, invid, MOVE_FAILED_RESPONSE,
sfe.getMessage());
}
// do the move and send the response
listener.moveSucceeded(moveTo((BodyObject)caller, placeId));
}
/**
@@ -68,8 +67,8 @@ public class LocationProvider extends InvocationProvider
* successful for some reason (which will be communicated as an error
* code in the exception's message data).
*/
public static PlaceConfig moveTo (BodyObject source, int placeId)
throws ServiceFailedException
public PlaceConfig moveTo (BodyObject source, int placeId)
throws InvocationException
{
int bodoid = source.getOid();
@@ -78,7 +77,7 @@ public class LocationProvider extends InvocationProvider
if (pmgr == null) {
Log.info("Requested to move to non-existent place " +
"[source=" + source + ", place=" + placeId + "].");
throw new ServiceFailedException(NO_SUCH_PLACE);
throw new InvocationException(NO_SUCH_PLACE);
}
// if they're already in the location they're asking to move to,
@@ -97,26 +96,17 @@ public class LocationProvider extends InvocationProvider
if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't
// been fully processed
throw new ServiceFailedException(MOVE_IN_PROGRESS);
throw new InvocationException(MOVE_IN_PROGRESS);
}
PlaceObject place = pmgr.getPlaceObject();
try {
place.startTransaction();
source.startTransaction();
// remove them from any previous location
leaveOccupiedPlace(source);
// set the body's new location
source.setLocation(place.getOid());
} finally {
source.commitTransaction();
}
try {
place.startTransaction();
// generate a new occupant info record and add it to the
// target location
OccupantInfo info = pmgr.buildOccupantInfo(source);
@@ -124,11 +114,15 @@ public class LocationProvider extends InvocationProvider
place.addToOccupantInfo(info);
}
// set the body's new location
source.setLocation(place.getOid());
// add the body oid to the place object's occupant list
place.addToOccupants(bodoid);
} finally {
place.commitTransaction();
source.commitTransaction();
}
} finally {
@@ -144,7 +138,7 @@ public class LocationProvider extends InvocationProvider
* Removes the specified body from the place object they currently
* occupy. Does nothing if the body is not currently in a place.
*/
public static void leaveOccupiedPlace (BodyObject source)
public void leaveOccupiedPlace (BodyObject source)
{
int oldloc = source.location;
int bodoid = source.getOid();
@@ -200,18 +194,16 @@ public class LocationProvider extends InvocationProvider
// first remove them from their old place
leaveOccupiedPlace(source);
// then send a move notification
_invmgr.sendNotification(
source.getOid(), MODULE_NAME, MOVE_NOTIFICATION,
new Object[] { new Integer(placeId) });
// then send a forced move notification
LocationSender.forcedMove(source, placeId);
}
/** The invocation manager with which we interoperate. */
protected static InvocationManager _invmgr;
protected InvocationManager _invmgr;
/** The distributed object manager with which we interoperate. */
protected static RootDObjectManager _omgr;
protected RootDObjectManager _omgr;
/** The place registry with which we interoperate. */
protected static PlaceRegistry _plreg;
protected PlaceRegistry _plreg;
}
@@ -0,0 +1,30 @@
//
// $Id: LocationSender.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.server;
import com.threerings.crowd.client.LocationDecoder;
import com.threerings.crowd.client.LocationReceiver;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationSender;
/**
* Used to issue notifications to a {@link LocationReceiver} instance on a
* client.
*/
public class LocationSender extends InvocationSender
{
/**
* Issues a notification that will result in a call to {@link
* LocationReceiver#forcedMove} on a client.
*/
public static void forcedMove (
ClientObject target, int arg1)
{
sendNotification(
target, LocationDecoder.RECEIVER_CODE, LocationDecoder.FORCED_MOVE,
new Object[] { new Integer(arg1) });
}
// Generated on 11:25:46 08/12/02.
}
@@ -1,5 +1,5 @@
//
// $Id: PlaceManager.java,v 1.31 2002/06/20 22:12:22 mdb Exp $
// $Id: PlaceManager.java,v 1.32 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.server;
@@ -7,6 +7,10 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.dobj.MessageListener;
@@ -22,6 +26,10 @@ import com.threerings.crowd.data.OccupantInfo;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.chat.SpeakDispatcher;
import com.threerings.crowd.chat.SpeakMarshaller;
import com.threerings.crowd.chat.SpeakProvider;
/**
* The place manager is the server-side entity that handles all
* place-related interaction. It subscribes to the place object and reacts
@@ -42,7 +50,8 @@ import com.threerings.crowd.data.PlaceObject;
* listeners.
*/
public class PlaceManager
implements MessageListener, OidListListener, ObjectDeathListener
implements MessageListener, OidListListener, ObjectDeathListener,
SpeakProvider.SpeakerValidator
{
/**
* An interface used to allow the registration of standard message
@@ -99,11 +108,13 @@ public class PlaceManager
* Called by the place registry after creating this place manager.
*/
public void init (
PlaceRegistry registry, PlaceConfig config, DObjectManager omgr)
PlaceRegistry registry, InvocationManager invmgr,
DObjectManager omgr, PlaceConfig config)
{
_registry = registry;
_config = config;
_invmgr = invmgr;
_omgr = omgr;
_config = config;
// let derived classes do initialization stuff
didInit();
@@ -135,6 +146,13 @@ public class PlaceManager
// keep track of this
_plobj = plobj;
// create and register a speaker service instance that clients can
// use to speak in this place
SpeakMarshaller speakService =
(SpeakMarshaller)_invmgr.registerDispatcher(
new SpeakDispatcher(new SpeakProvider(_plobj, this)), false);
plobj.setSpeakService(speakService);
// we'll need to hear about place object events
plobj.addListener(this);
@@ -379,6 +397,13 @@ public class PlaceManager
didShutdown();
}
// documentation inherited from interface
public boolean isValidSpeaker (DObject speakObj, ClientObject speaker)
{
// only allow people in the room to speak
return _plobj.occupants.contains(speaker.getOid());
}
/**
* Generates a string representation of this manager. Does so in a way
* that makes it easier for derived classes to add to the string
@@ -438,6 +463,13 @@ public class PlaceManager
}
}
/** A reference to the place registry with which we're registered. */
protected PlaceRegistry _registry;
/** The invocation manager with whom we register our game invocation
* services. */
protected InvocationManager _invmgr;
/** A distributed object manager for doing dobj stuff. */
protected DObjectManager _omgr;
@@ -447,9 +479,6 @@ public class PlaceManager
/** A reference to the configuration for our place. */
protected PlaceConfig _config;
/** A reference to the place registry with which we're registered. */
protected PlaceRegistry _registry;
/** Message handlers are used to process message events. */
protected HashMap _msghandlers;
@@ -1,5 +1,5 @@
//
// $Id: PlaceRegistry.java,v 1.20 2002/04/15 16:28:01 shaper Exp $
// $Id: PlaceRegistry.java,v 1.21 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.server;
@@ -43,17 +43,23 @@ public class PlaceRegistry
public void placeCreated (PlaceObject place, PlaceManager pmgr);
}
/** The location provider used by the place registry to provide
* location-related invocation services. */
public LocationProvider locprov;
/**
* Creates and initializes the place registry; called by the server
* during its initialization phase.
*/
public PlaceRegistry (InvocationManager invmgr, RootDObjectManager omgr)
{
// we'll need this later
_omgr = omgr;
// create and register our location provider
locprov = new LocationProvider(invmgr, omgr, this);
invmgr.registerDispatcher(new LocationDispatcher(locprov), true);
// register the location provider
LocationProvider.init(invmgr, omgr, this);
// we'll need these later
_omgr = omgr;
_invmgr = invmgr;
}
/**
@@ -86,7 +92,7 @@ public class PlaceRegistry
// create a place manager for this place
PlaceManager pmgr = (PlaceManager)pmgrClass.newInstance();
// let the pmgr know about us and its configuration
pmgr.init(this, config, _omgr);
pmgr.init(this, _invmgr, _omgr, config);
// stick the manager on the creation queue because we know
// we'll get our calls to objectAvailable()/requestFailed() in
@@ -221,6 +227,9 @@ public class PlaceRegistry
}
}
/** The invocation manager with which we operate. */
protected InvocationManager _invmgr;
/** The distributed object manager with which we operate. */
protected RootDObjectManager _omgr;