We love to revamp! Created a set of listener interfaces which are used
with distributed objects rather than having a single handleEvent() by which all subscribers are forced to hear about all events. Now one subscribes separately and then adds onesself as any of a few types of listener once they have access to the subscribed object reference. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@439 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: InvocationManager.java,v 1.8 2001/10/11 04:07:53 mdb Exp $
|
||||
// $Id: InvocationManager.java,v 1.9 2001/10/12 00:03:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.threerings.presents.util.ClassUtil;
|
||||
* the client.
|
||||
*/
|
||||
public class InvocationManager
|
||||
implements Subscriber
|
||||
implements Subscriber, MessageListener
|
||||
{
|
||||
public InvocationManager (DObjectManager omgr)
|
||||
{
|
||||
@@ -93,6 +93,9 @@ public class InvocationManager
|
||||
{
|
||||
// this must be our invocation object
|
||||
_invoid = object.getOid();
|
||||
|
||||
// add ourselves as a message listener
|
||||
object.addListener(this);
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
@@ -104,23 +107,15 @@ public class InvocationManager
|
||||
_invoid = -1;
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
public void messageReceived (MessageEvent event)
|
||||
{
|
||||
// we shouldn't be getting non-message events, but check just to
|
||||
// be sure
|
||||
if (!(event instanceof MessageEvent)) {
|
||||
Log.warning("Got non-message event!? [evt=" + event + "].");
|
||||
return true;
|
||||
}
|
||||
|
||||
// make sure the name is proper just for sanity's sake
|
||||
MessageEvent mevt = (MessageEvent)event;
|
||||
if (!mevt.getName().equals(InvocationObject.REQUEST_NAME)) {
|
||||
return true;
|
||||
if (!event.getName().equals(InvocationObject.REQUEST_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we've got an invocation request, so we process it
|
||||
Object[] args = mevt.getArgs();
|
||||
Object[] args = event.getArgs();
|
||||
String module = (String)args[0];
|
||||
String procedure = (String)args[1];
|
||||
Integer invid = (Integer)args[2];
|
||||
@@ -130,20 +125,20 @@ public class InvocationManager
|
||||
(InvocationProvider)_providers.get(module);
|
||||
if (provider == null) {
|
||||
Log.warning("No provider registered for invocation request " +
|
||||
"[evt=" + mevt + "].");
|
||||
return true;
|
||||
"[evt=" + event + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// prune the method arguments from the full message arguments
|
||||
Object[] margs = new Object[args.length-1];
|
||||
int cloid = mevt.getSourceOid();
|
||||
int cloid = event.getSourceOid();
|
||||
margs[0] = PresentsServer.omgr.getObject(cloid);
|
||||
// make sure the client is still around
|
||||
if (margs[0] == null) {
|
||||
Log.warning("Client no longer around for invocation provider " +
|
||||
"request [module=" + module +
|
||||
", proc=" + procedure + ", cloid=" + cloid + "].");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
System.arraycopy(args, 2, margs, 1, args.length-2);
|
||||
|
||||
@@ -154,7 +149,7 @@ public class InvocationManager
|
||||
Log.warning("Unable to resolve provider procedure " +
|
||||
"[provider=" + provider.getClass().getName() +
|
||||
", method=" + mname + "].");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// and invoke it
|
||||
@@ -166,8 +161,6 @@ public class InvocationManager
|
||||
", method=" + procmeth + "].");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected DObjectManager _omgr;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PresentsClient.java,v 1.20 2001/10/11 04:07:53 mdb Exp $
|
||||
// $Id: PresentsClient.java,v 1.21 2001/10/12 00:03:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -75,11 +75,6 @@ public class PresentsClient implements Subscriber, MessageHandler
|
||||
"[client=" + PresentsClient.this +
|
||||
", error=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Class clobjClass = _cmgr.getClientObjectClass();
|
||||
PresentsServer.omgr.createObject(clobjClass, sub, false);
|
||||
@@ -204,7 +199,13 @@ public class PresentsClient implements Subscriber, MessageHandler
|
||||
*/
|
||||
public synchronized void unmapSubscrip (int oid)
|
||||
{
|
||||
_subscrips.remove(oid);
|
||||
DObject object = (DObject)_subscrips.remove(oid);
|
||||
if (object != null) {
|
||||
object.removeListener(this);
|
||||
} else {
|
||||
Log.warning("Requested to unmap non-existent subscription " +
|
||||
"[oid=" + oid + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,6 +410,8 @@ public class PresentsClient implements Subscriber, MessageHandler
|
||||
// queue up an object response
|
||||
Connection conn = getConnection();
|
||||
if (conn != null) {
|
||||
// add ourselves as an event listener
|
||||
object.addListener(this);
|
||||
// pass the successful subscrip on to the client
|
||||
conn.postMessage(new ObjectResponse(object));
|
||||
// make a note of this new subscription
|
||||
@@ -434,7 +437,7 @@ public class PresentsClient implements Subscriber, MessageHandler
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
public void eventReceived (DEvent event)
|
||||
{
|
||||
// forward the event to the client
|
||||
Connection conn = getConnection();
|
||||
@@ -447,8 +450,6 @@ public class PresentsClient implements Subscriber, MessageHandler
|
||||
Log.info("Dropped event forward notification " +
|
||||
"[client=" + this + ", event=" + event + "].");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PresentsDObjectMgr.java,v 1.17 2001/10/11 04:07:53 mdb Exp $
|
||||
// $Id: PresentsDObjectMgr.java,v 1.18 2001/10/12 00:03:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -173,9 +173,9 @@ public class PresentsDObjectMgr implements DObjectManager
|
||||
|
||||
// if the event returns false from applyToObject, this
|
||||
// means it's a silent event and we shouldn't notify the
|
||||
// subscribers
|
||||
// listeners
|
||||
if (notify) {
|
||||
target.notifySubscribers(event);
|
||||
target.notifyListeners(event);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user