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:
Michael Bayne
2006-09-19 00:31:50 +00:00
parent 036271438a
commit afad7dd444
15 changed files with 271 additions and 131 deletions
@@ -24,6 +24,9 @@ package com.threerings.io;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/** /**
* Code to read and write basic object types (like arrays of primitives, * Code to read and write basic object types (like arrays of primitives,
* {@link Integer} instances, {@link Double} instances, etc.). * {@link Integer} instances, {@link Double} instances, etc.).
@@ -50,6 +53,8 @@ public class BasicStreamers
float[].class, float[].class,
double[].class, double[].class,
Object[].class, Object[].class,
List.class,
ArrayList.class,
}; };
/** An array of instances of all of the basic streamers. */ /** An array of instances of all of the basic streamers. */
@@ -72,6 +77,8 @@ public class BasicStreamers
new FloatArrayStreamer(), new FloatArrayStreamer(),
new DoubleArrayStreamer(), new DoubleArrayStreamer(),
new ObjectArrayStreamer(), new ObjectArrayStreamer(),
new ListStreamer(),
new ListStreamer(),
}; };
/** Streams {@link Boolean} instances. */ /** Streams {@link Boolean} instances. */
@@ -643,4 +650,42 @@ public class BasicStreamers
} }
} }
} }
/** Streams {@link List} instances. */
public static class ListStreamer extends Streamer
{
// documentation inherited
public Object createObject (ObjectInputStream in)
throws IOException
{
return new ArrayList();
}
// documentation inherited
public void writeObject (
Object object, ObjectOutputStream out, boolean useWriter)
throws IOException
{
List list = (List)object;
int ecount = list.size();
out.writeInt(ecount);
for (int ii = 0; ii < ecount; ii++) {
out.writeObject(list.get(ii));
}
}
// documentation inherited
public void readObject (
Object object, ObjectInputStream in, boolean useReader)
throws IOException, ClassNotFoundException
{
@SuppressWarnings("unchecked") ArrayList<Object> value =
(ArrayList<Object>)object;
int ecount = in.readInt();
value.ensureCapacity(ecount);
for (int ii = 0; ii < ecount; ii++) {
value.add(in.readObject());
}
}
}
} }
@@ -266,7 +266,7 @@ public class GenDObjectTask extends Task
// if this field is an array, we need its component types // if this field is an array, we need its component types
if (ftype.isArray()) { if (ftype.isArray()) {
Class<?> etype = ftype.getComponentType(); Class<?> etype = ftype.getComponentType();
ctx.put("elemtype", GenUtil.simpleName(etype)); ctx.put("elemtype", GenUtil.simpleName(etype, null));
ctx.put("wrapelem", GenUtil.boxArgument(etype, "value")); ctx.put("wrapelem", GenUtil.boxArgument(etype, "value"));
ctx.put("wrapoelem", GenUtil.boxArgument(etype, "ovalue")); ctx.put("wrapoelem", GenUtil.boxArgument(etype, "ovalue"));
} }
@@ -283,7 +283,8 @@ public class GenDObjectTask extends Task
ParameterizedType pt = (ParameterizedType)t; ParameterizedType pt = (ParameterizedType)t;
if (pt.getActualTypeArguments().length > 0) { if (pt.getActualTypeArguments().length > 0) {
ctx.put("etype", GenUtil.simpleName( ctx.put("etype", GenUtil.simpleName(
(Class<?>)pt.getActualTypeArguments()[0])); (Class<?>)pt.getActualTypeArguments()[0],
null));
} }
} else { } else {
ctx.put("etype", "DSet.Entry"); ctx.put("etype", "DSet.Entry");
@@ -74,7 +74,7 @@ public class GenServiceTask extends InvocationTask
public String getName () public String getName ()
{ {
String name = GenUtil.simpleName(listener); String name = GenUtil.simpleName(listener, null);
name = StringUtil.replace(name, "Listener", ""); name = StringUtil.replace(name, "Listener", "");
int didx = name.indexOf("."); int didx = name.indexOf(".");
return name.substring(didx+1); return name.substring(didx+1);
@@ -140,7 +140,8 @@ public class GenServiceTask extends InvocationTask
Class[] args = m.getParameterTypes(); Class[] args = m.getParameterTypes();
for (int aa = 0; aa < args.length; aa++) { for (int aa = 0; aa < args.length; aa++) {
if (_ilistener.isAssignableFrom(args[aa]) && if (_ilistener.isAssignableFrom(args[aa]) &&
GenUtil.simpleName(args[aa]).startsWith(sname + ".")) { GenUtil.simpleName(
args[aa], null).startsWith(sname + ".")) {
checkedAdd(listeners, new ServiceListener( checkedAdd(listeners, new ServiceListener(
service, args[aa], imports)); service, args[aa], imports));
} }
@@ -29,6 +29,7 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType; import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -50,8 +51,8 @@ public class GenUtil
Pattern.compile("^\\s*public\\s+(interface|class)\\s+(\\S+)(\\W|$)"); Pattern.compile("^\\s*public\\s+(interface|class)\\s+(\\S+)(\\W|$)");
/** /**
* Returns the name of the supplied class as it would likely appear in * Returns the name of the supplied class as it would likely appear in code
* code using the class (no package prefix, arrays specified as * using the class (no package prefix, arrays specified as
* <code>type[]</code>). * <code>type[]</code>).
*/ */
public static String simpleName (Field field) public static String simpleName (Field field)
@@ -64,7 +65,8 @@ public class GenUtil
field.getGenericType(); field.getGenericType();
cname = atype.getGenericComponentType().toString(); cname = atype.getGenericComponentType().toString();
} else { } else {
return simpleName(clazz.getComponentType()) + "[]"; return simpleName(clazz.getComponentType(),
field.getGenericType()) + "[]";
} }
} else if (field.getGenericType() instanceof ParameterizedType) { } else if (field.getGenericType() instanceof ParameterizedType) {
cname = field.getGenericType().toString(); cname = field.getGenericType().toString();
@@ -78,18 +80,22 @@ public class GenUtil
} }
/** /**
* Returns the name of the supplied class as it would likely appear in * Returns the name of the supplied class as it would likely appear in code
* code using the class (no package prefix, arrays specified as * using the class (no package prefix, arrays specified as
* <code>type[]</code>). * <code>type[]</code>).
*/ */
public static String simpleName (Class<?> clazz) public static String simpleName (Class<?> clazz, Type type)
{ {
if (clazz.isArray()) { if (clazz.isArray()) {
return simpleName(clazz.getComponentType()) + "[]"; return simpleName(clazz.getComponentType(), type) + "[]";
} else { } else {
String cname = clazz.getName();
if (type instanceof ParameterizedType) {
cname = type.toString();
}
Package pkg = clazz.getPackage(); Package pkg = clazz.getPackage();
int offset = (pkg == null) ? 0 : pkg.getName().length()+1; int offset = (pkg == null) ? 0 : pkg.getName().length()+1;
String name = clazz.getName().substring(offset); String name = cname.substring(offset);
return StringUtil.replace(name, "$", "."); return StringUtil.replace(name, "$", ".");
} }
} }
@@ -122,10 +128,10 @@ public class GenUtil
} }
/** /**
* "Unboxes" the supplied argument, ie. turning an * "Unboxes" the supplied argument, ie. turning an <code>Integer</code>
* <code>Integer</code> object into an <code>int</code>. * object into an <code>int</code>.
*/ */
public static String unboxArgument (Class<?> clazz, String name) public static String unboxArgument (Class<?> clazz, Type type, String name)
{ {
if (clazz == Boolean.TYPE) { if (clazz == Boolean.TYPE) {
return "((Boolean)" + name + ").booleanValue()"; return "((Boolean)" + name + ").booleanValue()";
@@ -144,7 +150,7 @@ public class GenUtil
} else if (clazz == Double.TYPE) { } else if (clazz == Double.TYPE) {
return "((Double)" + name + ").doubleValue()"; return "((Double)" + name + ").doubleValue()";
} else { } else {
return "(" + simpleName(clazz) + ")" + name + ""; return "(" + simpleName(clazz, type) + ")" + name + "";
} }
} }
@@ -8,6 +8,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -54,7 +55,7 @@ public abstract class InvocationTask extends Task
public String getMarshaller () public String getMarshaller ()
{ {
String name = GenUtil.simpleName(listener); String name = GenUtil.simpleName(listener, null);
// handle ye olde special case // handle ye olde special case
if (name.equals("InvocationService.InvocationListener")) { if (name.equals("InvocationService.InvocationListener")) {
return "ListenerMarshaller"; return "ListenerMarshaller";
@@ -106,7 +107,8 @@ public abstract class InvocationTask extends Task
// InvocationService listeners, we need to import its // InvocationService listeners, we need to import its
// marshaller as well // marshaller as well
if (_ilistener.isAssignableFrom(arg) && if (_ilistener.isAssignableFrom(arg) &&
!GenUtil.simpleName(arg).startsWith("InvocationService")) { !GenUtil.simpleName(
arg, null).startsWith("InvocationService")) {
String mname = arg.getName(); String mname = arg.getName();
mname = StringUtil.replace(mname, "Service", "Marshaller"); mname = StringUtil.replace(mname, "Service", "Marshaller");
mname = StringUtil.replace(mname, "Listener", "Marshaller"); mname = StringUtil.replace(mname, "Listener", "Marshaller");
@@ -135,11 +137,12 @@ public abstract class InvocationTask extends Task
{ {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
Class<?>[] args = method.getParameterTypes(); Class<?>[] args = method.getParameterTypes();
Type[] ptypes = method.getGenericParameterTypes();
for (int ii = skipFirst ? 1 : 0; ii < args.length; ii++) { for (int ii = skipFirst ? 1 : 0; ii < args.length; ii++) {
if (buf.length() > 0) { if (buf.length() > 0) {
buf.append(", "); buf.append(", ");
} }
buf.append(GenUtil.simpleName(args[ii])); buf.append(GenUtil.simpleName(args[ii], ptypes[ii]));
buf.append(" arg").append(skipFirst ? ii : ii+1); buf.append(" arg").append(skipFirst ? ii : ii+1);
} }
return buf.toString(); return buf.toString();
@@ -172,12 +175,13 @@ public abstract class InvocationTask extends Task
{ {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
Class<?>[] args = method.getParameterTypes(); Class<?>[] args = method.getParameterTypes();
Type[] ptypes = method.getGenericParameterTypes();
for (int ii = (listenerMode ? 0 : 1); ii < args.length; ii++) { for (int ii = (listenerMode ? 0 : 1); ii < args.length; ii++) {
if (buf.length() > 0) { if (buf.length() > 0) {
buf.append(", "); buf.append(", ");
} }
buf.append(unboxArgument(args[ii], listenerMode ? ii : ii-1, buf.append(unboxArgument(args[ii], ptypes[ii],
listenerMode)); listenerMode ? ii : ii-1, listenerMode));
} }
return buf.toString(); return buf.toString();
} }
@@ -192,12 +196,13 @@ public abstract class InvocationTask extends Task
} }
protected String unboxArgument ( protected String unboxArgument (
Class<?> clazz, int index, boolean listenerMode) Class<?> clazz, Type type, int index, boolean listenerMode)
{ {
if (listenerMode && _ilistener.isAssignableFrom(clazz)) { if (listenerMode && _ilistener.isAssignableFrom(clazz)) {
return "listener" + index; return "listener" + index;
} else { } else {
return GenUtil.unboxArgument(clazz, "args[" + index + "]"); return GenUtil.unboxArgument(
clazz, type, "args[" + index + "]");
} }
} }
} }
@@ -18,13 +18,13 @@ public class ${name}Dispatcher extends InvocationDispatcher
this.provider = provider; this.provider = provider;
} }
// documentation inherited // from InvocationDispatcher
public InvocationMarshaller createMarshaller () public InvocationMarshaller createMarshaller ()
{ {
return new ${name}Marshaller(); return new ${name}Marshaller();
} }
// documentation inherited @SuppressWarnings("unchecked") // from InvocationDispatcher
public void dispatchRequest ( public void dispatchRequest (
ClientObject source, int methodId, Object[] args) ClientObject source, int methodId, Object[] args)
throws InvocationException throws InvocationException
+32 -24
View File
@@ -28,8 +28,7 @@
classpathref="classpath"/> classpathref="classpath"/>
<!-- make sure the dobject class files are all compiled --> <!-- make sure the dobject class files are all compiled -->
<javac srcdir="src/java" destdir="${classes.dir}" <javac srcdir="src/java" destdir="${classes.dir}"
debug="on" optimize="${build.optimize}" deprecation="on" debug="on" deprecation="on" source="1.5" target="1.5">
source="1.4" target="1.4">
<classpath refid="classpath"/> <classpath refid="classpath"/>
<include name="**/*Object.java"/> <include name="**/*Object.java"/>
</javac> </javac>
@@ -39,30 +38,39 @@
</dobj> </dobj>
</target> </target>
<!-- generates marshaller and dispatcher classes for all invocation <!-- generates marshaller and dispatcher classes for all invocation -->
service declarations --> <!-- service declarations -->
<target name="genservice"> <target name="genservice">
<apply executable="../bin/genservice" failonerror="true" parallel="true"> <taskdef name="service" classpathref="classpath"
<arg value="--classpath"/> classname="com.threerings.presents.tools.GenServiceTask"/>
<arg value="${classes.dir}:${narya.classes.dir}"/> <!-- make sure the service class files are all compiled -->
<arg value="--sourcedir"/> <javac srcdir="src/java" destdir="${classes.dir}" debug="on"
<arg value="src/java"/> deprecation="on" source="1.5" target="1.5">
<fileset dir="src/java" includes="**/*Service.java" <classpath refid="classpath"/>
excludes="**/InvocationService.java"/> <include name="**/*Service.java"/>
</apply> </javac>
<!-- now generate the associated files -->
<service header="../lib/SOURCE_HEADER" classpathref="classpath">
<fileset dir="src/java" includes="**/*Service.java"/>
</service>
</target> </target>
<!-- generates sender and decoder classes for all invocation <!-- generates sender and decoder classes for all invocation -->
receiver declarations --> <!-- receiver declarations -->
<target name="genreceiver"> <target name="genreceiver">
<apply executable="../bin/genreceiver" failonerror="true" parallel="true"> <taskdef name="receiver" classpathref="classpath"
<arg value="--classpath"/> classname="com.threerings.presents.tools.GenReceiverTask"/>
<arg value="${classes.dir}:${narya.classes.dir}"/> <!-- make sure the receiver class files are all compiled -->
<arg value="--sourcedir"/> <javac srcdir="src/java" destdir="${classes.dir}"
<arg value="src/java"/> debug="on" deprecation="on" source="1.5" target="1.5">
<fileset dir="src/java" includes="**/*Receiver.java" <classpath refid="classpath"/>
excludes="**/InvocationReceiver.java"/> <include name="**/*Receiver.java"/>
</apply> <exclude name="**/InvocationReceiver.java"/>
</javac>
<!-- now generate the associated files -->
<receiver header="../lib/SOURCE_HEADER" classpathref="classpath">
<fileset dir="src/java" includes="**/*Receiver.java"/>
</receiver>
</target> </target>
<!-- prepares the application directories --> <!-- prepares the application directories -->
@@ -21,6 +21,8 @@
package com.threerings.presents.client; package com.threerings.presents.client;
import java.util.ArrayList;
import com.samskivert.util.Queue; import com.samskivert.util.Queue;
import com.samskivert.util.RunQueue; import com.samskivert.util.RunQueue;
@@ -36,8 +38,7 @@ import com.threerings.presents.net.*;
*/ */
public class TestClient public class TestClient
implements RunQueue, SessionObserver, Subscriber<TestObject>, EventListener, implements RunQueue, SessionObserver, Subscriber<TestObject>, EventListener,
TestService.TestFuncListener, TestService.TestOidListener, TestService.TestOidListener, TestReceiver
TestReceiver
{ {
public void setClient (Client client) public void setClient (Client client)
{ {
@@ -71,12 +72,26 @@ public class TestClient
Log.info("Client did logon [client=" + client + "]."); Log.info("Client did logon [client=" + client + "].");
// register ourselves as a test notification receiver // register ourselves as a test notification receiver
client.getInvocationDirector().registerReceiver( client.getInvocationDirector().registerReceiver(new TestDecoder(this));
new TestDecoder(this));
// get the test object id
TestService service = (TestService) TestService service = (TestService)
client.requireService(TestService.class); 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); service.getTestOid(client, this);
} }
@@ -114,12 +129,6 @@ public class TestClient
_client.logoff(true); _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 // documentation inherited from interface
public void gotTestOid (int testOid) 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 // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -21,6 +21,8 @@
package com.threerings.presents.client; package com.threerings.presents.client;
import java.util.ArrayList;
/** /**
* A test of the invocation services. * A test of the invocation services.
*/ */
@@ -35,7 +37,8 @@ public interface TestService extends InvocationService
/** Issues a test request. */ /** Issues a test request. */
public void test ( 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. */ /** Used to dispatch responses to {@link #getTestOid} requests. */
public static interface TestOidListener extends InvocationListener 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 // 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/ // http://www.threerings.net/code/narya/
// //
// This library is free software; you can redistribute it and/or modify it // 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.Client;
import com.threerings.presents.client.TestService; 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.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent; import com.threerings.presents.dobj.InvocationResponseEvent;
import java.util.ArrayList;
/** /**
* Provides the implementation of the {@link TestService} interface * 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} /** The method id used to dispatch {@link #testSucceeded}
* responses. */ * responses. */
public static final int TEST_SUCCEEDED = 0; public static final int TEST_SUCCEEDED = 1;
// documentation inherited from interface // documentation inherited from interface
public void testSucceeded (String arg1, int arg2) public void testSucceeded (String arg1, int arg2)
{ {
_invId = null;
omgr.postEvent(new InvocationResponseEvent( omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, TEST_SUCCEEDED, callerOid, requestId, TEST_SUCCEEDED,
new Object[] { arg1, new Integer(arg2) })); new Object[] { arg1, Integer.valueOf(arg2) }));
} }
// documentation inherited // documentation inherited
@@ -65,6 +65,7 @@ public class TestMarshaller extends InvocationMarshaller
default: default:
super.dispatchResponse(methodId, args); super.dispatchResponse(methodId, args);
return;
} }
} }
} }
@@ -75,14 +76,15 @@ public class TestMarshaller extends InvocationMarshaller
{ {
/** The method id used to dispatch {@link #gotTestOid} /** The method id used to dispatch {@link #gotTestOid}
* responses. */ * responses. */
public static final int GOT_TEST_OID = 0; public static final int GOT_TEST_OID = 1;
// documentation inherited from interface // documentation inherited from interface
public void gotTestOid (int arg1) public void gotTestOid (int arg1)
{ {
_invId = null;
omgr.postEvent(new InvocationResponseEvent( omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, GOT_TEST_OID, callerOid, requestId, GOT_TEST_OID,
new Object[] { new Integer(arg1) })); new Object[] { Integer.valueOf(arg1) }));
} }
// documentation inherited // documentation inherited
@@ -96,35 +98,35 @@ public class TestMarshaller extends InvocationMarshaller
default: default:
super.dispatchResponse(methodId, args); 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. */ /** 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 // 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; listener2.listener = arg2;
sendRequest(arg1, GET_TEST_OID, new Object[] { sendRequest(arg1, GET_TEST_OID, new Object[] {
listener2 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; package com.threerings.presents.data;
import java.util.ArrayList;
import com.threerings.presents.dobj.*; import com.threerings.presents.dobj.*;
/** /**
@@ -43,6 +45,9 @@ public class TestObject extends DObject
/** The field name of the <code>list</code> field. */ /** The field name of the <code>list</code> field. */
public static final String LIST = "list"; 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 // AUTO-GENERATED: FIELDS END
public int foo; public int foo;
@@ -55,6 +60,8 @@ public class TestObject extends DObject
public OidList list = new OidList(); public OidList list = new OidList();
public ArrayList<Long> longs = new ArrayList<Long>();
// AUTO-GENERATED: METHODS START // AUTO-GENERATED: METHODS START
/** /**
* Requests that the <code>foo</code> field be set to the * Requests that the <code>foo</code> field be set to the
@@ -68,7 +75,7 @@ public class TestObject extends DObject
{ {
int ovalue = this.foo; int ovalue = this.foo;
requestAttributeChange( requestAttributeChange(
FOO, new Integer(value), new Integer(ovalue)); FOO, Integer.valueOf(value), Integer.valueOf(ovalue));
this.foo = value; this.foo = value;
} }
@@ -117,7 +124,7 @@ public class TestObject extends DObject
{ {
int ovalue = this.ints[index]; int ovalue = this.ints[index];
requestElementUpdate( requestElementUpdate(
INTS, index, new Integer(value), new Integer(ovalue)); INTS, index, Integer.valueOf(value), Integer.valueOf(ovalue));
this.ints[index] = value; this.ints[index] = value;
} }
@@ -173,5 +180,21 @@ public class TestObject extends DObject
{ {
requestOidRemove(LIST, oid); 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 // 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 // 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/ // http://www.threerings.net/code/narya/
// //
// This library is free software; you can redistribute it and/or modify it // This library is free software; you can redistribute it and/or modify it
@@ -21,15 +21,13 @@
package com.threerings.presents.server; package com.threerings.presents.server;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.TestService; 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.ClientObject;
import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.data.TestMarshaller; import com.threerings.presents.data.TestMarshaller;
import com.threerings.presents.server.InvocationDispatcher; import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import java.util.ArrayList;
/** /**
* Dispatches requests to the {@link TestProvider}. * Dispatches requests to the {@link TestProvider}.
@@ -51,28 +49,29 @@ public class TestDispatcher extends InvocationDispatcher
return new TestMarshaller(); return new TestMarshaller();
} }
// documentation inherited @SuppressWarnings("unchecked") // documentation inherited
public void dispatchRequest ( public void dispatchRequest (
ClientObject source, int methodId, Object[] args) ClientObject source, int methodId, Object[] args)
throws InvocationException throws InvocationException
{ {
switch (methodId) { 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: case TestMarshaller.GET_TEST_OID:
((TestProvider)provider).getTestOid( ((TestProvider)provider).getTestOid(
source, 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; return;
default: default:
super.dispatchRequest(source, methodId, args); 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 // 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/ // http://www.threerings.net/code/narya/
// //
// This library is free software; you can redistribute it and/or modify it // This library is free software; you can redistribute it and/or modify it
@@ -21,36 +21,26 @@
package com.threerings.presents.server; package com.threerings.presents.server;
import com.threerings.presents.Log;
import com.threerings.presents.client.TestService; 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.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) * Handles a {@link TestService#getTestOid} request.
{ */
Log.info("Test request [one=" + one + ", two=" + two + "]."); public void getTestOid (ClientObject caller, TestService.TestOidListener arg1)
throws InvocationException;
// issue a test notification just for kicks /**
TestSender.sendTest(caller, 1, "two"); * Handles a {@link TestService#test} request.
*/
// and issue a response to this invocation request public void test (ClientObject caller, String arg1, int arg2, ArrayList<java.lang.Integer> arg3, TestService.TestFuncListener arg4)
listener.testSucceeded(one, two); throws InvocationException;
}
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());
}
} }
@@ -35,10 +35,14 @@ public class TestServer extends PresentsServer
super.init(); super.init();
// register our test provider // register our test provider
invmgr.registerDispatcher(new TestDispatcher(new TestProvider()), true); invmgr.registerDispatcher(new TestDispatcher(new TestManager()), true);
// create a test object // create a test object
testobj = omgr.registerObject(new TestObject()); 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) public static void main (String[] args)