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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ZoneCodes.java,v 1.1 2002/04/15 16:28:04 shaper Exp $
|
||||
// $Id: ZoneCodes.java,v 1.2 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.zone.data;
|
||||
|
||||
@@ -10,9 +10,6 @@ import com.threerings.whirled.data.SceneCodes;
|
||||
*/
|
||||
public interface ZoneCodes extends SceneCodes
|
||||
{
|
||||
/** The module name for the zone services. */
|
||||
public static final String MODULE_NAME = "whirled!zone";
|
||||
|
||||
/** An error code indicating that a zone identified by a particular
|
||||
* zone id does not exist. Usually generated by a failed moveTo
|
||||
* request. */
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// $Id: ZoneMarshaller.java,v 1.1 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.zone.data;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.zone.client.ZoneService;
|
||||
import com.threerings.whirled.zone.client.ZoneService.ZoneMoveListener;
|
||||
import com.threerings.whirled.zone.data.ZoneSummary;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link ZoneService} interface
|
||||
* that marshalls the arguments and delivers the request to the provider
|
||||
* on the server. Also provides an implementation of the response listener
|
||||
* interfaces that marshall the response arguments and deliver them back
|
||||
* to the requesting client.
|
||||
*/
|
||||
public class ZoneMarshaller extends InvocationMarshaller
|
||||
implements ZoneService
|
||||
{
|
||||
// documentation inherited
|
||||
public static class ZoneMoveMarshaller extends ListenerMarshaller
|
||||
implements ZoneMoveListener
|
||||
{
|
||||
/** The method id used to dispatch {@link #moveSucceeded}
|
||||
* responses. */
|
||||
public static final int MOVE_SUCCEEDED = 0;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void moveSucceeded (int arg1, PlaceConfig arg2, ZoneSummary arg3)
|
||||
{
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, MOVE_SUCCEEDED,
|
||||
new Object[] { new Integer(arg1), arg2, arg3 }));
|
||||
}
|
||||
/** The method id used to dispatch {@link #moveSucceededPlusUpdate}
|
||||
* responses. */
|
||||
public static final int MOVE_SUCCEEDED_PLUS_UPDATE = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void moveSucceededPlusUpdate (int arg1, PlaceConfig arg2, ZoneSummary arg3, SceneModel arg4)
|
||||
{
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, MOVE_SUCCEEDED_PLUS_UPDATE,
|
||||
new Object[] { new Integer(arg1), arg2, arg3, arg4 }));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchResponse (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case MOVE_SUCCEEDED:
|
||||
((ZoneMoveListener)listener).moveSucceeded(
|
||||
((Integer)args[0]).intValue(), (PlaceConfig)args[1], (ZoneSummary)args[2]);
|
||||
return;
|
||||
|
||||
case MOVE_SUCCEEDED_PLUS_UPDATE:
|
||||
((ZoneMoveListener)listener).moveSucceededPlusUpdate(
|
||||
((Integer)args[0]).intValue(), (PlaceConfig)args[1], (ZoneSummary)args[2], (SceneModel)args[3]);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #moveTo} requests. */
|
||||
public static final int MOVE_TO = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void moveTo (Client arg1, int arg2, int arg3, int arg4, ZoneMoveListener arg5)
|
||||
{
|
||||
ZoneMoveMarshaller listener5 = new ZoneMoveMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, MOVE_TO, new Object[] {
|
||||
new Integer(arg2), new Integer(arg3), new Integer(arg4), listener5
|
||||
});
|
||||
}
|
||||
|
||||
// Class file generated on 00:26:02 08/11/02.
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// $Id: ZoneDispatcher.java,v 1.1 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.zone.server;
|
||||
|
||||
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;
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.zone.client.ZoneService;
|
||||
import com.threerings.whirled.zone.client.ZoneService.ZoneMoveListener;
|
||||
import com.threerings.whirled.zone.data.ZoneMarshaller;
|
||||
import com.threerings.whirled.zone.data.ZoneSummary;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link ZoneProvider}.
|
||||
*/
|
||||
public class ZoneDispatcher extends InvocationDispatcher
|
||||
{
|
||||
/**
|
||||
* Creates a dispatcher that may be registered to dispatch invocation
|
||||
* service requests for the specified provider.
|
||||
*/
|
||||
public ZoneDispatcher (ZoneProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public InvocationMarshaller createMarshaller ()
|
||||
{
|
||||
return new ZoneMarshaller();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchRequest (
|
||||
ClientObject source, int methodId, Object[] args)
|
||||
throws InvocationException
|
||||
{
|
||||
switch (methodId) {
|
||||
case ZoneMarshaller.MOVE_TO:
|
||||
((ZoneProvider)provider).moveTo(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), ((Integer)args[2]).intValue(), (ZoneMoveListener)args[3]
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
//
|
||||
// $Id: ZoneProvider.java,v 1.9 2002/05/26 02:29:13 mdb Exp $
|
||||
// $Id: ZoneProvider.java,v 1.10 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.zone.server;
|
||||
|
||||
import com.threerings.presents.server.InvocationManager;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.presents.server.InvocationProvider;
|
||||
import com.threerings.presents.server.ServiceFailedException;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
@@ -17,6 +17,7 @@ import com.threerings.whirled.server.SceneRegistry;
|
||||
import com.threerings.whirled.server.SceneManager;
|
||||
|
||||
import com.threerings.whirled.zone.Log;
|
||||
import com.threerings.whirled.zone.client.ZoneService.ZoneMoveListener;
|
||||
import com.threerings.whirled.zone.data.ZoneCodes;
|
||||
import com.threerings.whirled.zone.data.ZoneSummary;
|
||||
import com.threerings.whirled.zone.data.ZonedBodyObject;
|
||||
@@ -26,7 +27,7 @@ import com.threerings.whirled.zone.data.ZonedBodyObject;
|
||||
* from zone to zone.
|
||||
*/
|
||||
public class ZoneProvider
|
||||
extends InvocationProvider implements ZoneCodes
|
||||
implements ZoneCodes, InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Constructs a zone provider that will interoperate with the supplied
|
||||
@@ -34,10 +35,10 @@ public class ZoneProvider
|
||||
* constructed and registered by the {@link ZoneRegistry}, which a
|
||||
* zone-using system must create and initialize in their server.
|
||||
*/
|
||||
public ZoneProvider (
|
||||
InvocationManager invmgr, ZoneRegistry zonereg, SceneRegistry screg)
|
||||
public ZoneProvider (LocationProvider locprov, ZoneRegistry zonereg,
|
||||
SceneRegistry screg)
|
||||
{
|
||||
_invmgr = invmgr;
|
||||
_locprov = locprov;
|
||||
_zonereg = zonereg;
|
||||
_screg = screg;
|
||||
}
|
||||
@@ -45,45 +46,45 @@ public class ZoneProvider
|
||||
/**
|
||||
* Processes a request from a client to move to a scene in a new zone.
|
||||
*
|
||||
* @param source the user requesting the move.
|
||||
* @param caller the user requesting the move.
|
||||
* @param invid the invocation id of the request.
|
||||
* @param zoneId the qualified zone id of the new zone.
|
||||
* @param sceneId the identifier of the new scene.
|
||||
* @param sceneVew the version of the scene model currently held by
|
||||
* @param sceneVer the version of the scene model currently held by
|
||||
* the client.
|
||||
* @param listener the entity to inform of success or failure.
|
||||
*/
|
||||
public void handleMoveToRequest (BodyObject source, int invid,
|
||||
int zoneId, int sceneId, int sceneVer)
|
||||
public void moveTo (ClientObject caller, int zoneId, int sceneId,
|
||||
int sceneVer, ZoneMoveListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// avoid cluttering up the method declaration with final keywords
|
||||
final BodyObject fsource = (BodyObject)caller;
|
||||
final int fsceneId = sceneId;
|
||||
final int fsceneVer = sceneVer;
|
||||
final ZoneMoveListener flistener = listener;
|
||||
|
||||
// look up the zone manager for the zone
|
||||
ZoneManager zmgr = _zonereg.getZoneManager(zoneId);
|
||||
if (zmgr == null) {
|
||||
Log.warning("Requested to enter a zone for which we have no " +
|
||||
"manager [user=" + source +
|
||||
"manager [user=" + fsource.who() +
|
||||
", zoneId=" + zoneId + "].");
|
||||
sendResponse(source, invid, MOVE_FAILED_RESPONSE, NO_SUCH_ZONE);
|
||||
return;
|
||||
throw new InvocationException(NO_SUCH_ZONE);
|
||||
}
|
||||
|
||||
// avoid cluttering up the method declaration with final keywords
|
||||
final BodyObject fsource = source;
|
||||
final int finvid = invid;
|
||||
final int fsceneId = sceneId;
|
||||
final int fsceneVer = sceneVer;
|
||||
|
||||
// resolve the zone!
|
||||
ZoneManager.ResolutionListener zl = new ZoneManager.ResolutionListener()
|
||||
{
|
||||
public void zoneWasResolved (ZoneSummary summary) {
|
||||
continueMoveToRequest(fsource, finvid, summary,
|
||||
fsceneId, fsceneVer);
|
||||
continueMoveTo(
|
||||
fsource, summary, fsceneId, fsceneVer, flistener);
|
||||
}
|
||||
|
||||
public void zoneFailedToResolve (int zoneId, Exception reason) {
|
||||
Log.warning("Unable to resolve zone [zoneId=" + zoneId +
|
||||
", reason=" + reason + "].");
|
||||
sendResponse(fsource, finvid,
|
||||
MOVE_FAILED_RESPONSE, NO_SUCH_ZONE);
|
||||
flistener.requestFailed(NO_SUCH_ZONE);
|
||||
}
|
||||
};
|
||||
zmgr.resolveZone(zoneId, zl);
|
||||
@@ -92,21 +93,21 @@ public class ZoneProvider
|
||||
/**
|
||||
* This is called after we have resolved our zone.
|
||||
*/
|
||||
protected void continueMoveToRequest (
|
||||
BodyObject source, int invid, ZoneSummary summary,
|
||||
int sceneId, int sceneVer)
|
||||
protected void continueMoveTo (
|
||||
BodyObject source, ZoneSummary summary, int sceneId, int sceneVer,
|
||||
ZoneMoveListener listener)
|
||||
{
|
||||
// avoid cluttering up the method declaration with final keywords
|
||||
final BodyObject fsource = source;
|
||||
final int finvid = invid;
|
||||
final ZoneSummary fsum = summary;
|
||||
final int fsceneVer = sceneVer;
|
||||
final ZoneMoveListener flistener = listener;
|
||||
|
||||
// give the zone manager a chance to veto the request
|
||||
ZoneManager zmgr = _zonereg.getZoneManager(summary.zoneId);
|
||||
String errmsg = zmgr.ratifyBodyEntry(source, summary.zoneId);
|
||||
if (errmsg != null) {
|
||||
sendResponse(fsource, finvid, MOVE_FAILED_RESPONSE, errmsg);
|
||||
listener.requestFailed(errmsg);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -116,15 +117,14 @@ public class ZoneProvider
|
||||
new SceneRegistry.ResolutionListener()
|
||||
{
|
||||
public void sceneWasResolved (SceneManager scmgr) {
|
||||
finishMoveToRequest(fsource, finvid, fsum, scmgr, fsceneVer);
|
||||
finishMoveTo(fsource, fsum, scmgr, fsceneVer, flistener);
|
||||
}
|
||||
|
||||
public void sceneFailedToResolve (int sceneId, Exception reason) {
|
||||
Log.warning("Unable to resolve scene [sceneid=" + sceneId +
|
||||
", reason=" + reason + "].");
|
||||
// pretend like the scene doesn't exist to the client
|
||||
sendResponse(fsource, finvid,
|
||||
MOVE_FAILED_RESPONSE, NO_SUCH_PLACE);
|
||||
flistener.requestFailed(NO_SUCH_PLACE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,9 +137,9 @@ public class ZoneProvider
|
||||
* This is called after the scene to which we are moving is guaranteed
|
||||
* to have been loaded into the server.
|
||||
*/
|
||||
protected void finishMoveToRequest (
|
||||
BodyObject source, int invid, ZoneSummary summary,
|
||||
SceneManager scmgr, int sceneVersion)
|
||||
protected void finishMoveTo (
|
||||
BodyObject source, ZoneSummary summary, SceneManager scmgr,
|
||||
int sceneVersion, ZoneMoveListener listener)
|
||||
{
|
||||
// move to the place object associated with this scene
|
||||
PlaceObject plobj = scmgr.getPlaceObject();
|
||||
@@ -147,7 +147,7 @@ public class ZoneProvider
|
||||
|
||||
try {
|
||||
// try doing the actual move
|
||||
PlaceConfig config = LocationProvider.moveTo(source, ploid);
|
||||
PlaceConfig config = _locprov.moveTo(source, ploid);
|
||||
|
||||
// now that we've finally moved, we can update the user object
|
||||
// with the new zone id
|
||||
@@ -157,23 +157,19 @@ public class ZoneProvider
|
||||
SceneModel model = scmgr.getSceneModel();
|
||||
if (sceneVersion < model.version) {
|
||||
// then send the moveTo response
|
||||
sendResponse(source, invid, MOVE_SUCCEEDED_PLUS_UPDATE_RESPONSE,
|
||||
new Object[] { new Integer(ploid), config,
|
||||
summary, model });
|
||||
listener.moveSucceededPlusUpdate(ploid, config, summary, model);
|
||||
|
||||
} else {
|
||||
// then send the moveTo response
|
||||
sendResponse(source, invid, MOVE_SUCCEEDED_RESPONSE,
|
||||
new Integer(ploid), config, summary);
|
||||
listener.moveSucceeded(ploid, config, summary);
|
||||
}
|
||||
|
||||
// let the zone manager know that someone just came on in
|
||||
ZoneManager zmgr = _zonereg.getZoneManager(summary.zoneId);
|
||||
zmgr.bodyDidEnterZone(source, summary.zoneId);
|
||||
|
||||
} catch (ServiceFailedException sfe) {
|
||||
sendResponse(source, invid,
|
||||
MOVE_FAILED_RESPONSE, sfe.getMessage());
|
||||
} catch (InvocationException ie) {
|
||||
listener.requestFailed(ie.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,23 +178,21 @@ public class ZoneProvider
|
||||
* request to move to the specified new zone and scene. This is the
|
||||
* zone-equivalent to {@link LocationProvider#moveBody}.
|
||||
*/
|
||||
public static void moveBody (BodyObject source, int zoneId, int sceneId)
|
||||
public void moveBody (BodyObject source, int zoneId, int sceneId)
|
||||
{
|
||||
// first remove them from their old place
|
||||
LocationProvider.leaveOccupiedPlace(source);
|
||||
_locprov.leaveOccupiedPlace(source);
|
||||
|
||||
// then send a move notification
|
||||
_invmgr.sendNotification(
|
||||
source.getOid(), MODULE_NAME, MOVE_NOTIFICATION,
|
||||
new Object[] { new Integer(zoneId), new Integer(sceneId) });
|
||||
// then send a forced move notification
|
||||
ZoneSender.forcedMove(source, zoneId, sceneId);
|
||||
}
|
||||
|
||||
/** The invocation manager with which we interact. */
|
||||
protected static InvocationManager _invmgr;
|
||||
/** The entity that handles basic location changes. */
|
||||
protected LocationProvider _locprov;
|
||||
|
||||
/** The zone registry with which we communicate. */
|
||||
protected static ZoneRegistry _zonereg;
|
||||
protected ZoneRegistry _zonereg;
|
||||
|
||||
/** The scene registry with which we communicate. */
|
||||
protected static SceneRegistry _screg;
|
||||
protected SceneRegistry _screg;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
//
|
||||
// $Id: ZoneRegistry.java,v 1.7 2002/05/26 02:24:46 mdb Exp $
|
||||
// $Id: ZoneRegistry.java,v 1.8 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.zone.server;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.presents.server.InvocationManager;
|
||||
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
import com.threerings.whirled.server.SceneRegistry;
|
||||
|
||||
import com.threerings.whirled.zone.Log;
|
||||
@@ -17,15 +19,19 @@ import com.threerings.whirled.zone.util.ZoneUtil;
|
||||
*/
|
||||
public class ZoneRegistry
|
||||
{
|
||||
/** Implements the server-side of the zone-related services. */
|
||||
public ZoneProvider zoneprov;
|
||||
|
||||
/**
|
||||
* Creates a zone manager with the supplied configuration.
|
||||
*/
|
||||
public ZoneRegistry (InvocationManager invmgr, SceneRegistry screg)
|
||||
public ZoneRegistry (InvocationManager invmgr, PlaceRegistry plreg,
|
||||
SceneRegistry screg)
|
||||
{
|
||||
// create a zone provider and register it with the invocation
|
||||
// services
|
||||
ZoneProvider provider = new ZoneProvider(invmgr, this, screg);
|
||||
invmgr.registerProvider(ZoneProvider.MODULE_NAME, provider);
|
||||
zoneprov = new ZoneProvider(plreg.locprov, this, screg);
|
||||
invmgr.registerDispatcher(new ZoneDispatcher(zoneprov), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// $Id: ZoneSender.java,v 1.1 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.zone.server;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationSender;
|
||||
import com.threerings.whirled.zone.client.ZoneDecoder;
|
||||
import com.threerings.whirled.zone.client.ZoneReceiver;
|
||||
|
||||
/**
|
||||
* Used to issue notifications to a {@link ZoneReceiver} instance on a
|
||||
* client.
|
||||
*/
|
||||
public class ZoneSender extends InvocationSender
|
||||
{
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* ZoneReceiver#forcedMove} on a client.
|
||||
*/
|
||||
public static void forcedMove (
|
||||
ClientObject target, int arg1, int arg2)
|
||||
{
|
||||
sendNotification(
|
||||
target, ZoneDecoder.RECEIVER_CODE, ZoneDecoder.FORCED_MOVE,
|
||||
new Object[] { new Integer(arg1), new Integer(arg2) });
|
||||
}
|
||||
|
||||
// Generated on 11:25:47 08/12/02.
|
||||
}
|
||||
Reference in New Issue
Block a user