The great invocation services rethink of 2002! Rearchitected the remote

method invocation services and converted everything to the new style.
Could this be my biggest checkin ever?


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1642 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-08-14 19:08:01 +00:00
parent 4481c5f835
commit e54a4d41f4
161 changed files with 6083 additions and 2805 deletions
@@ -1,5 +1,5 @@
//
// $Id: TestClient.java,v 1.8 2002/04/15 14:38:45 shaper Exp $
// $Id: TestClient.java,v 1.9 2002/08/14 19:07:59 mdb Exp $
package com.threerings.parlor;
@@ -99,35 +99,33 @@ public class TestClient
System.exit(0);
}
public void invitationReceived (int inviteId, String inviter,
GameConfig config)
public void invitationReceived (Invitation invite)
{
Log.info("Invitation received [inviteId=" + inviteId +
", inviter=" + inviter + ", config=" + config + "].");
Log.info("Invitation received [invite=" + invite + "].");
// accept the invitation. we're game...
_pardtr.accept(inviteId);
invite.accept();
}
public void invitationCancelled (int inviteId)
public void invitationCancelled (Invitation invite)
{
Log.info("Invitation cancelled [inviteId=" + inviteId + "].");
Log.info("Invitation cancelled [invite=" + invite + "].");
}
public void invitationAccepted (int inviteId)
public void invitationAccepted (Invitation invite)
{
Log.info("Invitation accepted [inviteId=" + inviteId + "].");
Log.info("Invitation accepted [invite=" + invite + "].");
}
public void invitationRefused (int inviteId, String message)
public void invitationRefused (Invitation invite, String message)
{
Log.info("Invitation refused [inviteId=" + inviteId +
Log.info("Invitation refused [invite=" + invite +
", message=" + message + "].");
}
public void invitationCountered (int inviteId, GameConfig config)
public void invitationCountered (Invitation invite, GameConfig config)
{
Log.info("Invitation countered [inviteId=" + inviteId +
Log.info("Invitation countered [invite=" + invite +
", config=" + config + "].");
}
@@ -1,5 +1,5 @@
//
// $Id: TestServer.java,v 1.4 2002/03/28 22:32:33 mdb Exp $
// $Id: TestServer.java,v 1.5 2002/08/14 19:07:59 mdb Exp $
package com.threerings.parlor;
@@ -23,7 +23,7 @@ public class TestServer extends CrowdServer
super.init();
// initialize our parlor manager
parmgr.init(invmgr);
parmgr.init(invmgr, plreg);
Log.info("Parlor server initialized.");
}
@@ -1,5 +1,5 @@
//
// $Id: TestClient.java,v 1.13 2002/02/09 20:47:11 mdb Exp $
// $Id: TestClient.java,v 1.14 2002/08/14 19:07:59 mdb Exp $
package com.threerings.presents.client;
@@ -14,7 +14,9 @@ import com.threerings.presents.server.TestObject;
* A standalone test client.
*/
public class TestClient
implements Client.Invoker, ClientObserver, Subscriber, EventListener
implements Client.Invoker, SessionObserver, Subscriber, EventListener,
TestService.TestFuncListener, TestService.TestOidListener,
TestReceiver
{
public void setClient (Client client)
{
@@ -39,29 +41,15 @@ public class TestClient
public void clientDidLogon (Client client)
{
Log.info("Client did logon [client=" + client + "].");
// register our test notification receiver
client.getInvocationDirector().registerReceiver(TestService.MODULE,
new TestReceiver());
// register ourselves as a test notification receiver
client.getInvocationDirector().registerReceiver(
new TestDecoder(this));
// get the test object id
TestService.getTestOid(client, this);
}
public void clientFailedToLogon (Client client, Exception cause)
{
Log.info("Client failed to logon [client=" + client +
", cause=" + cause + "].");
}
public void clientConnectionFailed (Client client, Exception cause)
{
Log.info("Client connection failed [client=" + client +
", cause=" + cause + "].");
}
public boolean clientWillLogoff (Client client)
{
Log.info("Client will logoff [client=" + client + "].");
return true;
TestService service = (TestService)
client.requireService(TestService.class);
service.getTestOid(client, this);
}
public void clientDidLogoff (Client client)
@@ -99,15 +87,30 @@ public class TestClient
}
}
public void handleTestSucceeded (int invid, String one, int two)
// documentation inherited from interface
public void testSucceeded (String one, int two)
{
Log.info("Got test response [one=" + one + ", two=" + two + "].");
}
public void handleGotTestOid (int invid, int oid)
// documentation inherited from interface
public void gotTestOid (int testOid)
{
// subscribe to the test object
_client.getDObjectManager().subscribeToObject(oid, this);
_client.getDObjectManager().subscribeToObject(testOid, this);
}
// documentation inherited from interface
public void requestFailed (String reason)
{
Log.info("Urk! Request failed [reason=" + reason + "].");
}
// documentation inherited from interface
public void receivedTest (int one, String two)
{
Log.info("Received test notification [one=" + one +
", two=" + two + "].");
}
public static void main (String[] args)
@@ -0,0 +1,52 @@
//
// $Id: TestDecoder.java,v 1.1 2002/08/14 19:07:59 mdb Exp $
package com.threerings.presents.client;
import com.threerings.presents.client.InvocationDecoder;
import com.threerings.presents.client.TestReceiver;
/**
* Dispatches calls to a {@link TestReceiver} instance.
*/
public class TestDecoder extends InvocationDecoder
{
/** The generated hash code used to identify this receiver class. */
public static final String RECEIVER_CODE = "b4b66d24b85d870d04c8da3524c188eb";
/** The method id used to dispatch {@link TestReceiver#receivedTest}
* notifications. */
public static final int RECEIVED_TEST = 1;
/**
* Creates a decoder that may be registered to dispatch invocation
* service notifications to the specified receiver.
*/
public TestDecoder (TestReceiver receiver)
{
this.receiver = receiver;
}
// documentation inherited
public String getReceiverCode ()
{
return RECEIVER_CODE;
}
// documentation inherited
public void dispatchNotification (int methodId, Object[] args)
{
switch (methodId) {
case RECEIVED_TEST:
((TestReceiver)receiver).receivedTest(
((Integer)args[0]).intValue(), (String)args[1]
);
return;
default:
super.dispatchNotification(methodId, args);
}
}
// Generated on 12:14:10 08/12/02.
}
@@ -1,15 +1,15 @@
//
// $Id: TestReceiver.java,v 1.5 2001/11/08 02:07:36 mdb Exp $
// $Id: TestReceiver.java,v 1.6 2002/08/14 19:07:59 mdb Exp $
package com.threerings.presents.client;
import com.threerings.presents.Log;
public class TestReceiver implements InvocationReceiver
/**
* A test of the invocation notification services.
*/
public interface TestReceiver extends InvocationReceiver
{
public void handleTestNotification (int invid, int one, String two)
{
Log.info("Received tell notification [invid=" + invid +
", one=" + one + ", two=" + two + "].");
}
/**
* Dispatches a test notification.
*/
public void receivedTest (int one, String two);
}
@@ -1,30 +1,31 @@
//
// $Id: TestService.java,v 1.5 2001/11/08 02:07:36 mdb Exp $
// $Id: TestService.java,v 1.6 2002/08/14 19:07:59 mdb Exp $
package com.threerings.presents.client;
import com.threerings.presents.Log;
/**
* A test of the invocation services.
*/
public class TestService
public interface TestService extends InvocationService
{
public static final String MODULE = "test";
public static void test (
Client client, String one, int two, Object rsptarget)
/** Used to dispatch responses to {@link #test} requests. */
public static interface TestFuncListener extends InvocationListener
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[] { one, new Integer(two) };
invdir.invoke(MODULE, "Test", args, rsptarget);
Log.info("Sent test request [one=" + one + ", two=" + two + "].");
/** Informs listener of successful {@link #test} request. */
public void testSucceeded (String one, int two);
}
public static void getTestOid (Client client, Object rsptarget)
/** Issues a test request. */
public void test (
Client client, String one, int two, TestFuncListener listener);
/** Used to dispatch responses to {@link #getTestOid} requests. */
public static interface TestOidListener extends InvocationListener
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[0];
invdir.invoke(MODULE, "GetTestOid", args, rsptarget);
/** Communicates test oid to listener. */
public void gotTestOid (int testOid);
}
/** Issues a request for the test oid. */
public void getTestOid (Client client, TestOidListener listener);
}
@@ -0,0 +1,112 @@
//
// $Id: TestMarshaller.java,v 1.1 2002/08/14 19:07:59 mdb Exp $
package com.threerings.presents.data;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.TestService;
import com.threerings.presents.client.TestService.TestFuncListener;
import com.threerings.presents.client.TestService.TestOidListener;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
/**
* Provides the implementation of the {@link TestService} interface
* that marshalls the arguments and delivers the request to the provider
* on the server. Also provides an implementation of the response listener
* interfaces that marshall the response arguments and deliver them back
* to the requesting client.
*/
public class TestMarshaller extends InvocationMarshaller
implements TestService
{
// documentation inherited
public static class TestFuncMarshaller extends ListenerMarshaller
implements TestFuncListener
{
/** The method id used to dispatch {@link #testSucceeded}
* responses. */
public static final int TEST_SUCCEEDED = 0;
// documentation inherited from interface
public void testSucceeded (String arg1, int arg2)
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, TEST_SUCCEEDED,
new Object[] { arg1, new Integer(arg2) }));
}
// documentation inherited
public void dispatchResponse (int methodId, Object[] args)
{
switch (methodId) {
case TEST_SUCCEEDED:
((TestFuncListener)listener).testSucceeded(
(String)args[0], ((Integer)args[1]).intValue());
return;
default:
super.dispatchResponse(methodId, args);
}
}
}
// documentation inherited
public static class TestOidMarshaller extends ListenerMarshaller
implements TestOidListener
{
/** The method id used to dispatch {@link #gotTestOid}
* responses. */
public static final int GOT_TEST_OID = 0;
// documentation inherited from interface
public void gotTestOid (int arg1)
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, GOT_TEST_OID,
new Object[] { new Integer(arg1) }));
}
// documentation inherited
public void dispatchResponse (int methodId, Object[] args)
{
switch (methodId) {
case GOT_TEST_OID:
((TestOidListener)listener).gotTestOid(
((Integer)args[0]).intValue());
return;
default:
super.dispatchResponse(methodId, args);
}
}
}
/** The method id used to dispatch {@link #test} requests. */
public static final int TEST = 1;
// documentation inherited from interface
public void test (Client arg1, String arg2, int arg3, TestFuncListener arg4)
{
TestFuncMarshaller listener4 = new TestFuncMarshaller();
listener4.listener = arg4;
sendRequest(arg1, TEST, new Object[] {
arg2, new Integer(arg3), listener4
});
}
/** The method id used to dispatch {@link #getTestOid} requests. */
public static final int GET_TEST_OID = 2;
// documentation inherited from interface
public void getTestOid (Client arg1, TestOidListener arg2)
{
TestOidMarshaller listener2 = new TestOidMarshaller();
listener2.listener = arg2;
sendRequest(arg1, GET_TEST_OID, new Object[] {
listener2
});
}
// Class file generated on 14:28:55 08/12/02.
}
@@ -0,0 +1,67 @@
//
// $Id: DSetTest.java,v 1.1 2002/08/14 19:08:00 mdb Exp $
package com.threerings.presents.dobj;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Tests the {@link DSet} class.
*/
public class DSetTest extends TestCase
{
public static class TestEntry implements DSet.Entry
{
public TestEntry (int value)
{
_value = new Integer(value);
}
public Comparable getKey ()
{
return _value;
}
public String toString ()
{
return _value.toString();
}
protected Integer _value;
}
public DSetTest ()
{
super(DSetTest.class.getName());
}
public void runTest ()
{
ArrayList seed = new ArrayList();
seed.add(new TestEntry(15));
seed.add(new TestEntry(7));
seed.add(new TestEntry(3));
seed.add(new TestEntry(29));
seed.add(new TestEntry(32));
DSet set = new DSet(seed.iterator());
System.out.println(set.add(new TestEntry(15)) + ": " + set);
System.out.println(set.add(new TestEntry(9)) + ": " + set);
System.out.println(set.remove(new TestEntry(32)) + ": " + set);
System.out.println(set.add(new TestEntry(32)) + ": " + set);
}
public static Test suite ()
{
return new DSetTest();
}
public static void main (String[] args)
{
DSetTest test = new DSetTest();
test.runTest();
}
}
@@ -0,0 +1,60 @@
//
// $Id: TestDispatcher.java,v 1.1 2002/08/14 19:08:00 mdb Exp $
package com.threerings.presents.server;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.TestService;
import com.threerings.presents.client.TestService.TestFuncListener;
import com.threerings.presents.client.TestService.TestOidListener;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.data.TestMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
/**
* Dispatches requests to the {@link TestProvider}.
*/
public class TestDispatcher extends InvocationDispatcher
{
/**
* Creates a dispatcher that may be registered to dispatch invocation
* service requests for the specified provider.
*/
public TestDispatcher (TestProvider provider)
{
this.provider = provider;
}
// documentation inherited
public InvocationMarshaller createMarshaller ()
{
return new TestMarshaller();
}
// documentation inherited
public void dispatchRequest (
ClientObject source, int methodId, Object[] args)
throws InvocationException
{
switch (methodId) {
case TestMarshaller.TEST:
((TestProvider)provider).test(
source,
(String)args[0], ((Integer)args[1]).intValue(), (TestFuncListener)args[2]
);
return;
case TestMarshaller.GET_TEST_OID:
((TestProvider)provider).getTestOid(
source,
(TestOidListener)args[0]
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
}
}
@@ -1,36 +1,38 @@
//
// $Id: TestProvider.java,v 1.10 2001/11/08 02:57:03 mdb Exp $
// $Id: TestProvider.java,v 1.11 2002/08/14 19:08:00 mdb Exp $
package com.threerings.presents.server;
import com.threerings.presents.Log;
import com.threerings.presents.client.TestService;
import com.threerings.presents.client.TestService.TestFuncListener;
import com.threerings.presents.client.TestService.TestOidListener;
import com.threerings.presents.data.ClientObject;
/**
* A test of the invocation services.
*/
public class TestProvider extends InvocationProvider
public class TestProvider implements InvocationProvider
{
public void handleTestRequest (
ClientObject source, int invid, String one, int two)
public void test (
ClientObject caller, String one, int two, TestFuncListener listener)
{
Log.info("Test request [one=" + one + ", two=" + two + "].");
// issue a test notification just for kicks
Object[] args = new Object[] { new Integer(1), "two" };
PresentsServer.invmgr.sendNotification(
source.getOid(), TestService.MODULE, "Test", args);
TestSender.sendTest(caller, 1, "two");
// and issue a response to this invocation request
sendResponse(source, invid, "TestSucceeded", one, new Integer(two));
listener.testSucceeded(one, two);
}
public void handleGetTestOidRequest (ClientObject source, int invid)
public void getTestOid (ClientObject caller, TestOidListener listener)
{
Log.info("Handling get test oid [src=" + source.getOid() +
", invid=" + invid + "].");
int oid = TestServer.testobj.getOid();
sendResponse(source, invid, "GotTestOid", new Integer(oid));
Log.info("Handling get test oid [src=" + caller + "].");
// issue a test notification just for kicks
TestSender.sendTest(caller, 1, "two");
listener.gotTestOid(TestServer.testobj.getOid());
}
}
@@ -0,0 +1,30 @@
//
// $Id: TestSender.java,v 1.1 2002/08/14 19:08:01 mdb Exp $
package com.threerings.presents.server;
import com.threerings.presents.client.TestDecoder;
import com.threerings.presents.client.TestReceiver;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationSender;
/**
* Used to issue notifications to a {@link TestReceiver} instance on a
* client.
*/
public class TestSender extends InvocationSender
{
/**
* Issues a notification that will result in a call to {@link
* TestReceiver#receivedTest} on a client.
*/
public static void sendTest (
ClientObject target, int arg1, String arg2)
{
sendNotification(
target, TestDecoder.RECEIVER_CODE, TestDecoder.RECEIVED_TEST,
new Object[] { new Integer(arg1), arg2 });
}
// Generated on 12:14:10 08/12/02.
}
@@ -1,5 +1,5 @@
//
// $Id: TestServer.java,v 1.8 2002/03/28 22:32:33 mdb Exp $
// $Id: TestServer.java,v 1.9 2002/08/14 19:08:01 mdb Exp $
package com.threerings.presents.server;
@@ -15,6 +15,9 @@ public class TestServer extends PresentsServer
{
super.init();
// register our test provider
invmgr.registerDispatcher(new TestDispatcher(new TestProvider()), true);
// create a test object
Subscriber sub = new Subscriber()
{