diff --git a/docs/crowd/notes.txt b/docs/crowd/notes.txt index ab2257325..8c6cbeac9 100644 --- a/docs/crowd/notes.txt +++ b/docs/crowd/notes.txt @@ -3,3 +3,6 @@ Party Notes -*- outline -*- * TODO Wire up PlaceRegistry code to remove registrations when place objects are destroyed. + +Flesh out the mechanism for passing config information to place managers. +Make it easy to build an inheriting chain of configuration properties. diff --git a/src/java/com/threerings/crowd/server/PlaceConfig.java b/src/java/com/threerings/crowd/server/PlaceConfig.java new file mode 100644 index 000000000..99510beb7 --- /dev/null +++ b/src/java/com/threerings/crowd/server/PlaceConfig.java @@ -0,0 +1,24 @@ +// +// $Id: PlaceConfig.java,v 1.1 2001/08/01 20:37:35 mdb Exp $ + +package com.threerings.cocktail.party.server; + +/** + * PlaceConfig acts as a central location and means for + * documenting the various standard configuration properties that can be + * provided to the place manager via its config properties object. + */ +public class PlaceConfig +{ + /** + * This configuration parameter specifies the classname of the place + * object derived class to be used when creating a new place. + */ + public static final String PLACEOBJ_CLASS = "pobj"; + + /** + * This configuration parameter specifies the classname of the place + * manager derived class to be used when creating a new place. + */ + public static final String PLACEMGR_CLASS = "pmgr"; +} diff --git a/src/java/com/threerings/crowd/server/PlaceManager.java b/src/java/com/threerings/crowd/server/PlaceManager.java index d9dad324a..0a7fbb40c 100644 --- a/src/java/com/threerings/crowd/server/PlaceManager.java +++ b/src/java/com/threerings/crowd/server/PlaceManager.java @@ -1,8 +1,10 @@ // -// $Id: PlaceManager.java,v 1.4 2001/08/01 17:00:58 mdb Exp $ +// $Id: PlaceManager.java,v 1.5 2001/08/01 20:37:35 mdb Exp $ package com.threerings.cocktail.party.server; +import java.util.Properties; + import com.threerings.cocktail.cher.dobj.*; import com.threerings.cocktail.party.data.PlaceObject; @@ -35,12 +37,13 @@ public class PlaceManager implements Subscriber { /** * Called by the place registry after creating this place manager. - * Initialization is followed by startup which happens when the place - * object that this manager will manage is available. + * Initialization is followed by startup which will happen when the + * place object to be managed is available. */ - public void init (PlaceRegistry registry) + public void init (PlaceRegistry registry, Properties config) { _registry = registry; + _config = config; } /** @@ -104,4 +107,7 @@ public class PlaceManager implements Subscriber /** A reference to the place registry with which we're registered. */ protected PlaceRegistry _registry; + + /** The configuration provided for this place manager. */ + protected Properties _config; } diff --git a/src/java/com/threerings/crowd/server/PlaceRegistry.java b/src/java/com/threerings/crowd/server/PlaceRegistry.java index 48c11cff4..e36ad3bb4 100644 --- a/src/java/com/threerings/crowd/server/PlaceRegistry.java +++ b/src/java/com/threerings/crowd/server/PlaceRegistry.java @@ -1,9 +1,11 @@ // -// $Id: PlaceRegistry.java,v 1.2 2001/08/01 17:00:59 mdb Exp $ +// $Id: PlaceRegistry.java,v 1.3 2001/08/01 20:37:35 mdb Exp $ package com.threerings.cocktail.party.server; import java.util.Enumeration; +import java.util.Properties; + import com.samskivert.util.Config; import com.samskivert.util.Queue; @@ -29,6 +31,41 @@ public class PlaceRegistry implements Subscriber { } + /** + * Creates and registers a new place along with a manager to manage + * that place. The place object class and place manager class are + * determined from the configuration information provided in the + * supplied properties instance. + * + * @param config the configuration information for this place manager. + * + * @see PlaceConfig#PLACEOBJ_CLASS + * @see PlaceConfig#PLACEMGR_CLASS + */ + public void createPlace (Properties config) + { + String pobjcl = config.getProperty(PlaceConfig.PLACEOBJ_CLASS); + if (pobjcl == null) { + Log.warning("No place object classname specified in " + + "place config [config=" + config + "]."); + return; + } + + String pmgrcl = config.getProperty(PlaceConfig.PLACEMGR_CLASS); + if (pobjcl == null) { + Log.warning("No place manager classname specified in " + + "place config [config=" + config + "]."); + return; + } + + try { + createPlace(Class.forName(pobjcl), Class.forName(pmgrcl), config); + } catch (Exception e) { + Log.warning("Unable to instantiate place object or " + + "manager class [error=" + e + "]."); + } + } + /** * Creates and registers a new place along with a manager to manage * that place. The registry takes care of tracking the creation of the @@ -38,14 +75,16 @@ public class PlaceRegistry implements Subscriber * should be instantiated to create the place object. * @param pmgrClass the PlaceManager derived class that * should be instantiated to manage the place. + * @param config the configuration information for this place manager. */ - public void createPlace (Class pobjClass, Class pmgrClass) + public void createPlace (Class pobjClass, Class pmgrClass, + Properties config) { // create a place manager for this place try { PlaceManager pmgr = (PlaceManager)pmgrClass.newInstance(); // let the pmgr know about us - pmgr.init(this); + pmgr.init(this, config); // stick the manager on the creation queue because we know // we'll get our calls to objectAvailable()/requestFailed() in // the order that we call createObject()