hammant 2002/11/26 16:08:49
Modified: altrmi build.xml
altrmi/src/java/org/apache/excalibur/altrmi/generator
ProxyGeneratorImpl.java
altrmi/src/java/org/apache/excalibur/altrmi/server
PublicationDescriptionItem.java
altrmi/src/test/org/apache/excalibur/altrmi/test/async
AsyncTest.java AsyncTestImpl.java
SimpleAsyncTestCase.java
Log:
async rollback working
Revision Changes Path
1.45 +2 -2 jakarta-avalon-excalibur/altrmi/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/build.xml,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- build.xml 26 Nov 2002 06:09:54 -0000 1.44
+++ build.xml 27 Nov 2002 00:08:49 -0000 1.45
@@ -244,8 +244,8 @@
<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"/>
</fileset>
1.16 +39 -3
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ProxyGeneratorImpl.java
Index: ProxyGeneratorImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ProxyGeneratorImpl.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ProxyGeneratorImpl.java 26 Nov 2002 06:09:55 -0000 1.15
+++ ProxyGeneratorImpl.java 27 Nov 2002 00:08:49 -0000 1.16
@@ -273,22 +273,31 @@
m_classSource.println( "{" );
if (async)
{
+ m_classSource.println( " synchronized(m_asyncInvocations) {" );
generateAsyncMethodBody(argTypes, rClass, methodSignature, method);
+ m_classSource.println( " }" );
}
else if (commit)
{
+ m_classSource.println( " synchronized(m_asyncInvocations) {" );
generateAsyncMethodBody(argTypes, rClass, methodSignature, method);
generateAsyncCommitMethodBody();
+ m_classSource.println( " }" );
}
else if (rollback)
{
- // generateAsyncRollbackMethodBody(argTypes, rClass, methodSignature,
method);
+ m_classSource.println( " synchronized(m_asyncInvocations) {" );
+ generateAsyncRollbackMethodBody(argTypes, methodSignature);
+ m_classSource.println( " }" );
}
else
{
generateNonAsyncMethodBody(argTypes, rClass, methodSignature, method);
}
- m_classSource.println( "}" );
+ m_classSource.println( " " +
+ "" +
+ "" +
+ "}" );
}
private void generateNonAsyncMethodBody(Class[] argTypes, Class rClass, String
methodSignature, Method method)
@@ -356,6 +365,33 @@
m_classSource.println( " try {" );
m_classSource.println( "
m_proxyHelper.processVoidRequests(m_asyncInvocations);" );
+ m_classSource.println( " } catch (Throwable t) {" );
+ m_classSource.println( " if (t instanceof RuntimeException) { " );
+ m_classSource.println( " throw (RuntimeException) t;" );
+ m_classSource.println( " } else if (t instanceof Error) { " );
+ m_classSource.println( " throw (Error) t;" );
+ m_classSource.println( " } else { " );
+ m_classSource.println( " t.printStackTrace(); " );
+ m_classSource.println(
+ " throw new org.apache.excalibur.altrmi.common."
+ + "AltrmiInvocationException(\"Should never get here: \"
+t.getMessage());");
+ m_classSource.println( " }" );
+ m_classSource.println( " } finally { " );
+ m_classSource.println( " m_asyncInvocations.removeAllElements();");
+ m_classSource.println( " }" );
+
+ }
+
+ private void generateAsyncRollbackMethodBody(Class[] argTypes, String
methodSignature)
+ {
+ Vector v = new Vector();
+ v.removeAllElements();
+ generateMethodArgs(argTypes);
+
+ m_classSource.println( " try {" );
+ m_classSource.println( " m_asyncInvocations.removeAllElements();");
+ m_classSource.println( " m_proxyHelper.processVoidRequest(\""
+ + methodSignature.toString() + "\",args);" );
m_classSource.println( " } catch (Throwable t) {" );
m_classSource.println( " if (t instanceof RuntimeException) { " );
m_classSource.println( " throw (RuntimeException) t;" );
1.4 +26 -13
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PublicationDescriptionItem.java 26 Nov 2002 06:09:55 -0000 1.3
+++ PublicationDescriptionItem.java 27 Nov 2002 00:08:49 -0000 1.4
@@ -10,6 +10,7 @@
import org.apache.excalibur.altrmi.common.MethodNameHelper;
import java.lang.reflect.Method;
+import java.util.Vector;
/**
* Class PublicationDescriptionItem
@@ -22,14 +23,13 @@
{
private final Class m_facadeClass;
- private final String[] m_asyncMethods;
+ private final Vector m_asyncMethods = new Vector();
private final String m_commitMethod;
private final String m_rollbackMethod;
public PublicationDescriptionItem(Class facadeClass)
{
m_facadeClass = facadeClass;
- m_asyncMethods = new String[0];
m_commitMethod = null;
m_rollbackMethod = null;
}
@@ -41,11 +41,16 @@
{
throw new RuntimeException("Facade class nust not be null");
}
- m_asyncMethods = asyncMethods;
for (int i = 0; i < asyncMethods.length; i++)
{
String asyncMethod = asyncMethods[i];
- testMethodType(facadeClass.getMethods(), asyncMethod);
+ m_asyncMethods.add(asyncMethod);
+ }
+
+ for (int i = 0; i < asyncMethods.length; i++)
+ {
+ String asyncMethod = asyncMethods[i];
+ testAsyncMethodType(facadeClass.getMethods(), asyncMethod);
}
m_commitMethod = null;
@@ -60,20 +65,26 @@
{
throw new RuntimeException("Facade class nust not be null");
}
- m_asyncMethods = asyncMethods;
+
+ for (int i = 0; i < asyncMethods.length; i++)
+ {
+ String asyncMethod = asyncMethods[i];
+ m_asyncMethods.add(asyncMethod);
+ }
+
m_commitMethod = commitMethod;
m_rollbackMethod = rollbackMethod;
for (int i = 0; i < asyncMethods.length; i++)
{
String asyncMethod = asyncMethods[i];
- testMethodType(facadeClass.getMethods(), asyncMethod);
+ testAsyncMethodType(facadeClass.getMethods(), asyncMethod);
}
- testMethodType(facadeClass.getMethods(), commitMethod);
- testMethodType(facadeClass.getMethods(), rollbackMethod);
+ testAsyncMethodType(facadeClass.getMethods(), commitMethod);
+ testAsyncMethodType(facadeClass.getMethods(), rollbackMethod);
}
- private void testMethodType(Method[] methods, String methodSignature) throws
PublicationException
+ private void testAsyncMethodType(Method[] methods, String methodSignature)
throws PublicationException
{
for (int i = 0; i < methods.length; i++)
{
@@ -105,7 +116,9 @@
public String[] getAsyncMethods()
{
- return m_asyncMethods;
+ String[] retval = new String[m_asyncMethods.size()];
+ m_asyncMethods.copyInto(retval);
+ return retval;
}
public String getCommitMethod()
@@ -121,9 +134,9 @@
public boolean isAsync(Method method)
{
String mthSig = MethodNameHelper.getMethodSignature(method);
- for (int i = 0; i < m_asyncMethods.length; i++)
+ for (int i = 0; i < m_asyncMethods.size(); i++)
{
- String asyncMethod = m_asyncMethods[i];
+ String asyncMethod = (String) m_asyncMethods.elementAt(i);
if (asyncMethod.equals(mthSig))
{
return true;
1.2 +2 -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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsyncTest.java 14 Nov 2002 23:49:29 -0000 1.1
+++ AsyncTest.java 27 Nov 2002 00:08:49 -0000 1.2
@@ -18,4 +18,6 @@
void fire();
+ void whoa();
+
}
1.2 +7 -0
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/AsyncTestImpl.java
Index: AsyncTestImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/async/AsyncTestImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsyncTestImpl.java 14 Nov 2002 23:49:29 -0000 1.1
+++ AsyncTestImpl.java 27 Nov 2002 00:08:49 -0000 1.2
@@ -14,6 +14,7 @@
public String two;
public String three;
public boolean fired;
+ public boolean whoa;
public void setOne(String one)
{
@@ -34,4 +35,10 @@
{
fired = true;
}
+
+ public void whoa()
+ {
+ whoa = true;
+ }
+
}
1.4 +22 -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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SimpleAsyncTestCase.java 26 Nov 2002 06:09:55 -0000 1.3
+++ SimpleAsyncTestCase.java 27 Nov 2002 00:08:49 -0000 1.4
@@ -51,7 +51,7 @@
"setTwo(java.lang.String)",
"setThree(java.lang.String)",
},
- "fire()", null
+ "fire()", "whoa()"
)
);
cr.generate("AsyncTest",pd, this.getClass().getClassLoader());
@@ -87,6 +87,27 @@
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);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>