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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p> 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:
|
||||
*
|
||||
* <ul>
|
||||
|
||||
* <li> It populates the config object with values from the persistent
|
||||
* configuration information.
|
||||
* <li> It mirrors object updates out to the persistent configuration
|
||||
* repository.
|
||||
* <li> It makes the set of registered objects available for inspection and
|
||||
* modification via the admin client interface.
|
||||
* </ul>
|
||||
*
|
||||
* <p> 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 <code>system.subsystem</code>), for
|
||||
* example: <code>yohoho.crew</code>.
|
||||
* @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 ();
|
||||
}
|
||||
+14
-51
@@ -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.
|
||||
*
|
||||
* <p> 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:
|
||||
*
|
||||
* <ul>
|
||||
* <li> It populates the config object with values from the persistent
|
||||
* configuration information (see {@link Config} for more information on
|
||||
* how that works).
|
||||
* <li> It mirrors object updates out to the persistent configuration
|
||||
* repository.
|
||||
* <li> It makes the set of registered objects available for inspection
|
||||
* and modification via the admin client interface.
|
||||
* </ul>
|
||||
*
|
||||
* <p> 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
|
||||
* <code>system.subsystem</code>), for example:
|
||||
* <code>yohoho.crew</code>.
|
||||
* @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();
|
||||
}
|
||||
Reference in New Issue
Block a user