Widening.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4776 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-07-18 21:58:16 +00:00
parent 6531aa581c
commit b0ec20eff9
@@ -47,8 +47,7 @@ public class LocationProvider
/** /**
* Creates a location provider and prepares it for operation. * Creates a location provider and prepares it for operation.
*/ */
public LocationProvider (InvocationManager invmgr, RootDObjectManager omgr, public LocationProvider (InvocationManager invmgr, RootDObjectManager omgr, PlaceRegistry plreg)
PlaceRegistry plreg)
{ {
// we'll need these later // we'll need these later
_invmgr = invmgr; _invmgr = invmgr;
@@ -57,18 +56,13 @@ public class LocationProvider
} }
/** /**
* Requests that this client's body be moved to the specified * Requests that this client's body be moved to the specified location.
* location.
* *
* @param caller the client object of the client that invoked this * @param caller the client object of the client that invoked this remotely callable method.
* remotely callable method. * @param placeId the object id of the place object to which the body should be moved.
* @param placeId the object id of the place object to which the body * @param listener the listener that will be informed of success or failure.
* should be moved.
* @param listener the listener that will be informed of success or
* failure.
*/ */
public void moveTo (ClientObject caller, int placeId, public void moveTo (ClientObject caller, int placeId, LocationService.MoveListener listener)
LocationService.MoveListener listener)
throws InvocationException throws InvocationException
{ {
// do the move and send the response // do the move and send the response
@@ -85,14 +79,13 @@ public class LocationProvider
} }
/** /**
* Moves the specified body from whatever location they currently * Moves the specified body from whatever location they currently occupy to the location
* occupy to the location identified by the supplied place id. * identified by the supplied place id.
* *
* @return the config object for the new location. * @return the config object for the new location.
* *
* @exception ServiceFaildException thrown if the move was not * @exception ServiceFaildException thrown if the move was not successful for some reason
* successful for some reason (which will be communicated as an error * (which will be communicated as an error code in the exception's message data).
* code in the exception's message data).
*/ */
public PlaceConfig moveTo (BodyObject source, int placeId) public PlaceConfig moveTo (BodyObject source, int placeId)
throws InvocationException throws InvocationException
@@ -102,18 +95,16 @@ public class LocationProvider
// make sure the place in question actually exists // make sure the place in question actually exists
PlaceManager pmgr = _plreg.getPlaceManager(placeId); PlaceManager pmgr = _plreg.getPlaceManager(placeId);
if (pmgr == null) { if (pmgr == null) {
Log.info("Requested to move to non-existent place " + Log.info("Requested to move to non-existent place [who=" + source.who() +
"[who=" + source.who() + ", place=" + placeId + "]."); ", place=" + placeId + "].");
throw new InvocationException(NO_SUCH_PLACE); throw new InvocationException(NO_SUCH_PLACE);
} }
// if they're already in the location they're asking to move to, // if they're already in the location they're asking to move to, just give them the config
// just give them the config because we don't need to update // because we don't need to update anything in distributed object world
// anything in distributed object world
if (source.location == placeId) { if (source.location == placeId) {
Log.debug("Going along with client request to move to where " + Log.debug("Going along with client request to move to where they already are " +
"they already are [source=" + source.who() + "[source=" + source.who() + ", placeId=" + placeId + "].");
", placeId=" + placeId + "].");
return pmgr.getConfig(); return pmgr.getConfig();
} }
@@ -123,16 +114,13 @@ public class LocationProvider
throw new InvocationException(errmsg); throw new InvocationException(errmsg);
} }
// acquire a lock on the body object to ensure that rapid fire // acquire a lock on the body object to avoid breakage by rapid fire moveTo requests
// moveTo requests don't break things
if (!source.acquireLock("moveToLock")) { if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't // if we're still locked, a previous moveTo request hasn't been fully processed
// been fully processed
throw new InvocationException(MOVE_IN_PROGRESS); throw new InvocationException(MOVE_IN_PROGRESS);
} }
// configure the client accordingly if they're moving to a place // configure the client accordingly if the place uses a custom class loader
// that uses a custom class loader
PresentsClient client = CrowdServer.clmgr.getClient(source.username); PresentsClient client = CrowdServer.clmgr.getClient(source.username);
if (client != null) { if (client != null) {
client.setClassLoader(_plreg.getClassLoader(pmgr.getConfig())); client.setClassLoader(_plreg.getClassLoader(pmgr.getConfig()));
@@ -141,8 +129,8 @@ public class LocationProvider
try { try {
PlaceObject place = pmgr.getPlaceObject(); PlaceObject place = pmgr.getPlaceObject();
// the doubly nested try catch is to prevent failure if one or // the doubly nested try catch is to prevent failure if one or the other of the
// the other of the transactions fails to start // transactions fails to start
place.startTransaction(); place.startTransaction();
try { try {
source.startTransaction(); source.startTransaction();
@@ -150,8 +138,7 @@ public class LocationProvider
// remove them from any previous location // remove them from any previous location
leaveOccupiedPlace(source); leaveOccupiedPlace(source);
// generate a new occupant info record (which will add // generate a new occinfo record (which will add it to the target location)
// it to the target location)
pmgr.buildOccupantInfo(source); pmgr.buildOccupantInfo(source);
// set the body's new location // set the body's new location
@@ -168,8 +155,7 @@ public class LocationProvider
} }
} finally { } finally {
// and finally queue up a lock release event to release the // and finally queue up an event to release the lock once these events are processed
// lock once all these events are processed
source.releaseLock("moveToLock"); source.releaseLock("moveToLock");
} }
@@ -177,8 +163,8 @@ public class LocationProvider
} }
/** /**
* Removes the specified body from the place object they currently * Removes the specified body from the place object they currently occupy. Does nothing if the
* occupy. Does nothing if the body is not currently in a place. * body is not currently in a place.
*/ */
public void leaveOccupiedPlace (BodyObject source) public void leaveOccupiedPlace (BodyObject source)
{ {
@@ -207,14 +193,13 @@ public class LocationProvider
} }
} else { } else {
Log.info("Body's prior location no longer around? " + Log.info("Body's prior location no longer around? [boid=" + bodoid +
"[boid=" + bodoid + ", poid=" + oldloc + "]."); ", poid=" + oldloc + "].");
} }
} catch (ClassCastException cce) { } catch (ClassCastException cce) {
Log.warning("Body claims to occupy non-PlaceObject!? " + Log.warning("Body claims to occupy non-PlaceObject!? [boid=" + bodoid +
"[boid=" + bodoid + ", poid=" + oldloc + ", poid=" + oldloc + ", error=" + cce + "].");
", error=" + cce + "].");
} }
// clear out their location oid // clear out their location oid
@@ -222,14 +207,12 @@ public class LocationProvider
} }
/** /**
* Forcibly moves the specified body object to the new place. This is * Forcibly moves the specified body object to the new place. This is accomplished by first
* accomplished by first removing the client from their old location * removing the client from their old location and then sending the client a notification,
* and then sending the client a notification, instructing it to move * instructing it to move to the new location (which it does using the normal moveTo service).
* to the new location (which it does using the normal moveTo * This has the benefit that the client is removed from their old place regardless of whether
* service). This has the benefit that the client is removed from * or not they are cooperating. If they choose to ignore the forced move request, they will
* their old place regardless of whether or not they are cooperating. * remain in limbo, unable to do much of anything.
* If they choose to ignore the forced move request, they will remain
* in limbo, unable to do much of anything.
*/ */
public void moveBody (BodyObject source, int placeId) public void moveBody (BodyObject source, int placeId)
{ {