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
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
// 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
|
* manager to handle admin services. This must be called by any server
|
||||||
* that wishes to make use of the admin services.
|
* 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(
|
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)
|
ClientObject caller, AdminService.ConfigInfoListener listener)
|
||||||
{
|
{
|
||||||
// we don't have to validate the request because the user can't do
|
// 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
|
// anything with the keys or oids unless they're an admin (we put the
|
||||||
// the burden of doing that checking on the creator of the config
|
// burden of doing that checking on the creator of the config object
|
||||||
// object because we would otherwise need some mechanism to
|
// because we would otherwise need some mechanism to determine whether
|
||||||
// determine whether a user is an admin and we don't want to force
|
// a user is an admin and we don't want to force some primitive system
|
||||||
// some primitive system on the service user)
|
// on the service user)
|
||||||
String[] keys = ConfObjRegistry.getKeys();
|
String[] keys = _registry.getKeys();
|
||||||
int[] oids = new int[keys.length];
|
int[] oids = new int[keys.length];
|
||||||
for (int ii = 0; ii < keys.length; ii++) {
|
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);
|
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;
|
import com.threerings.presents.dobj.ObjectAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a registry of configuration distributed objects. Using
|
* Implements the {@link ConfigRegistry} using the Java preferences system as a
|
||||||
* distributed object to store runtime configuration data can be
|
* persistent store for the configuration information (see {@link Config} for
|
||||||
* exceptionally useful in that clients (with admin privileges) can view
|
* more information on how that works).
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
public class ConfObjRegistry
|
public class PrefsConfigRegistry extends ConfigRegistry
|
||||||
{
|
{
|
||||||
/**
|
// documentation inherited
|
||||||
* Registers the supplied configuration object with the system.
|
public void registerObject (String key, String path, DObject object)
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
// create a new config record for this object
|
// create a new config record for this object
|
||||||
_configs.put(key, new ConfObjRecord(path, object));
|
_configs.put(key, new ConfObjRecord(path, object));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// documentation inherited
|
||||||
* Returns the config object mapped to the specified key, or null if
|
public DObject getObject (String key)
|
||||||
* none exists for that key.
|
|
||||||
*/
|
|
||||||
public static DObject getObject (String key)
|
|
||||||
{
|
{
|
||||||
ConfObjRecord record = (ConfObjRecord)_configs.get(key);
|
ConfObjRecord record = (ConfObjRecord)_configs.get(key);
|
||||||
return (record == null) ? null : record.confObj;
|
return (record == null) ? null : record.confObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// documentation inherited
|
||||||
* Returns an array containing the keys of all registered
|
public String[] getKeys ()
|
||||||
* configuration objects.
|
|
||||||
*/
|
|
||||||
public static String[] getKeys ()
|
|
||||||
{
|
{
|
||||||
String[] keys = new String[_configs.size()];
|
String[] keys = new String[_configs.size()];
|
||||||
Iterator iter = _configs.keySet().iterator();
|
Iterator iter = _configs.keySet().iterator();
|
||||||
@@ -118,8 +83,7 @@ public class ConfObjRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains all necessary info for a configuration object
|
* Contains all necessary info for a configuration object registration.
|
||||||
* registration.
|
|
||||||
*/
|
*/
|
||||||
protected static class ConfObjRecord
|
protected static class ConfObjRecord
|
||||||
implements AttributeChangeListener, SetListener
|
implements AttributeChangeListener, SetListener
|
||||||
@@ -132,8 +96,8 @@ public class ConfObjRegistry
|
|||||||
this.config = new Config(path);
|
this.config = new Config(path);
|
||||||
this.confObj = confObj;
|
this.confObj = confObj;
|
||||||
|
|
||||||
// read in the initial configuration settings from the
|
// read in the initial configuration settings from the persistent
|
||||||
// persistent configuration repository
|
// configuration repository
|
||||||
Class cclass = confObj.getClass();
|
Class cclass = confObj.getClass();
|
||||||
try {
|
try {
|
||||||
Field[] fields = cclass.getFields();
|
Field[] fields = cclass.getFields();
|
||||||
@@ -261,7 +225,6 @@ public class ConfObjRegistry
|
|||||||
field.set(confObj, config.getValue(key, defval));
|
field.set(confObj, config.getValue(key, defval));
|
||||||
|
|
||||||
} else if (Streamable.class.isAssignableFrom(type)) {
|
} else if (Streamable.class.isAssignableFrom(type)) {
|
||||||
|
|
||||||
// don't freak out if the conf is blank.
|
// don't freak out if the conf is blank.
|
||||||
String value = config.getValue(key, "");
|
String value = config.getValue(key, "");
|
||||||
if (StringUtil.isBlank(value)) {
|
if (StringUtil.isBlank(value)) {
|
||||||
@@ -370,5 +333,5 @@ public class ConfObjRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A mapping from identifying key to config object. */
|
/** 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