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:
@@ -24,6 +24,9 @@ package com.threerings.io;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Code to read and write basic object types (like arrays of primitives,
|
||||
* {@link Integer} instances, {@link Double} instances, etc.).
|
||||
@@ -50,6 +53,8 @@ public class BasicStreamers
|
||||
float[].class,
|
||||
double[].class,
|
||||
Object[].class,
|
||||
List.class,
|
||||
ArrayList.class,
|
||||
};
|
||||
|
||||
/** An array of instances of all of the basic streamers. */
|
||||
@@ -72,6 +77,8 @@ public class BasicStreamers
|
||||
new FloatArrayStreamer(),
|
||||
new DoubleArrayStreamer(),
|
||||
new ObjectArrayStreamer(),
|
||||
new ListStreamer(),
|
||||
new ListStreamer(),
|
||||
};
|
||||
|
||||
/** 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 (ftype.isArray()) {
|
||||
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("wrapoelem", GenUtil.boxArgument(etype, "ovalue"));
|
||||
}
|
||||
@@ -283,7 +283,8 @@ public class GenDObjectTask extends Task
|
||||
ParameterizedType pt = (ParameterizedType)t;
|
||||
if (pt.getActualTypeArguments().length > 0) {
|
||||
ctx.put("etype", GenUtil.simpleName(
|
||||
(Class<?>)pt.getActualTypeArguments()[0]));
|
||||
(Class<?>)pt.getActualTypeArguments()[0],
|
||||
null));
|
||||
}
|
||||
} else {
|
||||
ctx.put("etype", "DSet.Entry");
|
||||
|
||||
@@ -74,7 +74,7 @@ public class GenServiceTask extends InvocationTask
|
||||
|
||||
public String getName ()
|
||||
{
|
||||
String name = GenUtil.simpleName(listener);
|
||||
String name = GenUtil.simpleName(listener, null);
|
||||
name = StringUtil.replace(name, "Listener", "");
|
||||
int didx = name.indexOf(".");
|
||||
return name.substring(didx+1);
|
||||
@@ -140,7 +140,8 @@ public class GenServiceTask extends InvocationTask
|
||||
Class[] args = m.getParameterTypes();
|
||||
for (int aa = 0; aa < args.length; aa++) {
|
||||
if (_ilistener.isAssignableFrom(args[aa]) &&
|
||||
GenUtil.simpleName(args[aa]).startsWith(sname + ".")) {
|
||||
GenUtil.simpleName(
|
||||
args[aa], null).startsWith(sname + ".")) {
|
||||
checkedAdd(listeners, new ServiceListener(
|
||||
service, args[aa], imports));
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -50,8 +51,8 @@ public class GenUtil
|
||||
Pattern.compile("^\\s*public\\s+(interface|class)\\s+(\\S+)(\\W|$)");
|
||||
|
||||
/**
|
||||
* Returns the name of the supplied class as it would likely appear in
|
||||
* code using the class (no package prefix, arrays specified as
|
||||
* Returns the name of the supplied class as it would likely appear in code
|
||||
* using the class (no package prefix, arrays specified as
|
||||
* <code>type[]</code>).
|
||||
*/
|
||||
public static String simpleName (Field field)
|
||||
@@ -64,7 +65,8 @@ public class GenUtil
|
||||
field.getGenericType();
|
||||
cname = atype.getGenericComponentType().toString();
|
||||
} else {
|
||||
return simpleName(clazz.getComponentType()) + "[]";
|
||||
return simpleName(clazz.getComponentType(),
|
||||
field.getGenericType()) + "[]";
|
||||
}
|
||||
} else if (field.getGenericType() instanceof ParameterizedType) {
|
||||
cname = field.getGenericType().toString();
|
||||
@@ -78,18 +80,22 @@ public class GenUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the supplied class as it would likely appear in
|
||||
* code using the class (no package prefix, arrays specified as
|
||||
* Returns the name of the supplied class as it would likely appear in code
|
||||
* using the class (no package prefix, arrays specified as
|
||||
* <code>type[]</code>).
|
||||
*/
|
||||
public static String simpleName (Class<?> clazz)
|
||||
public static String simpleName (Class<?> clazz, Type type)
|
||||
{
|
||||
if (clazz.isArray()) {
|
||||
return simpleName(clazz.getComponentType()) + "[]";
|
||||
return simpleName(clazz.getComponentType(), type) + "[]";
|
||||
} else {
|
||||
String cname = clazz.getName();
|
||||
if (type instanceof ParameterizedType) {
|
||||
cname = type.toString();
|
||||
}
|
||||
Package pkg = clazz.getPackage();
|
||||
int offset = (pkg == null) ? 0 : pkg.getName().length()+1;
|
||||
String name = clazz.getName().substring(offset);
|
||||
String name = cname.substring(offset);
|
||||
return StringUtil.replace(name, "$", ".");
|
||||
}
|
||||
}
|
||||
@@ -122,10 +128,10 @@ public class GenUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* "Unboxes" the supplied argument, ie. turning an
|
||||
* <code>Integer</code> object into an <code>int</code>.
|
||||
* "Unboxes" the supplied argument, ie. turning an <code>Integer</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) {
|
||||
return "((Boolean)" + name + ").booleanValue()";
|
||||
@@ -144,7 +150,7 @@ public class GenUtil
|
||||
} else if (clazz == Double.TYPE) {
|
||||
return "((Double)" + name + ").doubleValue()";
|
||||
} else {
|
||||
return "(" + simpleName(clazz) + ")" + name + "";
|
||||
return "(" + simpleName(clazz, type) + ")" + name + "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -54,7 +55,7 @@ public abstract class InvocationTask extends Task
|
||||
|
||||
public String getMarshaller ()
|
||||
{
|
||||
String name = GenUtil.simpleName(listener);
|
||||
String name = GenUtil.simpleName(listener, null);
|
||||
// handle ye olde special case
|
||||
if (name.equals("InvocationService.InvocationListener")) {
|
||||
return "ListenerMarshaller";
|
||||
@@ -106,7 +107,8 @@ public abstract class InvocationTask extends Task
|
||||
// InvocationService listeners, we need to import its
|
||||
// marshaller as well
|
||||
if (_ilistener.isAssignableFrom(arg) &&
|
||||
!GenUtil.simpleName(arg).startsWith("InvocationService")) {
|
||||
!GenUtil.simpleName(
|
||||
arg, null).startsWith("InvocationService")) {
|
||||
String mname = arg.getName();
|
||||
mname = StringUtil.replace(mname, "Service", "Marshaller");
|
||||
mname = StringUtil.replace(mname, "Listener", "Marshaller");
|
||||
@@ -135,11 +137,12 @@ public abstract class InvocationTask extends Task
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Class<?>[] args = method.getParameterTypes();
|
||||
Type[] ptypes = method.getGenericParameterTypes();
|
||||
for (int ii = skipFirst ? 1 : 0; ii < args.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(GenUtil.simpleName(args[ii]));
|
||||
buf.append(GenUtil.simpleName(args[ii], ptypes[ii]));
|
||||
buf.append(" arg").append(skipFirst ? ii : ii+1);
|
||||
}
|
||||
return buf.toString();
|
||||
@@ -172,12 +175,13 @@ public abstract class InvocationTask extends Task
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Class<?>[] args = method.getParameterTypes();
|
||||
Type[] ptypes = method.getGenericParameterTypes();
|
||||
for (int ii = (listenerMode ? 0 : 1); ii < args.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(unboxArgument(args[ii], listenerMode ? ii : ii-1,
|
||||
listenerMode));
|
||||
buf.append(unboxArgument(args[ii], ptypes[ii],
|
||||
listenerMode ? ii : ii-1, listenerMode));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
@@ -192,12 +196,13 @@ public abstract class InvocationTask extends Task
|
||||
}
|
||||
|
||||
protected String unboxArgument (
|
||||
Class<?> clazz, int index, boolean listenerMode)
|
||||
Class<?> clazz, Type type, int index, boolean listenerMode)
|
||||
{
|
||||
if (listenerMode && _ilistener.isAssignableFrom(clazz)) {
|
||||
return "listener" + index;
|
||||
} 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;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
// from InvocationDispatcher
|
||||
public InvocationMarshaller createMarshaller ()
|
||||
{
|
||||
return new ${name}Marshaller();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@SuppressWarnings("unchecked") // from InvocationDispatcher
|
||||
public void dispatchRequest (
|
||||
ClientObject source, int methodId, Object[] args)
|
||||
throws InvocationException
|
||||
|
||||
+32
-24
@@ -28,8 +28,7 @@
|
||||
classpathref="classpath"/>
|
||||
<!-- make sure the dobject class files are all compiled -->
|
||||
<javac srcdir="src/java" destdir="${classes.dir}"
|
||||
debug="on" optimize="${build.optimize}" deprecation="on"
|
||||
source="1.4" target="1.4">
|
||||
debug="on" deprecation="on" source="1.5" target="1.5">
|
||||
<classpath refid="classpath"/>
|
||||
<include name="**/*Object.java"/>
|
||||
</javac>
|
||||
@@ -39,30 +38,39 @@
|
||||
</dobj>
|
||||
</target>
|
||||
|
||||
<!-- generates marshaller and dispatcher classes for all invocation
|
||||
service declarations -->
|
||||
<target name="genservice">
|
||||
<apply executable="../bin/genservice" failonerror="true" parallel="true">
|
||||
<arg value="--classpath"/>
|
||||
<arg value="${classes.dir}:${narya.classes.dir}"/>
|
||||
<arg value="--sourcedir"/>
|
||||
<arg value="src/java"/>
|
||||
<fileset dir="src/java" includes="**/*Service.java"
|
||||
excludes="**/InvocationService.java"/>
|
||||
</apply>
|
||||
<!-- generates marshaller and dispatcher classes for all invocation -->
|
||||
<!-- service declarations -->
|
||||
<target name="genservice">
|
||||
<taskdef name="service" classpathref="classpath"
|
||||
classname="com.threerings.presents.tools.GenServiceTask"/>
|
||||
<!-- make sure the service class files are all compiled -->
|
||||
<javac srcdir="src/java" destdir="${classes.dir}" debug="on"
|
||||
deprecation="on" source="1.5" target="1.5">
|
||||
<classpath refid="classpath"/>
|
||||
<include name="**/*Service.java"/>
|
||||
</javac>
|
||||
<!-- now generate the associated files -->
|
||||
<service header="../lib/SOURCE_HEADER" classpathref="classpath">
|
||||
<fileset dir="src/java" includes="**/*Service.java"/>
|
||||
</service>
|
||||
</target>
|
||||
|
||||
<!-- generates sender and decoder classes for all invocation
|
||||
receiver declarations -->
|
||||
<target name="genreceiver">
|
||||
<apply executable="../bin/genreceiver" failonerror="true" parallel="true">
|
||||
<arg value="--classpath"/>
|
||||
<arg value="${classes.dir}:${narya.classes.dir}"/>
|
||||
<arg value="--sourcedir"/>
|
||||
<arg value="src/java"/>
|
||||
<fileset dir="src/java" includes="**/*Receiver.java"
|
||||
excludes="**/InvocationReceiver.java"/>
|
||||
</apply>
|
||||
<!-- generates sender and decoder classes for all invocation -->
|
||||
<!-- receiver declarations -->
|
||||
<target name="genreceiver">
|
||||
<taskdef name="receiver" classpathref="classpath"
|
||||
classname="com.threerings.presents.tools.GenReceiverTask"/>
|
||||
<!-- make sure the receiver class files are all compiled -->
|
||||
<javac srcdir="src/java" destdir="${classes.dir}"
|
||||
debug="on" deprecation="on" source="1.5" target="1.5">
|
||||
<classpath refid="classpath"/>
|
||||
<include name="**/*Receiver.java"/>
|
||||
<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>
|
||||
|
||||
<!-- prepares the application directories -->
|
||||
|
||||
@@ -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