Revamped distributed object creation. There was no particular reason to create

distributed objects by reflection since we don't allow clients to create
objects, furthermore we needn't do it asynchronously. The object creation
methods were moved into the server-side only interface and made "immediate", so
the caller creates a derived instance of DObject and registers it with the
system instead of creating it with a Subscriber callback.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4342 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-08-23 23:46:48 +00:00
parent 1f204669c4
commit bc9f53396c
19 changed files with 304 additions and 589 deletions
@@ -21,8 +21,6 @@
package com.threerings.presents.server;
import java.util.ArrayList;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.StringUtil;
@@ -41,7 +39,6 @@ import com.threerings.presents.dobj.EventListener;
import com.threerings.presents.dobj.InvocationRequestEvent;
import com.threerings.presents.dobj.ObjectAccessException;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.dobj.Subscriber;
/**
* The invocation services provide client to server invocations (service
@@ -65,7 +62,7 @@ import com.threerings.presents.dobj.Subscriber;
* the client.
*/
public class InvocationManager
implements Subscriber<DObject>, EventListener
implements EventListener
{
/** The list of services that are to be provided to clients at boot
* time. Don't mess with this list! */
@@ -83,9 +80,16 @@ public class InvocationManager
_omgr = omgr;
// create the object on which we'll listen for invocation requests
omgr.createObject(DObject.class, this);
DObject invobj = omgr.registerObject(new DObject());
invobj.addListener(this);
_invoid = invobj.getOid();
// Log.info("Created invocation service object [oid=" + _invoid + "].");
}
/**
* Returns the object id of the invocation services object.
*/
public int getOid ()
{
return _invoid;
@@ -111,13 +115,6 @@ public class InvocationManager
InvocationMarshaller marsh = dispatcher.createMarshaller();
marsh.init(_invoid, invCode);
// if we haven't yet finished our own initialization, we need to
// throw this dispatcher on a queue so that we can fill in its
// invocation oid when we know what it should be
if (_invoid == -1) {
_lateInitQueue.add(marsh);
}
// register the dispatcher
_dispatchers.put(invCode, dispatcher);
@@ -165,32 +162,6 @@ public class InvocationManager
return (dispatcher == null) ? null : dispatcher.getClass();
}
public void objectAvailable (DObject object)
{
// this must be our invocation object
_invoid = object.getOid();
// add ourselves as a message listener
object.addListener(this);
// let any early registered marshallers know about our invoid
while (_lateInitQueue.size() > 0) {
InvocationMarshaller marsh = _lateInitQueue.remove(0);
marsh.setInvocationOid(_invoid);
}
// Log.info("Created invocation service object [oid=" + _invoid + "].");
}
public void requestFailed (int oid, ObjectAccessException cause)
{
// if for some reason we were unable to create our invocation
// object, we'll end up here
Log.warning("Unable to create invocation object " +
"[reason=" + cause + "].");
_invoid = -1;
}
// documentation inherited from interface
public void eventReceived (DEvent event)
{
@@ -314,12 +285,6 @@ public class InvocationManager
protected HashIntMap<InvocationDispatcher> _dispatchers =
new HashIntMap<InvocationDispatcher>();
/** Used to keep track of marshallers registered before we had our
* invocation object so that we can fill their invocation id in
* belatedly. */
protected ArrayList<InvocationMarshaller> _lateInitQueue =
new ArrayList<InvocationMarshaller>();
/** The text that is appended to the procedure name when automatically
* generating a failure response. */
protected static final String FAILED_SUFFIX = "Failed";