If we're going to do this, I guess we're going to do it properly. Nixed the

notion of a global group (though we implicitly define one in InvocationCodes)
added a mechanism for directors (which generally handle the client side of
invocation services) to register their interest in bootstrap service groups so
that the whole goddamned complex business can happen magically behind the
scenes.

If you instantiate a director, it will automatically register interest in the
service group it needs and everything will work. If you don't use the director
code, you don't get the services and you can safely exclude all of that code
from your client even though the services are still in use on the server (and
presumably used by some other types of clients).

This is going to break all the builds, which I'll soon fix. Then I'll go write
all this in ActionScript. Yay!


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4552 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-02-11 01:17:30 +00:00
parent 9afcc526a0
commit ebc99935d5
25 changed files with 406 additions and 358 deletions
@@ -1,54 +1,56 @@
//
// $Id$
package com.threerings.admin.client;
import java.util.HashMap;
import com.samskivert.util.StringUtil;
import com.threerings.admin.Log;
import com.threerings.admin.data.ConfigObject;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.SessionObserver;
import com.threerings.presents.client.ClientAdapter;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.ObjectAccessException;
import com.threerings.presents.dobj.Subscriber;
import com.threerings.admin.Log;
import com.threerings.admin.data.AdminCodes;
import com.threerings.admin.data.ConfigObject;
/**
* Handles subscribing to admin config objects.
*/
public class ConfigObjectManager implements AdminService.ConfigInfoListener
{
public ConfigObjectManager(Client client) {
public ConfigObjectManager(Client client)
{
_serverconfig = new HashMap<String,ConfigObject>();
_client = client;
_client.addClientObserver(new SessionObserver() {
// documentation inherited from interface SessionObserver
_client.addClientObserver(new ClientAdapter() {
public void clientWillLogon (Client client) {
client.addServiceGroup(AdminCodes.ADMIN_GROUP);
}
public void clientDidLogon (Client client) {
// Initialize the dobjmgr
_dobjmgr = _client.getDObjectManager();
// Now that we're logged on, let's grab the server configs
_service = (AdminService)
client.requireService(AdminService.class);
_service = (AdminService)client.requireService(AdminService.class);
getConfigInfo();
}
// documentation inherited from interface SessionObserver
public void clientDidLogoff (Client client) {
// Clean up our subscription to the server's configuration
for (int ii = 0; ii < _csubscribers.length; ii++) {
_csubscribers[ii].cleanup();
}
}
// documentation inherited from interface SessionObserver
public void clientObjectDidChange (Client client) {}
});
}
/**
* Convenience: generate a getConfigInfo request to the AdminService
* from the external class, instead from within the anonymous inner class
* Returns the ConfigObject identified by the given key
*/
protected void getConfigInfo() {
_service.getConfigInfo(_client, this);
public ConfigObject getServerConfig (String key)
{
return _serverconfig.get(key);
}
// documentation inherited from interface AdminService.ConfigInfoListener
@@ -60,29 +62,32 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener
_csubscribers[ii].subscribeConfig(keys[ii], oids[ii]);
}
}
// documentation inherited from interface AdminService.ConfigInfoListener
public void requestFailed (String reason) {
public void requestFailed (String reason)
{
Log.warning("Oh bugger, we didn't get the config data: " + reason);
}
/**
* Returns the ConfigObject identified by the given key
* Convenience: generate a getConfigInfo request to the AdminService from the external class,
* instead from within the anonymous inner class
*/
public ConfigObject getServerConfig (String key) {
return _serverconfig.get(key);
protected void getConfigInfo()
{
_service.getConfigInfo(_client, this);
}
/**
* This class takes care of the details of subscribing to and placing
* an individual ConfigObject that the server knows about into a HashMap
* This class takes care of the details of subscribing to and placing an individual
* ConfigObject that the server knows about into a HashMap
*/
protected class ConfigObjectSubscriber implements Subscriber<ConfigObject>
{
/**
* This method requests that we place a subscription to the
* ConfigObject with the given oid, identified by the key; when the
* object becomes available, it's added to our serverconfig map.
* This method requests that we place a subscription to the ConfigObject with the given
* oid, identified by the key; when the object becomes available, it's added to our
* serverconfig map.
*/
public void subscribeConfig (String key, int oid) {
_key = key;
@@ -95,15 +100,15 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener
_cobj = object;
_serverconfig.put(_key, _cobj);
}
// documentation inherited from interface Subscriber
public void requestFailed (int oid, ObjectAccessException cause) {
Log.warning("Unable to subscribe to config object " + _key);
}
/**
* Signals that we should stop subscribing to our ConfigObject,
* and flush out the entry from the serverconfig map.
* Signals that we should stop subscribing to our ConfigObject, and flush out the entry
* from the serverconfig map.
*/
public void cleanup () {
// clear out our subscription
@@ -114,26 +119,26 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener
/** The object that we are tracking */
protected ConfigObject _cobj;
/** The name of the config object that we are subscribing to */
protected String _key;
/** The oid of the object that we're tracking */
protected int _oid;
}
/** An array of handlers that each subscribe to a single ConfigObject */
protected ConfigObjectSubscriber[] _csubscribers;
/** Our local copy of the server-side runtime configuration */
protected HashMap<String,ConfigObject> _serverconfig;
/** Our distributed object manager */
protected DObjectManager _dobjmgr;
/** Our admin service that we're using to fetch data */
protected AdminService _service;
/** Our client object */
protected Client _client;
}