From b33ae477ac4ef52aa222f816f8f7ce025d705fad Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 20 Feb 2006 19:39:38 +0000 Subject: [PATCH] Started refactorying the config object registry so that we can make a database-backed implementation to replace the Java preferences backed version. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3869 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../admin/server/AdminProvider.java | 27 ++++--- .../admin/server/ConfigRegistry.java | 76 +++++++++++++++++++ ...Registry.java => PrefsConfigRegistry.java} | 65 ++++------------ 3 files changed, 107 insertions(+), 61 deletions(-) create mode 100644 src/java/com/threerings/admin/server/ConfigRegistry.java rename src/java/com/threerings/admin/server/{ConfObjRegistry.java => PrefsConfigRegistry.java} (85%) diff --git a/src/java/com/threerings/admin/server/AdminProvider.java b/src/java/com/threerings/admin/server/AdminProvider.java index 9425c2888..bbf5f507a 100644 --- a/src/java/com/threerings/admin/server/AdminProvider.java +++ b/src/java/com/threerings/admin/server/AdminProvider.java @@ -1,5 +1,5 @@ // -// $Id: AdminProvider.java,v 1.4 2004/08/27 02:12:24 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -38,10 +38,10 @@ public class AdminProvider implements InvocationProvider * manager to handle admin services. This must be called by any server * that wishes to make use of the admin services. */ - public static void init (InvocationManager invmgr) + public static void init (InvocationManager invmgr, ConfigRegistry registry) { invmgr.registerDispatcher( - new AdminDispatcher(new AdminProvider()), true); + new AdminDispatcher(new AdminProvider(registry)), true); } /** @@ -51,16 +51,23 @@ public class AdminProvider implements InvocationProvider ClientObject caller, AdminService.ConfigInfoListener listener) { // we don't have to validate the request because the user can't do - // anything with the keys or oids unless they're an admin (we put - // the burden of doing that checking on the creator of the config - // object because we would otherwise need some mechanism to - // determine whether a user is an admin and we don't want to force - // some primitive system on the service user) - String[] keys = ConfObjRegistry.getKeys(); + // anything with the keys or oids unless they're an admin (we put the + // burden of doing that checking on the creator of the config object + // because we would otherwise need some mechanism to determine whether + // a user is an admin and we don't want to force some primitive system + // on the service user) + String[] keys = _registry.getKeys(); int[] oids = new int[keys.length]; for (int ii = 0; ii < keys.length; ii++) { - oids[ii] = ConfObjRegistry.getObject(keys[ii]).getOid(); + oids[ii] = _registry.getObject(keys[ii]).getOid(); } listener.gotConfigInfo(keys, oids); } + + protected AdminProvider (ConfigRegistry registry) + { + _registry = registry; + } + + protected ConfigRegistry _registry; } diff --git a/src/java/com/threerings/admin/server/ConfigRegistry.java b/src/java/com/threerings/admin/server/ConfigRegistry.java new file mode 100644 index 000000000..a991b16f0 --- /dev/null +++ b/src/java/com/threerings/admin/server/ConfigRegistry.java @@ -0,0 +1,76 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.admin.server; + +import com.threerings.presents.dobj.AccessController; +import com.threerings.presents.dobj.DObject; + +/** + * Provides a registry of configuration distributed objects. Using distributed + * object to store runtime configuration data can be exceptionally useful in + * that clients (with admin privileges) can view and update the running + * server's configuration parameters on the fly. + * + *

Users of the service are responsible for creating their own + * configuration objects which are then registered via this class. The config + * object registry then performs a few functions: + * + *

+ * + *

