More work on invocation manager; modified startup sequence so that server

can get shit together before bootstrapping the client.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@68 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-07-19 07:09:16 +00:00
parent 6663aae772
commit 915f3db6f1
15 changed files with 371 additions and 129 deletions
@@ -1,10 +1,15 @@
//
// $Id: InvocationManager.java,v 1.1 2001/07/19 05:56:20 mdb Exp $
// $Id: InvocationManager.java,v 1.2 2001/07/19 07:09:16 mdb Exp $
package com.threerings.cocktail.cher.server;
import java.lang.reflect.Method;
import java.util.HashMap;
import com.threerings.cocktail.cher.Log;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.cher.data.*;
import com.threerings.cocktail.cher.util.ClassUtil;
/**
* The invocation services provide client to server invocations (service
@@ -22,7 +27,7 @@ import com.threerings.cocktail.cher.dobj.*;
*
* <p> The server invocation manager listens for invocation requests from
* the client and passes them on to the invocation provider registered for
* the requested invocation type. It also provides a mechanism by which
* the requested invocation module. It also provides a mechanism by which
* responses and asynchronous notification invocations can be delivered to
* the client.
*/
@@ -42,6 +47,15 @@ public class InvocationManager
return _invoid;
}
/**
* Registers the supplied invocation provider instance as the handler
* for all invocation requests for the specified module.
*/
public void registerProvider (String module, Object provider)
{
_providers.put(module, provider);
}
public void objectAvailable (DObject object)
{
// this must be our invocation object
@@ -66,12 +80,54 @@ public class InvocationManager
return true;
}
MessageEvent mevt = (MessageEvent)event;
// make sure the name is proper just for sanities sake
MessageEvent mevt = (MessageEvent)event;
if (!mevt.getName().equals(InvocationObject.MESSAGE_NAME)) {
return true;
}
// we've got an invocation request, so we process it
Object[] args = mevt.getArgs();
String module = (String)args[0];
String procedure = (String)args[1];
int invid = ((Integer)args[2]).intValue();
// locate a provider for this module
Object provider = _providers.get(module);
if (provider == null) {
Log.warning("No provider registered for invocation request " +
"[evt=" + mevt + "].");
return true;
}
// prune the method arguments from the full message arguments
Object[] margs = new Object[args.length-3];
System.arraycopy(args, 3, margs, 0, margs.length);
// look up the method that will handle this procedure
String mname = "handle" + procedure + "Request";
Method procmeth = ClassUtil.getMethod(mname, provider, _methcache);
if (procmeth == null) {
Log.warning("Unable to resolve provider procedure " +
"[provider=" + provider.getClass().getName() +
", method=" + mname + "].");
return true;
}
// and invoke it
try {
procmeth.invoke(provider, margs);
} catch (Exception e) {
Log.warning("Error invoking invocation procedure " +
"[provider=" + provider + ", method=" + procmeth +
", error=" + e + "].");
}
return true;
}
protected DObjectManager _omgr;
protected int _invoid;
protected HashMap _providers = new HashMap();
protected HashMap _methcache = new HashMap();
}
@@ -1,5 +1,5 @@
//
// $Id: PresentsClient.java,v 1.4 2001/06/11 17:44:04 mdb Exp $
// $Id: PresentsClient.java,v 1.5 2001/07/19 07:09:16 mdb Exp $
package com.threerings.cocktail.cher.server;
@@ -7,6 +7,7 @@ import java.io.IOException;
import java.util.HashMap;
import com.threerings.cocktail.cher.Log;
import com.threerings.cocktail.cher.data.ClientObject;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.cher.net.*;
import com.threerings.cocktail.cher.server.net.*;
@@ -36,6 +37,30 @@ public class Client implements Subscriber, MessageHandler
_cmgr = cmgr;
_username = username;
setConnection(conn);
// create our client object and bootstrap the client once we've
// got it
Subscriber sub = new Subscriber ()
{
public void objectAvailable (DObject object)
{
setClientObject((ClientObject)object);
sendBootstrap();
}
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.warning("Unable to create client object " +
"[client=" + Client.this +
", error=" + cause + "].");
}
public boolean handleEvent (DEvent event, DObject target)
{
return false;
}
};
CherServer.omgr.createObject(ClientObject.class, this, false);
}
/**
@@ -68,9 +93,59 @@ public class Client implements Subscriber, MessageHandler
// start using the new connection
setConnection(conn);
// send off a bootstrap notification immediately because we've
// already got our client object
sendBootstrap();
Log.info("Session resumed [client=" + this + "].");
}
protected void setClientObject (ClientObject clobj)
{
// keep track of this for later
_clobj = clobj;
}
/**
* This is called once we have a handle on the client distributed
* object. It sends a bootstrap notification to the client with all
* the information it will need to interact with the server.
*/
protected void sendBootstrap ()
{
// create and populate our bootstrap data
BootstrapData data = createBootstrapData();
populateBootstrapData(data);
// create a send bootstrap notification
_conn.postMessage(new BootstrapNotification(data));
}
/**
* Derived client classes can override this member to create derived
* bootstrap data classes that contain extra bootstrap information, if
* desired.
*/
protected BootstrapData createBootstrapData ()
{
return new BootstrapData();
}
/**
* Derived client classes can override this member to populate the
* bootstrap data with additional information. They should be sure to
* call <code>super.populateBootstrapData()</code> before doing their
* own populating, however.
*/
protected void populateBootstrapData (BootstrapData data)
{
// give them the client object id
data.clientOid = _clobj.getOid();
// give them the invocation oid
data.invOid = CherServer.invmgr.getOid();
}
/**
* Called by the connection manager when this client's connection
* fails. This is invoked on the conmgr thread, and should behave
@@ -269,6 +344,7 @@ public class Client implements Subscriber, MessageHandler
protected ClientManager _cmgr;
protected String _username;
protected Connection _conn;
protected ClientObject _clobj;
protected static HashMap _disps = new HashMap();
@@ -1,5 +1,5 @@
//
// $Id: PresentsServer.java,v 1.5 2001/06/09 23:39:04 mdb Exp $
// $Id: PresentsServer.java,v 1.6 2001/07/19 07:09:16 mdb Exp $
package com.threerings.cocktail.cher.server;
@@ -28,6 +28,9 @@ public class CherServer
/** The distributed object manager. */
public static DObjectManager omgr;
/** The invocation manager. */
public static InvocationManager invmgr;
/**
* Initializes all of the server services and prepares for operation.
*/
@@ -42,6 +45,8 @@ public class CherServer
clmgr = new ClientManager(conmgr);
// create our distributed object manager
omgr = new CherDObjectMgr();
// create our invocation manager
invmgr = new InvocationManager(omgr);
// create an object for testing
omgr.createObject(TestObject.class, null, false);