hammant 2002/12/02 16:19:57
Modified: altrmi build.xml default.properties
altrmi/src/java/org/apache/excalibur/altrmi/generator
AbstractProxyGenerator.java
altrmi/src/java/org/apache/excalibur/altrmi/server
PublicationDescription.java
PublicationDescriptionItem.java
altrmi/src/test/org/apache/excalibur/altrmi/test/async
AsyncTest.java SimpleAsyncTestCase.java
Added: altrmi/src/java/org/apache/excalibur/altrmi/server
AttributeHelper.java
altrmi/src/test/org/apache/excalibur/altrmi/test/async
SimpleAsync2TestCase.java
altrmi/lib commons-attributes-0.1.jar qdox-1.0.jar
Log:
Start of (optional) attribute usage for async AltRMI
Revision Changes Path
1.46 +14 -4 jakarta-avalon-excalibur/altrmi/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/build.xml,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- build.xml 27 Nov 2002 00:08:49 -0000 1.45
+++ build.xml 3 Dec 2002 00:19:56 -0000 1.46
@@ -16,8 +16,10 @@
<pathelement location="${avalon-framework.jar}"/>
<pathelement location="${excalibur-pool.jar}"/>
<pathelement location="${checkstyle.jar}"/>
- <pathelement path="${java.class.path}"/>
+ <pathelement location="${jakarta-commons-attributes.jar}"/>
+ <pathelement location="${qdox.jar}"/>
<pathelement location="${jakarta-bcel.jar}"/>
+ <pathelement path="${java.class.path}"/>
<pathelement path="lib/servlet.jar"/>
</path>
@@ -137,6 +139,12 @@
<include name="**/*.java"/>
</javac>
+ <taskdef name="attributes"
classname="org.apache.commons.attributes.task.AttributesCompiler">
+ <classpath refid="project.class.path" />
+ </taskdef>
+
+ <attributes src="${build.testsrc}" dest="${build.testclasses}"/>
+
<copy todir="${build.testclasses}">
<fileset dir="${test.dir}">
<exclude name="**/*.java"/>
@@ -234,6 +242,8 @@
<!-- Plain tests -->
+ <echo message="w" file="poo.txt"/>
+
<junit fork="true"
haltonfailure="${junit.failonerror}"
printsummary="yes"
@@ -244,10 +254,10 @@
<formatter type="plain" usefile="false"/> <!-- text reports for humans
-->
<batchtest todir="${build.tests}">
<fileset dir="${build.testclasses}">
- <!-- <include name="**/test/**/SimpleAsy*TestCase.class"/> -->
- <include name="**/test/**/*TestCase.class"/>
+ <include name="**/test/**/SimpleAsy*TestCase.class"/>
+<!-- <include name="**/test/**/*TestCase.class"/>
<exclude name="**/Abstract*"/>
- <exclude name="**/JSXObjectStreamTestCase.class"/>
+ <exclude name="**/JSXObjectStreamTestCase.class"/> -->
</fileset>
</batchtest>
</junit>
1.13 +3 -1 jakarta-avalon-excalibur/altrmi/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/default.properties,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- default.properties 16 Nov 2002 12:08:50 -0000 1.12
+++ default.properties 3 Dec 2002 00:19:56 -0000 1.13
@@ -27,7 +27,9 @@
avalon-framework.home=${basedir}/../../jakarta-avalon
avalon-framework.lib=${avalon-framework.home}/target/lib
avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
-jakarta-bcel.jar=./lib/bcel.jar
+jakarta-bcel.jar=lib/bcel.jar
+qdox.jar=lib/qdox-1.0.jar
+jakarta-commons-attributes.jar=./lib/commons-attributes-0.1.jar
# ----- Excalibur pool, version 1.1 or later -----
excalibur-pool.home=${basedir}/../pool/dist
1.5 +2 -4
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/AbstractProxyGenerator.java
Index: AbstractProxyGenerator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/AbstractProxyGenerator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractProxyGenerator.java 25 Nov 2002 21:17:07 -0000 1.4
+++ AbstractProxyGenerator.java 3 Dec 2002 00:19:56 -0000 1.5
@@ -276,9 +276,7 @@
for (int i = 0; i < publicationDescriptionItemses.length; i++)
{
PublicationDescriptionItem publicationDescriptionItem =
publicationDescriptionItemses[i];
- if (publicationDescriptionItem.getAsyncMethods().length != 0
- | publicationDescriptionItem.getCommitMethod() != null
- | publicationDescriptionItem.getRollbackMethod() != null)
+ if (publicationDescriptionItem.hasAsyncBehavior())
{
return true;
}
1.8 +2 -1
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/PublicationDescription.java
Index: PublicationDescription.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/PublicationDescription.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- PublicationDescription.java 25 Nov 2002 21:17:08 -0000 1.7
+++ PublicationDescription.java 3 Dec 2002 00:19:57 -0000 1.8
@@ -92,6 +92,7 @@
{
addInterfacesToExpose(interfacesToExpose);
addAdditionalFacadesToExpose(additionalFacades);
+
}
/**
1.5 +67 -53
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/PublicationDescriptionItem.java
Index: PublicationDescriptionItem.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/PublicationDescriptionItem.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PublicationDescriptionItem.java 27 Nov 2002 00:08:49 -0000 1.4
+++ PublicationDescriptionItem.java 3 Dec 2002 00:19:57 -0000 1.5
@@ -24,41 +24,45 @@
private final Class m_facadeClass;
private final Vector m_asyncMethods = new Vector();
- private final String m_commitMethod;
- private final String m_rollbackMethod;
+ private final Vector m_commitMethods = new Vector();
+ private final Vector m_rollbackMethods = new Vector();
public PublicationDescriptionItem(Class facadeClass)
{
m_facadeClass = facadeClass;
- m_commitMethod = null;
- m_rollbackMethod = null;
- }
-
- public PublicationDescriptionItem(Class facadeClass, String[] asyncMethods)
throws PublicationException
- {
- m_facadeClass = facadeClass;
- if (facadeClass == null)
+ Method[] methods = facadeClass.getDeclaredMethods();
+ try
{
- throw new RuntimeException("Facade class nust not be null");
- }
- for (int i = 0; i < asyncMethods.length; i++)
- {
- String asyncMethod = asyncMethods[i];
- m_asyncMethods.add(asyncMethod);
+ AttributeHelper attributeHelper = new AttributeHelper();
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method method = methods[i];
+ if (attributeHelper.isMethodAsync(method))
+ {
+ m_asyncMethods.add(MethodNameHelper.getMethodSignature(method));
+ }
+ if (attributeHelper.isMethodAsyncCommit(method))
+ {
+
m_commitMethods.add(MethodNameHelper.getMethodSignature(method));
+ }
+ if (attributeHelper.isMethodAsyncRollback(method))
+ {
+
m_rollbackMethods.add(MethodNameHelper.getMethodSignature(method));
+ }
+ }
}
-
- for (int i = 0; i < asyncMethods.length; i++)
+ catch (NoClassDefFoundError ncdfe)
{
- String asyncMethod = asyncMethods[i];
- testAsyncMethodType(facadeClass.getMethods(), asyncMethod);
-
+ System.out.println("--> ncdfe");
+ // attribute jars are missing.
+ // This allowed for when there is no Async functionality.
}
- m_commitMethod = null;
- m_rollbackMethod = null;
}
- public PublicationDescriptionItem(Class facadeClass, String[] asyncMethods,
- String commitMethod, String rollbackMethod)
throws PublicationException
+ public PublicationDescriptionItem(Class facadeClass,
+ String[] asyncMethods,
+ String[] commitMethods,
+ String[] rollbackMethods) throws
PublicationException
{
m_facadeClass = facadeClass;
if (facadeClass == null)
@@ -69,19 +73,23 @@
for (int i = 0; i < asyncMethods.length; i++)
{
String asyncMethod = asyncMethods[i];
+ testAsyncMethodType(facadeClass.getMethods(), asyncMethod);
m_asyncMethods.add(asyncMethod);
}
- m_commitMethod = commitMethod;
- m_rollbackMethod = rollbackMethod;
- for (int i = 0; i < asyncMethods.length; i++)
+ for (int i = 0; i < commitMethods.length; i++)
{
- String asyncMethod = asyncMethods[i];
- testAsyncMethodType(facadeClass.getMethods(), asyncMethod);
+ String commitMethod = commitMethods[i];
+ testAsyncMethodType(facadeClass.getMethods(), commitMethod);
+ m_commitMethods.add(commitMethod);
+ }
+ for (int i = 0; i < rollbackMethods.length; i++)
+ {
+ String rollbackMethod = rollbackMethods[i];
+ testAsyncMethodType(facadeClass.getMethods(), rollbackMethod);
+ m_rollbackMethods.add(rollbackMethod);
}
- testAsyncMethodType(facadeClass.getMethods(), commitMethod);
- testAsyncMethodType(facadeClass.getMethods(), rollbackMethod);
}
private void testAsyncMethodType(Method[] methods, String methodSignature)
throws PublicationException
@@ -114,21 +122,32 @@
return m_facadeClass;
}
- public String[] getAsyncMethods()
- {
- String[] retval = new String[m_asyncMethods.size()];
- m_asyncMethods.copyInto(retval);
- return retval;
- }
-
- public String getCommitMethod()
+ public boolean isCommit(Method method)
{
- return m_commitMethod;
+ String mthSig = MethodNameHelper.getMethodSignature(method);
+ for (int i = 0; i < m_commitMethods.size(); i++)
+ {
+ String asyncMethod = (String) m_commitMethods.elementAt(i);
+ if (asyncMethod.equals(mthSig))
+ {
+ return true;
+ }
+ }
+ return false;
}
- public String getRollbackMethod()
+ public boolean isRollback(Method method)
{
- return m_rollbackMethod;
+ String mthSig = MethodNameHelper.getMethodSignature(method);
+ for (int i = 0; i < m_rollbackMethods.size(); i++)
+ {
+ String asyncMethod = (String) m_rollbackMethods.elementAt(i);
+ if (asyncMethod.equals(mthSig))
+ {
+ return true;
+ }
+ }
+ return false;
}
public boolean isAsync(Method method)
@@ -145,16 +164,11 @@
return false;
}
- public boolean isCommit(Method method)
+ public boolean hasAsyncBehavior()
{
- String mthSig = MethodNameHelper.getMethodSignature(method);
- return mthSig.equals(m_commitMethod);
- }
-
- public boolean isRollback(Method method)
- {
- String mthSig = MethodNameHelper.getMethodSignature(method);
- return mthSig.equals(m_rollbackMethod);
+ return ( m_asyncMethods.size() !=0
+ | m_commitMethods.size() != 0
+ | m_rollbackMethods.size() != 0);
}
}
1.1
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/AttributeHelper.java
Index: AttributeHelper.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.excalibur.altrmi.server;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.Attribute;
import java.lang.reflect.Method;
public class AttributeHelper {
protected boolean isMethodAsync(Method method)
{
Attribute attr = Attributes.getAttribute(method, "altrmi:method");
return (attr.getValue().equals("async"));
}
protected boolean isMethodAsyncCommit(Method method)
{
Attribute attr = Attributes.getAttribute(method, "altrmi:method");
return (attr.getValue().equals("commit"));
}
protected boolean isMethodAsyncRollback(Method method)
{
Attribute attr = Attributes.getAttribute(method, "altrmi:method");
return (attr.getValue().equals("rollback"));
}
}
1.3 +18 -0
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/AsyncTest.java
Index: AsyncTest.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/AsyncTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AsyncTest.java 27 Nov 2002 00:08:49 -0000 1.2
+++ AsyncTest.java 3 Dec 2002 00:19:57 -0000 1.3
@@ -7,17 +7,35 @@
*/
package org.apache.excalibur.altrmi.test.async;
+/**
+ * @altrmi:facade async-mode1
+ */
public interface AsyncTest
{
+ /**
+ * @altrmi:method async
+ */
void setOne(String one);
+ /**
+ * @altrmi:method async
+ */
void setTwo(String two);
+ /**
+ * @altrmi:method async
+ */
void setThree(String three);
+ /**
+ * @altrmi:method commit
+ */
void fire();
+ /**
+ * @altrmi:method rollback
+ */
void whoa();
}
1.5 +2 -1
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/SimpleAsyncTestCase.java
Index: SimpleAsyncTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/SimpleAsyncTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SimpleAsyncTestCase.java 27 Nov 2002 00:08:49 -0000 1.4
+++ SimpleAsyncTestCase.java 3 Dec 2002 00:19:57 -0000 1.5
@@ -51,7 +51,8 @@
"setTwo(java.lang.String)",
"setThree(java.lang.String)",
},
- "fire()", "whoa()"
+ new String[] {"fire()"},
+ new String[] {"whoa()"}
)
);
cr.generate("AsyncTest",pd, this.getClass().getClassLoader());
1.1
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/SimpleAsync2TestCase.java
Index: SimpleAsync2TestCase.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.excalibur.altrmi.test.async;
import
org.apache.excalibur.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
import
org.apache.excalibur.altrmi.server.impl.classretrievers.JavacDynamicGeneratorClassRetriever;
import org.apache.excalibur.altrmi.server.PublicationDescription;
import org.apache.excalibur.altrmi.server.PublicationDescriptionItem;
import org.apache.excalibur.altrmi.client.impl.ServerClassAltrmiFactory;
import org.apache.excalibur.altrmi.client.impl.socket.SocketCustomStreamHostContext;
import org.apache.excalibur.altrmi.client.AltrmiFactory;
import junit.framework.TestCase;
import java.io.File;
public class SimpleAsync2TestCase extends TestCase
{
AsyncTestImpl asyncTestImpl;
AsyncTest testClient;
AltrmiFactory altrmiFactory;
CompleteSocketCustomStreamServer server;
public SimpleAsync2TestCase(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
// server side setup.
server = new CompleteSocketCustomStreamServer(11004);
JavacDynamicGeneratorClassRetriever cr = new
JavacDynamicGeneratorClassRetriever(
this.getClass().getClassLoader());
cr.setClassGenDir(".");
cr.setAltrmiClasspath("..\\build\\classes;C:\\j2sdk1.4.1\\lib\\tools.jar");
cr.setSrcGenDir(".");
server.setClassRetriever(cr);
asyncTestImpl = new AsyncTestImpl();
// automatic determination of async elements.
PublicationDescription pd = new PublicationDescription(AsyncTest.class);
cr.generate("AsyncTestB",pd, this.getClass().getClassLoader());
server.publish(asyncTestImpl, "AsyncTestB", pd);
server.start();
// Client side setup
altrmiFactory = new ServerClassAltrmiFactory(false);
altrmiFactory.setHostContext(
new SocketCustomStreamHostContext("127.0.0.1", 11004), false);
testClient = (AsyncTest) altrmiFactory.lookup("AsyncTestB");
// just a kludge for unit testing given we are intrinsically dealing with
// threads, AltRMI being a client/server thing
Thread.yield();
}
public void testSimpleAsync() throws Exception
{
testClient.setOne("one");
testClient.setTwo("two");
testClient.setThree("three");
assertNull("Field 'One' should be null", asyncTestImpl.one);
assertNull("Field 'Two' should be null", asyncTestImpl.two);
assertNull("Field 'Tree' should be null", asyncTestImpl.three);
assertFalse("Field 'Fire' should be false", asyncTestImpl.fired);
testClient.fire();
assertNotNull("Field 'One' should not be null", asyncTestImpl.one);
assertNotNull("Field 'Two' should not be null", asyncTestImpl.two);
assertNotNull("Field 'Tree' should not be null", asyncTestImpl.three);
assertTrue("Field 'Fire' should not be false", asyncTestImpl.fired);
}
public void testRollback() throws Exception
{
testClient.setOne("111");
assertNull("Field 'One' should be null #1", asyncTestImpl.one);
testClient.whoa();
testClient.fire();
assertNull("Field 'One' should be null #2", asyncTestImpl.one);
assertTrue("Field 'Whoa' should not be false", asyncTestImpl.whoa);
assertTrue("Field 'Fire' should not be false", asyncTestImpl.fired);
testClient.setOne("222");
testClient.fire();
assertNotNull("Field 'One' should not be null", asyncTestImpl.one);
}
protected void tearDown() throws Exception
{
testClient = null;
System.gc();
Thread.yield();
altrmiFactory.close();
Thread.yield();
server.stop();
Thread.yield();
server = null;
asyncTestImpl = null;
super.tearDown();
}
public static void main(String[] args) throws Exception
{
SimpleAsync2TestCase simp = new SimpleAsync2TestCase("testSimpleAsync");
simp.setUp();
simp.testSimpleAsync();
simp.tearDown();
}
}
1.1 jakarta-avalon-excalibur/altrmi/lib/commons-attributes-0.1.jar
<<Binary file>>
1.1 jakarta-avalon-excalibur/altrmi/lib/qdox-1.0.jar
<<Binary file>>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>