Beginnings of runtime control panel stuff.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1428 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-06-07 06:22:24 +00:00
parent b81ab2f176
commit 6202c1a463
8 changed files with 506 additions and 0 deletions
@@ -0,0 +1,51 @@
//
// $Id: AdminProvider.java,v 1.1 2002/06/07 06:22:24 mdb Exp $
package com.threerings.admin.server;
import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.presents.server.ServiceFailedException;
import com.threerings.crowd.data.BodyObject;
import com.threerings.admin.Log;
import com.threerings.admin.data.AdminCodes;
/**
* Provides the server-side interface to various administrator services.
*/
public class AdminProvider extends InvocationProvider
implements AdminCodes
{
/**
* Constructs an admin provider and registers it with the invocation
* 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)
{
invmgr.registerProvider(MODULE_NAME, new AdminProvider());
}
/**
* Processes a request from a client to obtain the configuration keys
* and oids for all registered configuration objects.
*/
public void handleGetConfigInfoRequest (BodyObject source, int invid)
throws ServiceFailedException
{
// 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();
int[] oids = new int[keys.length];
for (int ii = 0; ii < keys.length; ii++) {
oids[ii] = ConfObjRegistry.getObject(keys[ii]).getOid();
}
sendResponse(source, invid, CONFIG_INFO_RESPONSE, keys, oids);
}
}
@@ -0,0 +1,67 @@
//
// $Id: ConfObjRegistry.java,v 1.1 2002/06/07 06:22:24 mdb Exp $
package com.threerings.admin.server;
import java.util.HashMap;
import java.util.Iterator;
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 with this class which
* simply makes available a list of all registered configuration objects
* to the client. The service users 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
{
/**
* 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 object the object to be registered.
*/
public static void registerObject (String key, DObject object)
{
_confobjs.put(key, object);
}
/**
* Returns the config object mapped to the specified key, or null if
* none exists for that key.
*/
public static DObject getObject (String key)
{
return (DObject)_confobjs.get(key);
}
/**
* Returns an array containing the keys of all registered
* configuration objects.
*/
public static String[] getKeys ()
{
String[] keys = new String[_confobjs.size()];
Iterator iter = _confobjs.keySet().iterator();
for (int ii = 0; iter.hasNext(); ii++) {
keys[ii] = (String)iter.next();
}
return keys;
}
/** A mapping from identifying key to config object. */
protected static HashMap _confobjs = new HashMap();
}