You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ha...@apache.org on 2002/01/16 12:32:20 UTC
cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test TestObject.java TestClient.java TestInterface.java TestInterfaceImpl.java
hammant 02/01/16 03:32:20
Modified: altrmi PROPOSAL
altrmi/src/java/org/apache/commons/altrmi/generator
PrimarySourceGenerator.java
altrmi/src/java/org/apache/commons/altrmi/server/impl
DefaultInvocationHandler.java
ObjectStreamServerConnection.java
altrmi/src/java/org/apache/commons/altrmi/test
TestClient.java TestInterface.java
TestInterfaceImpl.java
Added: altrmi/src/java/org/apache/commons/altrmi/test
TestObject.java
Log:
Arrays for return values now possible.
Revision Changes Path
1.3 +5 -4 jakarta-commons-sandbox/altrmi/PROPOSAL
Index: PROPOSAL
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/PROPOSAL,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PROPOSAL 11 Jan 2002 14:24:07 -0000 1.2
+++ PROPOSAL 16 Jan 2002 11:32:19 -0000 1.3
@@ -55,7 +55,7 @@
- To suit remote facilities that are happy with refection and do
not need to cast to an interface to use a bean (I am thinking of
- beanshell) the proxy class can be generated without specifying
+ BeanShell) the proxy class can be generated without specifying
that it implements the interface(s).
7) Suspendable/Resumable service.
@@ -91,15 +91,16 @@
- The server implements and acts upon start() and stop() methods.
-12) No just pass by value.
+12) Not just pass by value.
- AltRMI started life as 'pass by value' only. In now supports return
types and parameters wrapped in another AltRMI Facade.
13) No duplicate instances.
- - If you call Person p = getPerson("Fred") twice you will get the same
- instance on the client side is it is the same instance on the server side.
+ - For Facades, if you call Person p = getPerson("Fred") twice you will get
+ the same instance on the client side is it is the same instance on the
+ server side.
Limitations:
1.6 +64 -15 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/PrimarySourceGenerator.java
Index: PrimarySourceGenerator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/PrimarySourceGenerator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PrimarySourceGenerator.java 14 Jan 2002 13:53:14 -0000 1.5
+++ PrimarySourceGenerator.java 16 Jan 2002 11:32:20 -0000 1.6
@@ -29,7 +29,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class PrimarySourceGenerator extends AbstractMethodHandler {
@@ -159,7 +159,7 @@
if (!methodsDone.contains(methodSignature)) {
methodsDone.add(methodSignature);
- String rClass = method.getReturnType().getName();
+ Class rClass = method.getReturnType();
if (!(method.getReturnType() instanceof Serializable)) {
throw new SourceGenerationException("Return type " + rClass
@@ -168,7 +168,7 @@
String mName = method.getName();
- mClassSource.print(" public " + rClass + " " + mName + " (");
+ mClassSource.print(" public " + generateReturnValue(rClass) + " " + mName + " (");
Class[] argTypes = method.getParameterTypes();
@@ -214,8 +214,8 @@
mClassSource.println(
" Object retVal = mBaseServedObject.altrmiProcessObjectRequestGettingFacade(\""
+ methodSignature.toString() + "\",args,\""
- + encodeClassName(rClass) + "\");");
- mClassSource.println(" return (" + rClass + ") retVal;");
+ + encodeClassName(rClass.getName()) + "\");");
+ mClassSource.println(" return (" + rClass.getName() + ") retVal;");
} else {
mClassSource.println(
" Object retVal = mBaseServedObject.altrmiProcessObjectRequest(\""
@@ -384,27 +384,76 @@
}
}
- private void generateReturnLine(String rClass) {
+ private void generateReturnLine(Class rClass) {
- if (rClass.equals("boolean")) {
+ String arrayOtNot = rClass.isArray() ? "[]" : "";
+ String cn = rClass.getName();
+
+ if (cn.equals("boolean")) {
mClassSource.println(" return ((Boolean) retVal).booleanValue();");
- } else if (rClass.equals("integer")) {
+ } else if (cn.equals("integer")) {
mClassSource.println(" return ((Integer) retVal).intValue();");
- } else if (rClass.equals("short")) {
+ } else if (cn.equals("short")) {
mClassSource.println(" return ((Short) retVal).shortValue();");
- } else if (rClass.equals("float")) {
+ } else if (cn.equals("float")) {
mClassSource.println(" return ((Float) retVal).floatValue();");
- } else if (rClass.equals("double")) {
+ } else if (cn.equals("double")) {
mClassSource.println(" return ((Double) retVal).doubleValue();");
- } else if (rClass.equals("long")) {
+ } else if (cn.equals("long")) {
mClassSource.println(" return ((Long) retVal).longValue();");
- } else if (rClass.equals("char")) {
+ } else if (cn.equals("char")) {
mClassSource.println(" return ((Character) retVal).charValue();");
- } else if (rClass.equals("byte")) {
+ } else if (cn.equals("void")) {
+ mClassSource.println(" return;");
+ } else if (cn.equals("byte")) {
mClassSource.println(" return ((Byte) retVal).byteValue();");
+ } else if (cn.equals("[B")) {
+ mClassSource.println(" return (byte[]) retVal;");
+ } else if (cn.equals("[C")) {
+ mClassSource.println(" return (char[]) retVal;");
+ } else if (cn.equals("[D")) {
+ mClassSource.println(" return (double[]) retVal;");
+ } else if (cn.equals("[F")) {
+ mClassSource.println(" return (float[]) retVal;");
+ } else if (cn.equals("[I")) {
+ mClassSource.println(" return (int[]) retVal;");
+ } else if (cn.equals("[J")) {
+ mClassSource.println(" return (long[]) retVal;");
+ } else if (cn.equals("[S")) {
+ mClassSource.println(" return (short[]) retVal;");
+ } else if (cn.equals("[Z")) {
+ mClassSource.println(" return (boolean[]) retVal;");
+ } else if (rClass.getName().startsWith("[L")) {
+ mClassSource.println(" return (" + cn.substring(2,cn.length()-1) + "[]) retVal;");
+ } else {
+ mClassSource.println(" return (" + cn + ") retVal;");
+ }
+ }
+
+ private String generateReturnValue(Class rClass) {
+ String cn = rClass.getName();
+ if (cn.equals("[B")) {
+ return "byte[]";
+ } else if (cn.equals("[C")) {
+ return "char[]";
+ } else if (cn.equals("[D")) {
+ return "double[]";
+ } else if (cn.equals("[F")) {
+ return "float[]";
+ } else if (cn.equals("[I")) {
+ return "int[]";
+ } else if (cn.equals("[J")) {
+ return "long[]";
+ } else if (cn.equals("[S")) {
+ return "short[]";
+ } else if (cn.equals("[Z")) {
+ return "boolean[]";
+ } else if (cn.startsWith("[L")) {
+ return cn.substring(2,cn.length()-1) + "[]";
} else {
- mClassSource.println(" return (" + rClass + ") retVal;");
+ return cn;
}
+
}
private boolean isAdditionalFacade(String className) {
1.3 +3 -2 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/DefaultInvocationHandler.java
Index: DefaultInvocationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/DefaultInvocationHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultInvocationHandler.java 14 Jan 2002 23:03:30 -0000 1.2
+++ DefaultInvocationHandler.java 16 Jan 2002 11:32:20 -0000 1.3
@@ -35,7 +35,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class DefaultInvocationHandler implements AltrmiServerInvocationHandler {
@@ -148,6 +148,7 @@
Throwable t = ite.getTargetException();
if (t instanceof Serializable) {
+ // NOTE Sever side stack traces will appear on the client side
return new ExceptionReply(t);
} else {
return new ExceptionReply(
@@ -155,7 +156,7 @@
"Exception was not serializable :" + t.getClass().getName()));
}
} catch (Throwable t) {
- t.printStackTrace();
+ System.out.println("QQQQ 2");
return new ExceptionReply(
new AltrmiInvocationException(
"Some ServerSide exception problem :" + t.getMessage()));
1.3 +4 -1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/ObjectStreamServerConnection.java
Index: ObjectStreamServerConnection.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/ObjectStreamServerConnection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ObjectStreamServerConnection.java 13 Jan 2002 10:30:23 -0000 1.2
+++ ObjectStreamServerConnection.java 16 Jan 2002 11:32:20 -0000 1.3
@@ -30,7 +30,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class ObjectStreamServerConnection implements Runnable, AltrmiServerConnection {
@@ -76,6 +76,9 @@
AltrmiReply reply = mAbstractServer.processRequest(request);
oOS.writeObject(reply);
oOS.flush();
+ // http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ // halves the performance though.
+ //oOS.reset();
if (mEndConnection) {
oOS.writeObject(new EndConnectionReply());
1.3 +22 -1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestClient.java
Index: TestClient.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestClient.java 10 Jan 2002 00:08:59 -0000 1.2
+++ TestClient.java 16 Jan 2002 11:32:20 -0000 1.3
@@ -23,7 +23,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class TestClient {
@@ -80,6 +80,27 @@
System.out.println("CLT: One (by finder) name = '" + ti2OneB.getName() + "'");
System.out.println("CLT: new object == (instance equality) to '111' obj ? -> "
+ (ti2One == ti2OneB));
+
+ System.out.println("CLT: A test for bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html");
+
+ TestObject[] tos = ti.getTestObjects();
+ for (int i = 0; i < tos.length; i++) {
+ TestObject to = tos[i];
+ System.out.println("CLT : test obj " + i + " name = " + tos[i].getName());
+
+ }
+
+ System.out.println("CLT: Changing names on the server side to (aaa,bbb,ccc)");
+ ti.changeTestObjectNames();
+
+ TestObject[] tos2 = ti.getTestObjects();
+ for (int i = 0; i < tos2.length; i++) {
+ TestObject to = tos2[i];
+ System.out.println("CLT : test obj " + i + " name = " + tos2[i].getName());
+
+ }
+
+
System.out.println("CLT: Two timings about to start, please stand by...");
ti.testSpeed(); // to ignore for timing
1.2 +27 -1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterface.java
Index: TestInterface.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterface.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestInterface.java 9 Jan 2002 19:25:56 -0000 1.1
+++ TestInterface.java 16 Jan 2002 11:32:20 -0000 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -19,7 +20,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version * $Revision: 1.1 $
+ * @version * $Revision: 1.2 $
*/
public interface TestInterface {
@@ -115,4 +116,29 @@
*
*/
TestInterface2 findTestInterface2ByName(String nameToFind);
+
+ /**
+ * Method getTestObjects
+ * Helps ilustrate the bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ *
+ * @return
+ *
+ */
+ TestObject[] getTestObjects();
+
+ /**
+ * Method changeTestObjectNames
+ * Helps ilustrate the bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ *
+ *
+ */
+ void changeTestObjectNames();
+
+ /**
+ * Method makeNewTestObjectNames
+ * Helps ilustrate the bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ *
+ */
+ void makeNewTestObjectNames();
+
}
1.2 +48 -1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterfaceImpl.java
Index: TestInterfaceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterfaceImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestInterfaceImpl.java 9 Jan 2002 19:25:56 -0000 1.1
+++ TestInterfaceImpl.java 16 Jan 2002 11:32:20 -0000 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -21,11 +22,12 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class TestInterfaceImpl implements TestInterface {
Vector ti2Holder = new Vector();
+ TestObject[] mTestObjects;
/**
* Method hello
@@ -173,5 +175,50 @@
}
return new TestInterface2Impl("Not Found");
+ }
+
+ /**
+ * Method getTestObjects
+ * Helps ilustrate the bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ *
+ * @return
+ *
+ */
+ public TestObject[] getTestObjects() {
+
+
+ if (mTestObjects == null) {
+ mTestObjects = new TestObject[3];
+ mTestObjects[0] = new TestObject("AAA");
+ mTestObjects[1] = new TestObject("BBB");
+ mTestObjects[2] = new TestObject("CCC");
+ }
+
+ return mTestObjects;
+ }
+
+ /**
+ * Method changeTestObjectNames
+ * Helps ilustrate the bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ *
+ */
+ public void changeTestObjectNames() {
+
+ mTestObjects[0].setName("aaa");
+ mTestObjects[1].setName("bbb");
+ mTestObjects[2].setName("ccc");
+ }
+
+ /**
+ * Method makeNewTestObjectNames
+ * Helps ilustrate the bug http://developer.java.sun.com/developer/bugParade/bugs/4499841.html
+ *
+ */
+ public void makeNewTestObjectNames() {
+
+ mTestObjects[0] = new TestObject("aAa");
+ mTestObjects[1] = new TestObject("bBb");
+ mTestObjects[2] = new TestObject("cCc");
+
}
}
1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestObject.java
Index: TestObject.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.altrmi.test;
import java.io.Serializable;
/**
* Class TestObject
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class TestObject implements Serializable {
private String mName;
public TestObject(String name) {
mName = name;
}
/**
* Method getName
*
*
* @return
*
*/
public String getName() {
return mName;
}
/**
* Method setName
*
*
* @param name
*
*/
public void setName(String name) {
mName = name;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>