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: ZoneDecoder.java,v 1.1 2002/08/14 19:07:58 mdb Exp $
package com.threerings.whirled.zone.client;
import com.threerings.presents.client.InvocationDecoder;
import com.threerings.whirled.zone.client.ZoneReceiver;
/**
* Dispatches calls to a {@link ZoneReceiver} instance.
*/
public class ZoneDecoder extends InvocationDecoder
{
/** The generated hash code used to identify this receiver class. */
public static final String RECEIVER_CODE = "2d900cf54355111b4bb4befcdff42b82";
/** The method id used to dispatch {@link ZoneReceiver#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 ZoneDecoder (ZoneReceiver 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:
((ZoneReceiver)receiver).forcedMove(
((Integer)args[0]).intValue(), ((Integer)args[1]).intValue()
);
return;
default:
super.dispatchNotification(methodId, args);
}
}
// Generated on 11:25:47 08/12/02.
}
@@ -1,5 +1,5 @@
//
// $Id: ZoneDirector.java,v 1.8 2002/06/14 01:40:16 ray Exp $
// $Id: ZoneDirector.java,v 1.9 2002/08/14 19:07:58 mdb Exp $
package com.threerings.whirled.zone.client;
@@ -7,7 +7,9 @@ import java.util.ArrayList;
import com.samskivert.util.ResultListener;
import com.threerings.presents.client.InvocationReceiver;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.client.SceneDirector;
@@ -15,7 +17,6 @@ import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.util.WhirledContext;
import com.threerings.whirled.zone.Log;
import com.threerings.whirled.zone.data.ZoneCodes;
import com.threerings.whirled.zone.data.ZoneSummary;
/**
@@ -27,8 +28,8 @@ import com.threerings.whirled.zone.data.ZoneSummary;
* summary which provides information on the zone which can be used to
* generate an overview map or similar.
*/
public class ZoneDirector
implements InvocationReceiver, ZoneCodes
public class ZoneDirector extends BasicDirector
implements ZoneReceiver, ZoneService.ZoneMoveListener
{
/**
* Constructs a zone director with the supplied context, and delegate
@@ -38,12 +39,13 @@ public class ZoneDirector
*/
public ZoneDirector (WhirledContext ctx, SceneDirector scdir)
{
super(ctx);
_ctx = ctx;
_scdir = scdir;
// register for zone notifications
_ctx.getClient().getInvocationDirector().registerReceiver(
MODULE_NAME, this);
new ZoneDecoder(this));
}
/**
@@ -116,41 +118,46 @@ public class ZoneDirector
}
// issue a moveTo request
ZoneService.moveTo(_ctx.getClient(), zoneId, sceneId, sceneVers, this);
_zservice.moveTo(_ctx.getClient(), zoneId, sceneId, sceneVers, this);
return true;
}
// documentation inherited
protected void fetchServices (Client client)
{
_zservice = (ZoneService)client.requireService(ZoneService.class);
}
/**
* Called in response to a successful zoned <code>moveTo</code>
* Called in response to a successful {@link ZoneService#moveTo}
* request.
*/
public void handleMoveSucceeded (
int invid, int placeId, PlaceConfig config, ZoneSummary summary)
public void moveSucceeded (
int placeId, PlaceConfig config, ZoneSummary summary)
{
// keep track of the summary
_summary = summary;
// pass the rest off to the standard scene transition code
_scdir.handleMoveSucceeded(invid, placeId, config);
_scdir.moveSucceeded(placeId, config);
// and let the zone observers know what's up
notifyObservers(summary);
}
/**
* Called in response to a successful zoned <code>moveTo</code>
* Called in response to a successful {@link ZoneService#moveTo}
* 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, ZoneSummary summary,
SceneModel model)
public void moveSucceededPlusUpdate (
int placeId, PlaceConfig config, ZoneSummary summary, SceneModel model)
{
// keep track of the summary
_summary = summary;
// pass the rest off to the standard scene transition code
_scdir.handleMoveSucceededPlusUpdate(invid, placeId, config, model);
_scdir.moveSucceededPlusUpdate(placeId, config, model);
// and let the zone observers know what's up
notifyObservers(summary);
@@ -159,22 +166,17 @@ public class ZoneDirector
/**
* Called in response to a failed zoned <code>moveTo</code> request.
*/
public void handleMoveFailed (int invid, String reason)
public void requestFailed (String reason)
{
// let the scene director cope
_scdir.handleMoveFailed(invid, reason);
_scdir.requestFailed(reason);
// and let the observers know what's up
notifyObservers(reason);
}
/**
* Called when the server has decided to forcibly move us to another
* zone and 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 zoneId, int sceneId)
// documentation inherited from interface
public void forcedMove (int zoneId, int sceneId)
{
Log.info("Moving at request of server [zoneId=" + zoneId +
", sceneId=" + sceneId + "].");
@@ -218,6 +220,9 @@ public class ZoneDirector
/** A reference to the scene director with which we coordinate. */
protected SceneDirector _scdir;
/** Provides access to zone services. */
protected ZoneService _zservice;
/** A reference to the zone summary for the currently occupied
* zone. */
protected ZoneSummary _summary;
@@ -0,0 +1,22 @@
//
// $Id: ZoneReceiver.java,v 1.1 2002/08/14 19:07:58 mdb Exp $
package com.threerings.whirled.zone.client;
import com.threerings.presents.client.InvocationReceiver;
/**
* Defines, for the zone services, a set of notifications delivered
* asynchronously by the server to the client.
*/
public interface ZoneReceiver 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
* ZoneService#moveTo} request to move to the new scene in the
* specified zone.
*/
public void forcedMove (int zoneId, int sceneId);
}
@@ -1,20 +1,32 @@
//
// $Id: ZoneService.java,v 1.5 2002/05/15 23:54:35 mdb Exp $
// $Id: ZoneService.java,v 1.6 2002/08/14 19:07:58 mdb Exp $
package com.threerings.whirled.zone.client;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationDirector;
import com.threerings.presents.client.InvocationService;
import com.threerings.whirled.zone.Log;
import com.threerings.whirled.zone.data.ZoneCodes;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.zone.data.ZoneSummary;
/**
* The zone service class provides the client interface to the zone
* related invocation services (e.g. moving between zones).
* Defines the client interface to the zone related invocation services
* (e.g. moving between zones).
*/
public class ZoneService implements ZoneCodes
public interface ZoneService extends InvocationService
{
public static interface ZoneMoveListener extends InvocationListener
{
public void moveSucceeded (
int placeId, PlaceConfig config, ZoneSummary summary);
public void moveSucceededPlusUpdate (
int placeId, PlaceConfig config, ZoneSummary summary,
SceneModel model);
}
/**
* Requests that that this client's body be moved to the specified
* scene in the specified zone.
@@ -23,17 +35,9 @@ public class ZoneService implements ZoneCodes
* @param sceneId the scene id to which we want to move.
* @param sceneVers the version number of the scene object that we
* have in our local repository.
* @param rsptarget the object that will receive the callback when the
* @param listener the object that will receive the callback when the
* request succeeds or fails.
*/
public static void moveTo (Client client, int zoneId, int sceneId,
int sceneVers, Object rsptarget)
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[] {
new Integer(zoneId), new Integer(sceneId), new Integer(sceneVers) };
invdir.invoke(MODULE_NAME, MOVE_TO_REQUEST, args, rsptarget);
Log.debug("Sent moveTo request [zone=" + zoneId +
", scene=" + sceneId + ", version=" + sceneVers + "].");
}
public void moveTo (Client client, int zoneId, int sceneId,
int sceneVers, ZoneMoveListener listener);
}