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: SceneDecoder.java,v 1.1 2002/08/14 19:07:57 mdb Exp $
package com.threerings.whirled.client;
import com.threerings.presents.client.InvocationDecoder;
import com.threerings.whirled.client.SceneReceiver;
/**
* Dispatches calls to a {@link SceneReceiver} instance.
*/
public class SceneDecoder extends InvocationDecoder
{
/** The generated hash code used to identify this receiver class. */
public static final String RECEIVER_CODE = "c4d0cf66b81a6e83d119b2d607725651";
/** The method id used to dispatch {@link SceneReceiver#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 SceneDecoder (SceneReceiver 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:
((SceneReceiver)receiver).forcedMove(
((Integer)args[0]).intValue()
);
return;
default:
super.dispatchNotification(methodId, args);
}
}
// Generated on 11:25:48 08/12/02.
}
@@ -1,5 +1,5 @@
//
// $Id: SceneDirector.java,v 1.19 2002/06/14 01:40:16 ray Exp $
// $Id: SceneDirector.java,v 1.20 2002/08/14 19:07:57 mdb Exp $
package com.threerings.whirled.client;
@@ -7,9 +7,8 @@ import java.io.IOException;
import com.samskivert.util.HashIntMap;
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.ObjectAccessException;
@@ -37,9 +36,9 @@ import com.threerings.whirled.util.WhirledContext;
* LocationObserver#locationMayChange} and {@link
* LocationObserver#locationChangeFailed}.
*/
public class SceneDirector
implements SceneCodes, SessionObserver, LocationDirector.FailureHandler,
InvocationReceiver
public class SceneDirector extends BasicDirector
implements SceneCodes, LocationDirector.FailureHandler,
SceneReceiver, SceneService.SceneMoveListener
{
/**
* Creates a new scene director with the specified context.
@@ -55,6 +54,8 @@ public class SceneDirector
public SceneDirector (WhirledContext ctx, LocationDirector locdir,
SceneRepository screp, DisplaySceneFactory dsfact)
{
super(ctx);
// we'll need these for later
_ctx = ctx;
_locdir = locdir;
@@ -65,13 +66,9 @@ public class SceneDirector
// director because we need to do special processing
_locdir.setFailureHandler(this);
// register ourselves as a client observer so that we can clear
// out our scene when the client logs off
_ctx.getClient().addClientObserver(this);
// register for scene notifications
_ctx.getClient().getInvocationDirector().registerReceiver(
MODULE_NAME, this);
new SceneDecoder(this));
}
/**
@@ -115,7 +112,7 @@ public class SceneDirector
}
// issue a moveTo request
SceneService.moveTo(_ctx.getClient(), sceneId, sceneVers, this);
_sservice.moveTo(_ctx.getClient(), sceneId, sceneVers, this);
return true;
}
@@ -176,11 +173,8 @@ public class SceneDirector
return _pendingModel;
}
/**
* Called in response to a successful <code>moveTo</code> request.
*/
public void handleMoveSucceeded (
int invid, int placeId, PlaceConfig config)
// documentation inherited from interface
public void moveSucceeded (int placeId, PlaceConfig config)
{
// our move request was successful, deal with subscribing to our
// new place object
@@ -214,13 +208,9 @@ public class SceneDirector
_scene = _dsfact.createScene(_model, config);
}
/**
* Called in response to a successful <code>moveTo</code> request when
* our cached scene was out of date and the server determined that we
* needed an updated copy.
*/
public void handleMoveSucceededPlusUpdate (
int invid, int placeId, PlaceConfig config, SceneModel model)
// documentation inherited from interface
public void moveSucceededPlusUpdate (
int placeId, PlaceConfig config, SceneModel model)
{
// update the model in the repository
try {
@@ -237,13 +227,11 @@ public class SceneDirector
_scache.put(model.sceneId, model);
// and pass through to the normal move succeeded handler
handleMoveSucceeded(invid, placeId, config);
moveSucceeded(placeId, config);
}
/**
* 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 sceneId = _pendingSceneId;
@@ -266,13 +254,8 @@ public class SceneDirector
clearScene();
}
/**
* Called when the server has decided to forcibly move us to another
* scene. The server first ejects us from our previous scene and then
* sends us a notification with our new location. We then turn around
* and issue a standard moveTo request.
*/
public void handleMoveNotification (int sceneId)
// documentation inherited from interface
public void forcedMove (int sceneId)
{
Log.info("Moving at request of server [sceneId=" + sceneId + "].");
@@ -361,20 +344,26 @@ public class SceneDirector
}
// documentation inherited from interface
public void clientDidLogon (Client client)
public void clientDidLogoff (Client client)
{
// nothing for now
super.clientDidLogoff(client);
clearScene();
}
// documentation inherited from interface
public void clientDidLogoff (Client client)
protected void fetchServices (Client client)
{
clearScene();
// get a handle on our scene service
_sservice = (SceneService)client.requireService(SceneService.class);
}
/** Access to general client services. */
protected WhirledContext _ctx;
/** Access to our scene services. */
protected SceneService _sservice;
/** The client's active location director. */
protected LocationDirector _locdir;
@@ -0,0 +1,21 @@
//
// $Id: SceneReceiver.java,v 1.1 2002/08/14 19:07:57 mdb Exp $
package com.threerings.whirled.client;
import com.threerings.presents.client.InvocationReceiver;
/**
* Defines, for the scene services, a set of notifications delivered
* asynchronously by the server to the client.
*/
public interface SceneReceiver extends InvocationReceiver
{
/**
* Used to communicate a required move notification to the client. The
* server will have removed the client from their existing scene
* and the client is then responsible for generating a {@link
* SceneService#moveTo} request to move to the new scene.
*/
public void forcedMove (int sceneId);
}
@@ -1,20 +1,46 @@
//
// $Id: SceneService.java,v 1.8 2002/05/15 23:54:34 mdb Exp $
// $Id: SceneService.java,v 1.9 2002/08/14 19:07:57 mdb Exp $
package com.threerings.whirled.client;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationDirector;
import com.threerings.presents.client.InvocationService;
import com.threerings.whirled.Log;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.data.SceneModel;
/**
* The scene service class provides the client interface to the scene
* related invocation services (e.g. moving from scene to scene).
*/
public class SceneService implements SceneCodes
public interface SceneService extends InvocationService
{
/**
* Used to communicate the response to a {@link #moveTo} request.
*/
public static interface SceneMoveListener extends InvocationListener
{
/**
* Indicates that a move succeeded.
*
* @param placeId the place object id of the newly occupied scene.
* @param config metadata related to the newly occupied scene.
*/
public void moveSucceeded (int placeId, PlaceConfig config);
/**
* Indicates that a move succeeded and that the client's cached
* scene information should be updated with the supplied data.
*
* @param placeId the place object id of the newly occupied scene.
* @param config metadata related to the newly occupied scene.
* @param model the most recent scene data for the newly occupied
* scene.
*/
public void moveSucceededPlusUpdate (
int placeId, PlaceConfig config, SceneModel model);
}
/**
* Requests that that this client's body be moved to the specified
* scene.
@@ -23,14 +49,6 @@ public class SceneService implements SceneCodes
* @param sceneVers the version number of the scene object that we
* have in our local repository.
*/
public static void moveTo (Client client, int sceneId,
int sceneVers, Object rsptarget)
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[] {
new Integer(sceneId), new Integer(sceneVers) };
invdir.invoke(MODULE_NAME, MOVE_TO_REQUEST, args, rsptarget);
Log.debug("Sent moveTo request [scene=" + sceneId +
", version=" + sceneVers + "].");
}
public void moveTo (Client client, int sceneId,
int sceneVers, SceneMoveListener listener);
}