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:
@@ -1,123 +1,117 @@
|
||||
//
|
||||
// $Id: SpotProvider.java,v 1.12 2002/07/22 22:54:04 ray Exp $
|
||||
// $Id: SpotProvider.java,v 1.13 2002/08/14 19:07:58 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.spot.server;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.dobj.RootDObjectManager;
|
||||
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.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.LocationProvider;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.whirled.client.SceneService.SceneMoveListener;
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.server.SceneManager;
|
||||
import com.threerings.whirled.server.SceneRegistry;
|
||||
|
||||
import com.threerings.whirled.spot.Log;
|
||||
import com.threerings.whirled.spot.client.SpotService.ChangeLocListener;
|
||||
import com.threerings.whirled.spot.data.SpotCodes;
|
||||
import com.threerings.whirled.spot.data.SpotOccupantInfo;
|
||||
|
||||
/**
|
||||
* This class provides the server side of the spot services.
|
||||
* Provides the server-side implementation of the spot services.
|
||||
*/
|
||||
public class SpotProvider extends InvocationProvider
|
||||
implements SpotCodes
|
||||
public class SpotProvider
|
||||
implements SpotCodes, InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Constructs a spot provider and registers it with the invocation
|
||||
* manager to handle spot services. This need be done by a server that
|
||||
* wishes to make use of the Spot services.
|
||||
* Creates a spot provider that can be registered with the invocation
|
||||
* manager to handle spot services.
|
||||
*/
|
||||
public static void init (
|
||||
InvocationManager invmgr, SceneRegistry screg, RootDObjectManager omgr)
|
||||
public SpotProvider (RootDObjectManager omgr, PlaceRegistry plreg,
|
||||
SceneRegistry screg)
|
||||
{
|
||||
// we'll need these later
|
||||
_plreg = plreg;
|
||||
_screg = screg;
|
||||
_omgr = omgr;
|
||||
|
||||
// register a spot provider instance
|
||||
invmgr.registerProvider(MODULE_NAME, new SpotProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from a client to traverse a portal.
|
||||
*
|
||||
* @param source the body object of the client making the request.
|
||||
* @param invid the invocation service invocation id.
|
||||
* @param sceneId the source scene id.
|
||||
* @param portalId the portal in the source scene that is being
|
||||
* traversed.
|
||||
* @param sceneVer the version of the destination scene data that the
|
||||
* client has cached.
|
||||
* @param listener the entity to which we communicate our response.
|
||||
*/
|
||||
public void handleTraversePortalRequest (
|
||||
BodyObject source, int invid, int sceneId, int portalId, int sceneVer)
|
||||
public void traversePortal (ClientObject caller, int sceneId, int portalId,
|
||||
int sceneVer, SceneMoveListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
try {
|
||||
// obtain the source scene
|
||||
SpotSceneManager smgr = (SpotSceneManager)
|
||||
_screg.getSceneManager(sceneId);
|
||||
if (smgr == null) {
|
||||
Log.warning("Traverse portal missing source scene " +
|
||||
"[user=" + source.who() + ", sceneId=" + sceneId +
|
||||
", portalId=" + portalId + "].");
|
||||
throw new ServiceFailedException(INTERNAL_ERROR);
|
||||
}
|
||||
// avoid cluttering up the method declaration with final keywords
|
||||
final BodyObject fsource = (BodyObject)caller;
|
||||
final int fportalId = portalId;
|
||||
final int fsceneVer = sceneVer;
|
||||
final SceneMoveListener flistener = listener;
|
||||
|
||||
// obtain the destination scene and location id
|
||||
RuntimeSpotScene rss = (RuntimeSpotScene)smgr.getScene();
|
||||
int destSceneId = rss.getTargetSceneId(portalId);
|
||||
final int destLocId = rss.getTargetLocationId(portalId);
|
||||
|
||||
// make sure this portal has valid info
|
||||
if (destSceneId == -1) {
|
||||
Log.warning("Traverse portal provided with invalid portal " +
|
||||
"[user=" + source.who() + ", sceneId=" + sceneId +
|
||||
", portalId=" + portalId +
|
||||
", destSceneId=" + destSceneId + "].");
|
||||
throw new ServiceFailedException(NO_SUCH_PORTAL);
|
||||
}
|
||||
|
||||
// avoid cluttering up the method declaration with final
|
||||
// keywords
|
||||
final BodyObject fsource = source;
|
||||
final int finvid = invid;
|
||||
final int fportalId = portalId;
|
||||
final int fsceneVer = sceneVer;
|
||||
|
||||
// create a callback object that will handle the resolution or
|
||||
// failed resolution of the scene
|
||||
SceneRegistry.ResolutionListener rl =
|
||||
new SceneRegistry.ResolutionListener() {
|
||||
public void sceneWasResolved (SceneManager scmgr) {
|
||||
SpotSceneManager sscmgr = (SpotSceneManager)scmgr;
|
||||
finishTraversePortalRequest(
|
||||
fsource, finvid, sscmgr, fsceneVer,
|
||||
fportalId, destLocId);
|
||||
}
|
||||
|
||||
public void sceneFailedToResolve (
|
||||
int rsceneId, Exception reason) {
|
||||
Log.warning("Unable to resolve target scene " +
|
||||
"[sceneId=" + rsceneId +
|
||||
", reason=" + reason + "].");
|
||||
// pretend like the scene doesn't exist to the client
|
||||
sendResponse(fsource, finvid, MOVE_FAILED_RESPONSE,
|
||||
NO_SUCH_PLACE);
|
||||
}
|
||||
};
|
||||
|
||||
// make sure the scene they are headed to is actually loaded into
|
||||
// the server
|
||||
_screg.resolveScene(destSceneId, rl);
|
||||
|
||||
} catch (ServiceFailedException sfe) {
|
||||
sendResponse(source, invid, MOVE_FAILED_RESPONSE, sfe.getMessage());
|
||||
// obtain the source scene
|
||||
SpotSceneManager smgr = (SpotSceneManager)
|
||||
_screg.getSceneManager(sceneId);
|
||||
if (smgr == null) {
|
||||
Log.warning("Traverse portal missing source scene " +
|
||||
"[user=" + fsource.who() + ", sceneId=" + sceneId +
|
||||
", portalId=" + portalId + "].");
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
// obtain the destination scene and location id
|
||||
RuntimeSpotScene rss = (RuntimeSpotScene)smgr.getScene();
|
||||
int destSceneId = rss.getTargetSceneId(portalId);
|
||||
final int destLocId = rss.getTargetLocationId(portalId);
|
||||
|
||||
// make sure this portal has valid info
|
||||
if (destSceneId == -1) {
|
||||
Log.warning("Traverse portal provided with invalid portal " +
|
||||
"[user=" + fsource.who() + ", sceneId=" + sceneId +
|
||||
", portalId=" + portalId +
|
||||
", destSceneId=" + destSceneId + "].");
|
||||
throw new InvocationException(NO_SUCH_PORTAL);
|
||||
}
|
||||
|
||||
// create a callback object that will handle the resolution or
|
||||
// failed resolution of the scene
|
||||
SceneRegistry.ResolutionListener rl =
|
||||
new SceneRegistry.ResolutionListener() {
|
||||
public void sceneWasResolved (SceneManager scmgr) {
|
||||
SpotSceneManager sscmgr = (SpotSceneManager)scmgr;
|
||||
finishTraversePortalRequest(
|
||||
fsource, sscmgr, fsceneVer, fportalId, destLocId,
|
||||
flistener);
|
||||
}
|
||||
|
||||
public void sceneFailedToResolve (
|
||||
int rsceneId, Exception reason) {
|
||||
Log.warning("Unable to resolve target scene " +
|
||||
"[sceneId=" + rsceneId +
|
||||
", reason=" + reason + "].");
|
||||
// pretend like the scene doesn't exist to the client
|
||||
flistener.requestFailed(NO_SUCH_PLACE);
|
||||
}
|
||||
};
|
||||
|
||||
// make sure the scene they are headed to is actually loaded into
|
||||
// the server
|
||||
_screg.resolveScene(destSceneId, rl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,8 +119,8 @@ public class SpotProvider extends InvocationProvider
|
||||
* to have been loaded into the server.
|
||||
*/
|
||||
protected void finishTraversePortalRequest (
|
||||
BodyObject source, int invid, SpotSceneManager scmgr,
|
||||
int sceneVer, int exitPortalId, int destLocId)
|
||||
BodyObject source, SpotSceneManager scmgr, int sceneVer,
|
||||
int exitPortalId, int destLocId, SceneMoveListener listener)
|
||||
{
|
||||
// move to the place object associated with this scene
|
||||
PlaceObject plobj = scmgr.getPlaceObject();
|
||||
@@ -138,23 +132,21 @@ public class SpotProvider extends InvocationProvider
|
||||
|
||||
try {
|
||||
// try doing the actual move
|
||||
PlaceConfig config = LocationProvider.moveTo(source, ploid);
|
||||
PlaceConfig config = _plreg.locprov.moveTo(source, ploid);
|
||||
|
||||
// check to see if they need a newer version of the scene data
|
||||
SceneModel model = scmgr.getSceneModel();
|
||||
if (sceneVer < model.version) {
|
||||
// then send the moveTo response
|
||||
sendResponse(source, invid, MOVE_SUCCEEDED_PLUS_UPDATE_RESPONSE,
|
||||
new Integer(ploid), config, model);
|
||||
listener.moveSucceededPlusUpdate(ploid, config, model);
|
||||
|
||||
} else {
|
||||
// then send the moveTo response
|
||||
sendResponse(source, invid, MOVE_SUCCEEDED_RESPONSE,
|
||||
new Integer(ploid), config);
|
||||
listener.moveSucceeded(ploid, config);
|
||||
}
|
||||
|
||||
} catch (ServiceFailedException sfe) {
|
||||
sendResponse(source, invid, MOVE_FAILED_RESPONSE, sfe.getMessage());
|
||||
} catch (InvocationException sfe) {
|
||||
listener.requestFailed(sfe.getMessage());
|
||||
|
||||
// and let the destination scene manager know that we're no
|
||||
// longer coming in
|
||||
@@ -165,39 +157,35 @@ public class SpotProvider extends InvocationProvider
|
||||
/**
|
||||
* Processes a request from a client to move to a new location.
|
||||
*/
|
||||
public void handleChangeLocRequest (
|
||||
BodyObject source, int invid, int sceneId, int locationId)
|
||||
public void changeLoc (ClientObject caller, int sceneId, int locationId,
|
||||
ChangeLocListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
try {
|
||||
// look up the scene manager for the specified scene
|
||||
SpotSceneManager smgr = (SpotSceneManager)
|
||||
_screg.getSceneManager(sceneId);
|
||||
if (smgr == null) {
|
||||
Log.warning("User requested to change location in " +
|
||||
"non-existent scene [user=" + source.who() +
|
||||
", sceneId=" + sceneId +
|
||||
", locId=" + locationId + "].");
|
||||
throw new ServiceFailedException(INTERNAL_ERROR);
|
||||
}
|
||||
BodyObject source = (BodyObject)caller;
|
||||
|
||||
int locOid = smgr.handleChangeLocRequest(source, locationId);
|
||||
sendResponse(source, invid, CHANGE_LOC_SUCCEEDED_RESPONSE,
|
||||
new Integer(locOid));
|
||||
|
||||
} catch (ServiceFailedException sfe) {
|
||||
sendResponse(source, invid, CHANGE_LOC_FAILED_RESPONSE,
|
||||
sfe.getMessage());
|
||||
// look up the scene manager for the specified scene
|
||||
SpotSceneManager smgr = (SpotSceneManager)
|
||||
_screg.getSceneManager(sceneId);
|
||||
if (smgr == null) {
|
||||
Log.warning("User requested to change location in " +
|
||||
"non-existent scene [user=" + source.who() +
|
||||
", sceneId=" + sceneId +
|
||||
", locId=" + locationId + "].");
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
int locOid = smgr.handleChangeLocRequest(source, locationId);
|
||||
listener.changeLocSucceeded(locOid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles {@link SpotCodes#CLUSTER_SPEAK_REQUEST} messages.
|
||||
* Handles request to generate a speak message in the specified cluster.
|
||||
*/
|
||||
public void handleClusterSpeakRequest (
|
||||
BodyObject source, int invid, int sceneId, int locId, String message,
|
||||
byte mode)
|
||||
public void clusterSpeak (ClientObject caller, int sceneId, int locationId,
|
||||
String message, byte mode)
|
||||
{
|
||||
sendClusterChatMessage(sceneId, locId, source.getOid(),
|
||||
BodyObject source = (BodyObject)caller;
|
||||
sendClusterChatMessage(sceneId, locationId, source.getOid(),
|
||||
source.username, null, message, mode);
|
||||
}
|
||||
|
||||
@@ -220,7 +208,7 @@ public class SpotProvider extends InvocationProvider
|
||||
* from a real live human who wrote it in their native tongue).
|
||||
* @param message the text of the chat message.
|
||||
*/
|
||||
public static void sendClusterChatMessage (
|
||||
public void sendClusterChatMessage (
|
||||
int sceneId, int locId, int speakerOid, String speaker,
|
||||
String bundle, String message, byte mode)
|
||||
{
|
||||
@@ -242,9 +230,12 @@ public class SpotProvider extends InvocationProvider
|
||||
}
|
||||
}
|
||||
|
||||
/** The place registry with which we interoperate. */
|
||||
protected PlaceRegistry _plreg;
|
||||
|
||||
/** The scene registry with which we interoperate. */
|
||||
protected static SceneRegistry _screg;
|
||||
protected SceneRegistry _screg;
|
||||
|
||||
/** The object manager we use to do dobject stuff. */
|
||||
protected static RootDObjectManager _omgr;
|
||||
protected RootDObjectManager _omgr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user