Users of this service will want to use {@link AccessController}s on + * their configuration distributed objects to prevent non-administrators from + * subscribing to or modifying the objects. +*/ +public abstract class ConfigRegistry +{ + /** + * Registers the supplied configuration object with the system. + * + * @param key a string that identifies this object. These are generally + * hierarchical in nature (of the form system.subsystem), for + * example: yohoho.crew. + * @param path The the path in the persistent configuration repository. + * @param object the object to be registered. + */ + public abstract void registerObject ( + String key, String path, DObject object); + + /** + * Returns the config object mapped to the specified key, or null if none + * exists for that key. + */ + public abstract DObject getObject (String key); + + /** + * Returns an array containing the keys of all registered configuration + * objects. + */ + public abstract String[] getKeys (); +} diff --git a/src/java/com/threerings/admin/server/ConfObjRegistry.java b/src/java/com/threerings/admin/server/PrefsConfigRegistry.java similarity index 85% rename from src/java/com/threerings/admin/server/ConfObjRegistry.java rename to src/java/com/threerings/admin/server/PrefsConfigRegistry.java index 48b051aa3..84eb6e553 100644 --- a/src/java/com/threerings/admin/server/ConfObjRegistry.java +++ b/src/java/com/threerings/admin/server/PrefsConfigRegistry.java @@ -51,63 +51,28 @@ import com.threerings.admin.Log; import com.threerings.presents.dobj.ObjectAccessException; /** - * Provides a registry of configuration distributed objects. Using - * distributed object to store runtime configuration data can be - * exceptionally useful in that clients (with admin privileges) can view - * and update the running server's configuration parameters on the fly. - * - *

Users of the service are responsible for creating their own - * configuration objects which are then registered via this class. The - * config object registry then performs a few functions: - * - *

- * - *

Users of this service will want to use {@link AccessController}s on - * their configuration distributed objects to prevent non-administrators - * from subscribing to or modifying the objects. + * Implements the {@link ConfigRegistry} using the Java preferences system as a + * persistent store for the configuration information (see {@link Config} for + * more information on how that works). */ -public class ConfObjRegistry +public class PrefsConfigRegistry extends ConfigRegistry { - /** - * Registers the supplied configuration object with the system. - * - * @param key a string that identifies this object. These are - * generally hierarchical in nature (of the form - * system.subsystem), for example: - * yohoho.crew. - * @param path The the path in the persistent configuration repository - * (see {@link Config} for more info). - * @param object the object to be registered. - */ - public static void registerObject (String key, String path, DObject object) + // documentation inherited + public void registerObject (String key, String path, DObject object) { // create a new config record for this object _configs.put(key, new ConfObjRecord(path, object)); } - /** - * Returns the config object mapped to the specified key, or null if - * none exists for that key. - */ - public static DObject getObject (String key) + // documentation inherited + public DObject getObject (String key) { ConfObjRecord record = (ConfObjRecord)_configs.get(key); return (record == null) ? null : record.confObj; } - /** - * Returns an array containing the keys of all registered - * configuration objects. - */ - public static String[] getKeys () + // documentation inherited + public String[] getKeys () { String[] keys = new String[_configs.size()]; Iterator iter = _configs.keySet().iterator(); @@ -118,8 +83,7 @@ public class ConfObjRegistry } /** - * Contains all necessary info for a configuration object - * registration. + * Contains all necessary info for a configuration object registration. */ protected static class ConfObjRecord implements AttributeChangeListener, SetListener @@ -132,8 +96,8 @@ public class ConfObjRegistry this.config = new Config(path); this.confObj = confObj; - // read in the initial configuration settings from the - // persistent configuration repository + // read in the initial configuration settings from the persistent + // configuration repository Class cclass = confObj.getClass(); try { Field[] fields = cclass.getFields(); @@ -261,7 +225,6 @@ public class ConfObjRegistry field.set(confObj, config.getValue(key, defval)); } else if (Streamable.class.isAssignableFrom(type)) { - // don't freak out if the conf is blank. String value = config.getValue(key, ""); if (StringUtil.isBlank(value)) { @@ -370,5 +333,5 @@ public class ConfObjRegistry } /** A mapping from identifying key to config object. */ - protected static HashMap _configs = new HashMap(); + protected HashMap _configs = new HashMap(); }