Added support for streaming List and ArrayList natively. A List will be
unmarshalled into an ArrayList on the receiver. Along the way, I improved support for generic types as arguments to invocation services (which required one unfortunate "sweeping" warning suppression, but since this is in generated code, I think we can be sure it won't be doing anything untoward). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4375 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.Queue;
|
||||
import com.samskivert.util.RunQueue;
|
||||
|
||||
@@ -36,8 +38,7 @@ import com.threerings.presents.net.*;
|
||||
*/
|
||||
public class TestClient
|
||||
implements RunQueue, SessionObserver, Subscriber<TestObject>, EventListener,
|
||||
TestService.TestFuncListener, TestService.TestOidListener,
|
||||
TestReceiver
|
||||
TestService.TestOidListener, TestReceiver
|
||||
{
|
||||
public void setClient (Client client)
|
||||
{
|
||||
@@ -71,12 +72,26 @@ public class TestClient
|
||||
Log.info("Client did logon [client=" + client + "].");
|
||||
|
||||
// register ourselves as a test notification receiver
|
||||
client.getInvocationDirector().registerReceiver(
|
||||
new TestDecoder(this));
|
||||
client.getInvocationDirector().registerReceiver(new TestDecoder(this));
|
||||
|
||||
// get the test object id
|
||||
TestService service = (TestService)
|
||||
client.requireService(TestService.class);
|
||||
|
||||
// send a test request
|
||||
ArrayList<Integer> three = new ArrayList<Integer>();
|
||||
three.add(3);
|
||||
three.add(4);
|
||||
three.add(5);
|
||||
service.test(client, "one", 2, three, new TestService.TestFuncListener() {
|
||||
public void testSucceeded (String one, int two) {
|
||||
Log.info("Got test response [one=" + one + ", two=" + two + "].");
|
||||
}
|
||||
public void requestFailed (String reason) {
|
||||
Log.info("Urk! Request failed [reason=" + reason + "].");
|
||||
}
|
||||
});
|
||||
|
||||
// get the test object id
|
||||
service.getTestOid(client, this);
|
||||
}
|
||||
|
||||
@@ -114,12 +129,6 @@ public class TestClient
|
||||
_client.logoff(true);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void testSucceeded (String one, int two)
|
||||
{
|
||||
Log.info("Got test response [one=" + one + ", two=" + two + "].");
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void gotTestOid (int testOid)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestService.java,v 1.7 2004/08/27 02:21:02 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A test of the invocation services.
|
||||
*/
|
||||
@@ -35,7 +37,8 @@ public interface TestService extends InvocationService
|
||||
|
||||
/** Issues a test request. */
|
||||
public void test (
|
||||
Client client, String one, int two, TestFuncListener listener);
|
||||
Client client, String one, int two, ArrayList<Integer> three,
|
||||
TestFuncListener listener);
|
||||
|
||||
/** Used to dispatch responses to {@link #getTestOid} requests. */
|
||||
public static interface TestOidListener extends InvocationListener
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// $Id: TestMarshaller.java,v 1.2 2004/08/27 02:21:03 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
@@ -23,10 +23,9 @@ 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;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link TestService} interface
|
||||
@@ -44,14 +43,15 @@ public class TestMarshaller extends InvocationMarshaller
|
||||
{
|
||||
/** The method id used to dispatch {@link #testSucceeded}
|
||||
* responses. */
|
||||
public static final int TEST_SUCCEEDED = 0;
|
||||
public static final int TEST_SUCCEEDED = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void testSucceeded (String arg1, int arg2)
|
||||
{
|
||||
_invId = null;
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, TEST_SUCCEEDED,
|
||||
new Object[] { arg1, new Integer(arg2) }));
|
||||
new Object[] { arg1, Integer.valueOf(arg2) }));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -65,6 +65,7 @@ public class TestMarshaller extends InvocationMarshaller
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,14 +76,15 @@ public class TestMarshaller extends InvocationMarshaller
|
||||
{
|
||||
/** The method id used to dispatch {@link #gotTestOid}
|
||||
* responses. */
|
||||
public static final int GOT_TEST_OID = 0;
|
||||
public static final int GOT_TEST_OID = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void gotTestOid (int arg1)
|
||||
{
|
||||
_invId = null;
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, GOT_TEST_OID,
|
||||
new Object[] { new Integer(arg1) }));
|
||||
new Object[] { Integer.valueOf(arg1) }));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -96,35 +98,35 @@ public class TestMarshaller extends InvocationMarshaller
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 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;
|
||||
public static final int GET_TEST_OID = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void getTestOid (Client arg1, TestOidListener arg2)
|
||||
public void getTestOid (Client arg1, TestService.TestOidListener arg2)
|
||||
{
|
||||
TestOidMarshaller listener2 = new TestOidMarshaller();
|
||||
TestMarshaller.TestOidMarshaller listener2 = new TestMarshaller.TestOidMarshaller();
|
||||
listener2.listener = arg2;
|
||||
sendRequest(arg1, GET_TEST_OID, new Object[] {
|
||||
listener2
|
||||
});
|
||||
}
|
||||
|
||||
// Class file generated on 14:28:55 08/12/02.
|
||||
/** The method id used to dispatch {@link #test} requests. */
|
||||
public static final int TEST = 2;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void test (Client arg1, String arg2, int arg3, ArrayList<java.lang.Integer> arg4, TestService.TestFuncListener arg5)
|
||||
{
|
||||
TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, TEST, new Object[] {
|
||||
arg2, Integer.valueOf(arg3), arg4, listener5
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
package com.threerings.presents.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.dobj.*;
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,9 @@ public class TestObject extends DObject
|
||||
|
||||
/** The field name of the <code>list</code> field. */
|
||||
public static final String LIST = "list";
|
||||
|
||||
/** The field name of the <code>longs</code> field. */
|
||||
public static final String LONGS = "longs";
|
||||
// AUTO-GENERATED: FIELDS END
|
||||
|
||||
public int foo;
|
||||
@@ -55,6 +60,8 @@ public class TestObject extends DObject
|
||||
|
||||
public OidList list = new OidList();
|
||||
|
||||
public ArrayList<Long> longs = new ArrayList<Long>();
|
||||
|
||||
// AUTO-GENERATED: METHODS START
|
||||
/**
|
||||
* Requests that the <code>foo</code> field be set to the
|
||||
@@ -68,7 +75,7 @@ public class TestObject extends DObject
|
||||
{
|
||||
int ovalue = this.foo;
|
||||
requestAttributeChange(
|
||||
FOO, new Integer(value), new Integer(ovalue));
|
||||
FOO, Integer.valueOf(value), Integer.valueOf(ovalue));
|
||||
this.foo = value;
|
||||
}
|
||||
|
||||
@@ -117,7 +124,7 @@ public class TestObject extends DObject
|
||||
{
|
||||
int ovalue = this.ints[index];
|
||||
requestElementUpdate(
|
||||
INTS, index, new Integer(value), new Integer(ovalue));
|
||||
INTS, index, Integer.valueOf(value), Integer.valueOf(ovalue));
|
||||
this.ints[index] = value;
|
||||
}
|
||||
|
||||
@@ -173,5 +180,21 @@ public class TestObject extends DObject
|
||||
{
|
||||
requestOidRemove(LIST, oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>longs</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
* event will be propagated through the system to notify all listeners
|
||||
* that the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setLongs (ArrayList<java.lang.Long> value)
|
||||
{
|
||||
ArrayList<java.lang.Long> ovalue = this.longs;
|
||||
requestAttributeChange(
|
||||
LONGS, value, ovalue);
|
||||
this.longs = value;
|
||||
}
|
||||
// AUTO-GENERATED: METHODS END
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// $Id: TestDispatcher.java,v 1.2 2004/08/27 02:21:04 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
@@ -21,15 +21,13 @@
|
||||
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link TestProvider}.
|
||||
@@ -51,28 +49,29 @@ public class TestDispatcher extends InvocationDispatcher
|
||||
return new TestMarshaller();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@SuppressWarnings("unchecked") // 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]
|
||||
(TestService.TestOidListener)args[0]
|
||||
);
|
||||
return;
|
||||
|
||||
case TestMarshaller.TEST:
|
||||
((TestProvider)provider).test(
|
||||
source,
|
||||
(String)args[0], ((Integer)args[1]).intValue(), (ArrayList<java.lang.Integer>)args[2], (TestService.TestFuncListener)args[3]
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
|
||||
/**
|
||||
* Implements the server side of the TestProvider interface.
|
||||
*/
|
||||
public class TestManager
|
||||
implements TestProvider
|
||||
{
|
||||
// from interface TestProvider
|
||||
public void getTestOid (ClientObject caller,
|
||||
TestService.TestOidListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
// from interface TestProvider
|
||||
public void test (ClientObject caller, String one, int two,
|
||||
ArrayList<Integer> three, TestService.TestFuncListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
Log.info("Test request [one=" + one + ", two=" + two +
|
||||
", three=" + StringUtil.toString(three) + "].");
|
||||
|
||||
// and issue a response to this invocation request
|
||||
listener.testSucceeded(one, two);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// $Id: TestProvider.java,v 1.12 2004/08/27 02:21:04 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
@@ -21,36 +21,26 @@
|
||||
|
||||
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;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.presents.server.InvocationProvider;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A test of the invocation services.
|
||||
* Defines the server-side of the {@link TestService}.
|
||||
*/
|
||||
public class TestProvider implements InvocationProvider
|
||||
public interface TestProvider extends InvocationProvider
|
||||
{
|
||||
public void test (
|
||||
ClientObject caller, String one, int two, TestFuncListener listener)
|
||||
{
|
||||
Log.info("Test request [one=" + one + ", two=" + two + "].");
|
||||
/**
|
||||
* Handles a {@link TestService#getTestOid} request.
|
||||
*/
|
||||
public void getTestOid (ClientObject caller, TestService.TestOidListener arg1)
|
||||
throws InvocationException;
|
||||
|
||||
// issue a test notification just for kicks
|
||||
TestSender.sendTest(caller, 1, "two");
|
||||
|
||||
// and issue a response to this invocation request
|
||||
listener.testSucceeded(one, two);
|
||||
}
|
||||
|
||||
public void getTestOid (ClientObject caller, TestOidListener listener)
|
||||
{
|
||||
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());
|
||||
}
|
||||
/**
|
||||
* Handles a {@link TestService#test} request.
|
||||
*/
|
||||
public void test (ClientObject caller, String arg1, int arg2, ArrayList<java.lang.Integer> arg3, TestService.TestFuncListener arg4)
|
||||
throws InvocationException;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,14 @@ public class TestServer extends PresentsServer
|
||||
super.init();
|
||||
|
||||
// register our test provider
|
||||
invmgr.registerDispatcher(new TestDispatcher(new TestProvider()), true);
|
||||
invmgr.registerDispatcher(new TestDispatcher(new TestManager()), true);
|
||||
|
||||
// create a test object
|
||||
testobj = omgr.registerObject(new TestObject());
|
||||
testobj.longs.add(System.currentTimeMillis());
|
||||
long value = Integer.MAX_VALUE;
|
||||
value++;
|
||||
testobj.longs.add(value);
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
|
||||
Reference in New Issue
Block a user