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
@@ -0,0 +1,52 @@
//
// $Id: LocationDecoder.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.client;
import com.threerings.crowd.client.LocationReceiver;
import com.threerings.presents.client.InvocationDecoder;
/**
* Dispatches calls to a {@link LocationReceiver} instance.
*/
public class LocationDecoder extends InvocationDecoder
{
/** The generated hash code used to identify this receiver class. */
public static final String RECEIVER_CODE = "58f2830e027f4f3377e100ef12332497";
/** The method id used to dispatch {@link LocationReceiver#forcedMove}
* notifications. */
public static final int FORCED_MOVE = 1;
/**
* Creates a decoder that may be registered to dispatch invocation
* service notifications to the specified receiver.
*/
public LocationDecoder (LocationReceiver receiver)
{
this.receiver = receiver;
}
// documentation inherited
public String getReceiverCode ()
{
return RECEIVER_CODE;
}
// documentation inherited
public void dispatchNotification (int methodId, Object[] args)
{
switch (methodId) {
case FORCED_MOVE:
((LocationReceiver)receiver).forcedMove(
((Integer)args[0]).intValue()
);
return;
default:
super.dispatchNotification(methodId, args);
}
}
// Generated on 11:25:46 08/12/02.
}
@@ -1,5 +1,5 @@
//
// $Id: LocationDirector.java,v 1.24 2002/06/14 01:40:16 ray Exp $
// $Id: LocationDirector.java,v 1.25 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.client;
@@ -10,9 +10,9 @@ import com.samskivert.util.ObserverList;
import com.samskivert.util.ObserverList.ObserverOp;
import com.samskivert.util.ResultListener;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationReceiver;
import com.threerings.presents.client.SessionObserver;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.ObjectAccessException;
@@ -32,8 +32,9 @@ import com.threerings.crowd.util.CrowdContext;
* provides a mechanism for ratifying a request to move to a new place
* before actually issuing the request.
*/
public class LocationDirector
implements LocationCodes, SessionObserver, Subscriber, InvocationReceiver
public class LocationDirector extends BasicDirector
implements LocationCodes, Subscriber, LocationReceiver,
LocationService.MoveListener
{
/**
* Used to recover from a moveTo request that was accepted but
@@ -55,15 +56,14 @@ public class LocationDirector
*/
public LocationDirector (CrowdContext ctx)
{
super(ctx);
// keep this around for later
_ctx = ctx;
// register ourselves as a client observer
ctx.getClient().addClientObserver(this);
// register for location notifications
_ctx.getClient().getInvocationDirector().registerReceiver(
MODULE_NAME, this);
new LocationDecoder(this));
}
/**
@@ -137,7 +137,7 @@ public class LocationDirector
_pendingPlaceId = placeId;
// issue a moveTo request
LocationService.moveTo(_ctx.getClient(), placeId, this);
_lservice.moveTo(_ctx.getClient(), placeId, this);
return true;
}
@@ -314,7 +314,9 @@ public class LocationDirector
// documentation inherited from interface
public void clientDidLogon (Client client)
{
// get a copy of our body object
super.clientDidLogon(client);
// subscribe to our body object
Subscriber sub = new Subscriber() {
public void objectAvailable (DObject object)
{
@@ -332,6 +334,14 @@ public class LocationDirector
client.getDObjectManager().subscribeToObject(cloid, sub);
}
// documentation inherited
protected void fetchServices (Client client)
{
// obtain our service handle
_lservice = (LocationService)
client.requireService(LocationService.class);
}
protected void gotBodyObject (BodyObject clobj)
{
// check to see if we are already in a location, in which case
@@ -341,17 +351,19 @@ public class LocationDirector
// documentation inherited from interface
public void clientDidLogoff (Client client)
{
super.clientDidLogoff(client);
// clear ourselves out and inform observers of our departure
didLeavePlace();
// let our observers know that we're no longer in a location
_observers.apply(_didChangeOp);
_lservice = null;
}
/**
* Called in response to a successful <code>moveTo</code> request.
*/
public void handleMoveSucceeded (int invid, PlaceConfig config)
// documentation inherited from interface
public void moveSucceeded (PlaceConfig config)
{
// handle the successful move
didMoveTo(_pendingPlaceId, config);
@@ -360,10 +372,8 @@ public class LocationDirector
_pendingPlaceId = -1;
}
/**
* Called in response to a failed <code>moveTo</code> request.
*/
public void handleMoveFailed (int invid, String reason)
// documentation inherited from interface
public void requestFailed (String reason)
{
// clear out our pending request oid
int placeId = _pendingPlaceId;
@@ -376,13 +386,8 @@ public class LocationDirector
notifyFailure(placeId, reason);
}
/**
* Called when the server has decided to forcibly move us to another
* room. The server first ejects us from our previous room and then
* sends us a notification with our new location. We then turn around
* and issue a standard moveTo request.
*/
public void handleMoveNotification (int placeId)
// documentation inherited from interface
public void forcedMove (int placeId)
{
Log.info("Moving at request of server [placeId=" + placeId + "].");
@@ -493,6 +498,9 @@ public class LocationDirector
/** The context through which we access needed services. */
protected CrowdContext _ctx;
/** Provides access to location services. */
protected LocationService _lservice;
/** Our location observer list. */
protected ObserverList _observers =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
@@ -0,0 +1,21 @@
//
// $Id: LocationReceiver.java,v 1.1 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.client;
import com.threerings.presents.client.InvocationReceiver;
/**
* Defines, for the location services, a set of notifications delivered
* asynchronously by the server to the client.
*/
public interface LocationReceiver extends InvocationReceiver
{
/**
* Used to communicate a required move notification to the client. The
* server will have removed the client from their existing location
* and the client is then responsible for generating a {@link
* LocationService#moveTo} request to move to the new location.
*/
public void forcedMove (int placeId);
}
@@ -1,33 +1,43 @@
//
// $Id: LocationService.java,v 1.6 2002/05/15 23:54:34 mdb Exp $
// $Id: LocationService.java,v 1.7 2002/08/14 19:07:49 mdb Exp $
package com.threerings.crowd.client;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationDirector;
import com.threerings.presents.client.InvocationService;
import com.threerings.crowd.Log;
import com.threerings.crowd.data.LocationCodes;
import com.threerings.crowd.data.PlaceConfig;
/**
* The location services provide a mechanism by which the client can
* request to move from place to place in the server. These services
* should not be used directly, but instead should be accessed via the
* location director.
*
* @see LocationDirector
* {@link LocationDirector}.
*/
public class LocationService implements LocationCodes
public interface LocationService extends InvocationService
{
/**
* Requests that that this client's body be moved to the specified
* location.
* Used to communicate responses to {@link #moveTo} requests.
*/
public static void moveTo (Client client, int placeId,
LocationDirector rsptarget)
public static interface MoveListener extends InvocationListener
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[] { new Integer(placeId) };
invdir.invoke(MODULE_NAME, MOVE_TO_REQUEST, args, rsptarget);
Log.debug("Sent moveTo request [place=" + placeId + "].");
/**
* Called in response to a successful {@link #moveTo} request.
*/
public void moveSucceeded (PlaceConfig config);
}
/**
* Requests that this client's body be moved to the specified
* location.
*
* @param client a reference to the client object that defines the
* context in which this invocation service should be executed.
* @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 moveTo (Client client, int placeId, MoveListener listener);
}