I love to make vast, sweeping changes. Now the place services incorporate

a place config object which is used to determine the classes of the place
manager and the (newly added) place controller.

Moved PlaceView and PlaceViewUtil into cocktail.party.client from
cocktail.party.util because the controller and the UI (in very abstract
form) are now part of the place services.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@399 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-10-05 23:57:26 +00:00
parent 7636e33a7c
commit 63191ec610
9 changed files with 327 additions and 57 deletions
@@ -1,10 +1,11 @@
//
// $Id: LocationProvider.java,v 1.8 2001/10/01 22:14:55 mdb Exp $
// $Id: LocationProvider.java,v 1.9 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.server;
import com.threerings.cocktail.cher.dobj.DObject;
import com.threerings.cocktail.cher.server.InvocationProvider;
import com.threerings.cocktail.cher.server.ServiceFailedException;
import com.threerings.cocktail.party.Log;
import com.threerings.cocktail.party.client.LocationCodes;
@@ -23,14 +24,15 @@ public class LocationProvider
public void handleMoveToRequest (BodyObject source, int invid,
int placeId)
{
// try to do the actual move
String rcode = moveTo(source, placeId);
try {
// do the move
PlaceConfig config = moveTo(source, placeId);
// and send the response
sendResponse(source, invid, MOVE_SUCCEEDED_RESPONSE, config);
// send the response
if (rcode.equals(SUCCESS)) {
sendResponse(source, invid, MOVE_SUCCEEDED_RESPONSE);
} else {
sendResponse(source, invid, MOVE_FAILED_RESPONSE, rcode);
} catch (ServiceFailedException sfe) {
sendResponse(source, invid, MOVE_FAILED_RESPONSE,
sfe.getMessage());
}
}
@@ -38,10 +40,14 @@ public class LocationProvider
* Moves the specified body from whatever location they currently
* occupy to the location identified by the supplied place id.
*
* @return the string <code>SUCCESS</code> if the move was successful
* or a reason code for failure if not.
* @return the config object for the new location.
*
* @exception ServiceFaildException thrown if the move was not
* successful for some reason (which will be communicated as an error
* code in the exception's message data).
*/
public static String moveTo (BodyObject source, int placeId)
public static PlaceConfig moveTo (BodyObject source, int placeId)
throws ServiceFailedException
{
int bodoid = source.getOid();
@@ -50,7 +56,7 @@ public class LocationProvider
if (pmgr == null) {
Log.info("Requested to move to non-existent place " +
"[source=" + source + ", place=" + placeId + "].");
return NO_SUCH_PLACE;
throw new ServiceFailedException(NO_SUCH_PLACE);
}
// acquire a lock on the body object to ensure that rapid fire
@@ -58,13 +64,13 @@ public class LocationProvider
if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't
// been fully processed
return MOVE_IN_PROGRESS;
throw new ServiceFailedException(MOVE_IN_PROGRESS);
}
// make sure they're not already in the location they're asking to
// move to
if (source.location == placeId) {
return ALREADY_THERE;
throw new ServiceFailedException(ALREADY_THERE);
}
// find out if they were previously in some other location
@@ -112,6 +118,6 @@ public class LocationProvider
// once all these events are processed
source.releaseLock("moveToLock");
return SUCCESS;
return pmgr.getConfig();
}
}
@@ -1,5 +1,5 @@
//
// $Id: PlaceManager.java,v 1.13 2001/10/02 02:07:50 mdb Exp $
// $Id: PlaceManager.java,v 1.14 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.server;
@@ -33,11 +33,19 @@ import com.threerings.cocktail.party.data.*;
public class PlaceManager implements Subscriber
{
/**
* Called by the place registry after creating this place manager.
* Returns a reference to our place configuration object.
*/
public void setPlaceRegistry (PlaceRegistry registry)
public PlaceConfig getConfig ()
{
_registry = registry;
return _config;
}
/**
* Returns the place object managed by this place manager.
*/
public PlaceObject getPlaceObject ()
{
return _plobj;
}
/**
@@ -58,6 +66,29 @@ public class PlaceManager implements Subscriber
return PlaceObject.class;
}
/**
* Called by the place registry after creating this place manager.
*/
public void init (PlaceRegistry registry, PlaceConfig config)
{
_registry = registry;
_config = config;
// let derived classes do initialization stuff
didInit();
}
/**
* Called after this place manager has been initialized with its
* configuration information but before it has been started up with
* its place object reference. Derived classes can override this
* function and perform any basic initialization that they desire.
* They should of course be sure to call <code>super.didInit()</code>.
*/
protected void didInit ()
{
}
/**
* Called by the place manager after the place object has been
* successfully created.
@@ -194,14 +225,6 @@ public class PlaceManager implements Subscriber
_msghandlers.put(name, handler);
}
/**
* Returns the place object managed by this place manager.
*/
public PlaceObject getPlaceObject ()
{
return _plobj;
}
// nothing doing
public void objectAvailable (DObject object)
{
@@ -269,6 +292,7 @@ public class PlaceManager implements Subscriber
protected void toString (StringBuffer buf)
{
buf.append("place=").append(_plobj);
buf.append(", config=").append(_config);
}
/**
@@ -291,6 +315,9 @@ public class PlaceManager implements Subscriber
/** A reference to the place object that we manage. */
protected PlaceObject _plobj;
/** A reference to the configuration for our place. */
protected PlaceConfig _config;
/** A reference to the place registry with which we're registered. */
protected PlaceRegistry _registry;
@@ -1,5 +1,5 @@
//
// $Id: PlaceRegistry.java,v 1.9 2001/10/02 02:07:50 mdb Exp $
// $Id: PlaceRegistry.java,v 1.10 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.server;
@@ -12,6 +12,7 @@ import com.samskivert.util.Queue;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.party.Log;
import com.threerings.cocktail.party.data.PlaceConfig;
import com.threerings.cocktail.party.data.PlaceObject;
/**
@@ -36,8 +37,10 @@ public class PlaceRegistry implements Subscriber
* creation of the object and informing the manager when it is
* created.
*
* @param pmgrClass the {@link PlaceManager} derived class that should
* be instantiated to manage the place.
* @param config the configuration object for the place to be
* created. The {@link PlaceManager} derived class that should be
* instantiated to manage the place will be determined from the config
* object.
*
* @return a reference to the place manager that will manage the new
* place object.
@@ -45,14 +48,16 @@ public class PlaceRegistry implements Subscriber
* @exception InstantiationException thrown if an error occurs trying
* to instantiate and initialize the place manager.
*/
public PlaceManager createPlace (Class pmgrClass)
public PlaceManager createPlace (PlaceConfig config)
throws InstantiationException
{
try {
// load up the manager class
Class pmgrClass = Class.forName(config.getManagerClassName());
// create a place manager for this place
PlaceManager pmgr = (PlaceManager)pmgrClass.newInstance();
// let the pmgr know about us
pmgr.setPlaceRegistry(this);
// let the pmgr know about us and its configuration
pmgr.init(this, config);
// stick the manager on the creation queue because we know
// we'll get our calls to objectAvailable()/requestFailed() in
@@ -65,9 +70,10 @@ public class PlaceRegistry implements Subscriber
return pmgr;
} catch (IllegalAccessException iae) {
} catch (Exception e) {
Log.logStackTrace(e);
throw new InstantiationException(
"Error instantiating place manager: " + iae);
"Error creating place manager [config=" + config + "].");
}
}