From afad7dd4440e7ac7679e71fc794f2a506448b37f Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 19 Sep 2006 00:31:50 +0000 Subject: [PATCH] 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 --- .../com/threerings/io/BasicStreamers.java | 45 +++++++++++++++ .../presents/tools/GenDObjectTask.java | 5 +- .../presents/tools/GenServiceTask.java | 5 +- .../threerings/presents/tools/GenUtil.java | 30 ++++++---- .../presents/tools/InvocationTask.java | 19 ++++--- .../threerings/presents/tools/dispatcher.tmpl | 4 +- tests/build.xml | 56 +++++++++++-------- .../presents/client/TestClient.java | 31 ++++++---- .../presents/client/TestService.java | 7 ++- .../presents/data/TestMarshaller.java | 52 ++++++++--------- .../threerings/presents/data/TestObject.java | 27 ++++++++- .../presents/server/TestDispatcher.java | 27 +++++---- .../presents/server/TestManager.java | 44 +++++++++++++++ .../presents/server/TestProvider.java | 44 ++++++--------- .../presents/server/TestServer.java | 6 +- 15 files changed, 271 insertions(+), 131 deletions(-) create mode 100644 tests/src/java/com/threerings/presents/server/TestManager.java diff --git a/src/java/com/threerings/io/BasicStreamers.java b/src/java/com/threerings/io/BasicStreamers.java index 6debd5830..c48332ef3 100644 --- a/src/java/com/threerings/io/BasicStreamers.java +++ b/src/java/com/threerings/io/BasicStreamers.java @@ -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 value = + (ArrayList)object; + int ecount = in.readInt(); + value.ensureCapacity(ecount); + for (int ii = 0; ii < ecount; ii++) { + value.add(in.readObject()); + } + } + } } diff --git a/src/java/com/threerings/presents/tools/GenDObjectTask.java b/src/java/com/threerings/presents/tools/GenDObjectTask.java index 36a330eaf..943674964 100644 --- a/src/java/com/threerings/presents/tools/GenDObjectTask.java +++ b/src/java/com/threerings/presents/tools/GenDObjectTask.java @@ -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"); diff --git a/src/java/com/threerings/presents/tools/GenServiceTask.java b/src/java/com/threerings/presents/tools/GenServiceTask.java index 87f7d8132..51527a3ca 100644 --- a/src/java/com/threerings/presents/tools/GenServiceTask.java +++ b/src/java/com/threerings/presents/tools/GenServiceTask.java @@ -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)); } diff --git a/src/java/com/threerings/presents/tools/GenUtil.java b/src/java/com/threerings/presents/tools/GenUtil.java index 08f7c916e..81c30cfa4 100644 --- a/src/java/com/threerings/presents/tools/GenUtil.java +++ b/src/java/com/threerings/presents/tools/GenUtil.java @@ -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 * type[]). */ 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 * type[]). */ - 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 - * Integer object into an int. + * "Unboxes" the supplied argument, ie. turning an Integer + * object into an int. */ - 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 + ""; } } diff --git a/src/java/com/threerings/presents/tools/InvocationTask.java b/src/java/com/threerings/presents/tools/InvocationTask.java index eed5d3fc0..27a08c408 100644 --- a/src/java/com/threerings/presents/tools/InvocationTask.java +++ b/src/java/com/threerings/presents/tools/InvocationTask.java @@ -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 + "]"); } } } diff --git a/src/java/com/threerings/presents/tools/dispatcher.tmpl b/src/java/com/threerings/presents/tools/dispatcher.tmpl index cd28bf808..fc27b5c40 100644 --- a/src/java/com/threerings/presents/tools/dispatcher.tmpl +++ b/src/java/com/threerings/presents/tools/dispatcher.tmpl @@ -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 diff --git a/tests/build.xml b/tests/build.xml index 8adc291f8..4a795fde7 100644 --- a/tests/build.xml +++ b/tests/build.xml @@ -28,8 +28,7 @@ classpathref="classpath"/> + debug="on" deprecation="on" source="1.5" target="1.5"> @@ -39,30 +38,39 @@ - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + diff --git a/tests/src/java/com/threerings/presents/client/TestClient.java b/tests/src/java/com/threerings/presents/client/TestClient.java index eaa3d2cf9..36963cf41 100644 --- a/tests/src/java/com/threerings/presents/client/TestClient.java +++ b/tests/src/java/com/threerings/presents/client/TestClient.java @@ -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, 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 three = new ArrayList(); + 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) { diff --git a/tests/src/java/com/threerings/presents/client/TestService.java b/tests/src/java/com/threerings/presents/client/TestService.java index 1d1283b75..53104ff33 100644 --- a/tests/src/java/com/threerings/presents/client/TestService.java +++ b/tests/src/java/com/threerings/presents/client/TestService.java @@ -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 three, + TestFuncListener listener); /** Used to dispatch responses to {@link #getTestOid} requests. */ public static interface TestOidListener extends InvocationListener diff --git a/tests/src/java/com/threerings/presents/data/TestMarshaller.java b/tests/src/java/com/threerings/presents/data/TestMarshaller.java index 152b152a4..1ee09dbcf 100644 --- a/tests/src/java/com/threerings/presents/data/TestMarshaller.java +++ b/tests/src/java/com/threerings/presents/data/TestMarshaller.java @@ -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 arg4, TestService.TestFuncListener arg5) + { + TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller(); + listener5.listener = arg5; + sendRequest(arg1, TEST, new Object[] { + arg2, Integer.valueOf(arg3), arg4, listener5 + }); + } + } diff --git a/tests/src/java/com/threerings/presents/data/TestObject.java b/tests/src/java/com/threerings/presents/data/TestObject.java index 1e099db89..8b353e65c 100644 --- a/tests/src/java/com/threerings/presents/data/TestObject.java +++ b/tests/src/java/com/threerings/presents/data/TestObject.java @@ -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 list field. */ public static final String LIST = "list"; + + /** The field name of the longs 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 longs = new ArrayList(); + // AUTO-GENERATED: METHODS START /** * Requests that the foo 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 longs 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 value) + { + ArrayList ovalue = this.longs; + requestAttributeChange( + LONGS, value, ovalue); + this.longs = value; + } // AUTO-GENERATED: METHODS END } diff --git a/tests/src/java/com/threerings/presents/server/TestDispatcher.java b/tests/src/java/com/threerings/presents/server/TestDispatcher.java index b955a86af..36504474a 100644 --- a/tests/src/java/com/threerings/presents/server/TestDispatcher.java +++ b/tests/src/java/com/threerings/presents/server/TestDispatcher.java @@ -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)args[2], (TestService.TestFuncListener)args[3] ); return; default: super.dispatchRequest(source, methodId, args); + return; } } } diff --git a/tests/src/java/com/threerings/presents/server/TestManager.java b/tests/src/java/com/threerings/presents/server/TestManager.java new file mode 100644 index 000000000..b6baf6fe9 --- /dev/null +++ b/tests/src/java/com/threerings/presents/server/TestManager.java @@ -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 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); + } +} diff --git a/tests/src/java/com/threerings/presents/server/TestProvider.java b/tests/src/java/com/threerings/presents/server/TestProvider.java index c95a48f72..b0341186a 100644 --- a/tests/src/java/com/threerings/presents/server/TestProvider.java +++ b/tests/src/java/com/threerings/presents/server/TestProvider.java @@ -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 arg3, TestService.TestFuncListener arg4) + throws InvocationException; } diff --git a/tests/src/java/com/threerings/presents/server/TestServer.java b/tests/src/java/com/threerings/presents/server/TestServer.java index 42ce11c57..968976991 100644 --- a/tests/src/java/com/threerings/presents/server/TestServer.java +++ b/tests/src/java/com/threerings/presents/server/TestServer.java @@ -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)