I'm trying out the new Java continuations stuff seperately from Cocoon.
However, I have run into a problem. The instrumented bytecode throws a ClassCastException In the case where I am trying to resume a Continuation from a Continuable which delegates to another Continuable.
I have inlined a couple of Java test files. These test different Continuable implementations. The first two Continuable types (SimpleContinuable and ExtendedContinuable) work. When I try it with a WrapperContinuable which delegates to a SimpleContinuable I'm in trouble.
Some deeper digging shows that it retrieves a WrapperContinuable from the ContinuationStack and tries to cast it to a SimpleContinuable. It looks like something is wrong with the bytecode instrumentation? Can you help me out?
Thanks,
Peter Mortier
------------------------- ContinuationTest.java ------------------------------
import org.apache.cocoon.components.flow.java.Continuation; import org.apache.cocoon.components.flow.java.ContinuationClassLoader;
public class ContinuationTest {
static public void main( String args[] ) {
try {
testSimpleContinuable();
System.out.println("SimpleContinuable test done");
testExtendedContinuable();
System.out.println("ExtendedContinuable test done");
testWrapperContinuable();
System.out.println("Wrapper continuable test done");
} catch (Exception e) {
e.printStackTrace();
}
}protected static void testSimpleContinuable() throws Exception {
ContinuationClassLoader cl = new ContinuationClassLoader(Thread.currentThread().getContextClassLoader());
Continuation continuation = new Continuation(null);
continuation.registerThread();
Class clazz = cl.loadClass("SimpleContinuable");
Object object = clazz.newInstance();
clazz.getMethod("suspend", null).invoke(object, null);
continuation = new Continuation(continuation, null);
continuation.registerThread();
clazz.getMethod("suspend", null).invoke(object, null);
}
protected static void testWrapperContinuable() throws Exception {
ContinuationClassLoader cl = new ContinuationClassLoader(Thread.currentThread().getContextClassLoader());
Continuation continuation = new Continuation(null);
continuation.registerThread();
Class clazz = cl.loadClass("WrapperContinuable");
Object object = clazz.newInstance();
clazz.getMethod("test", null).invoke(object, null);
continuation = new Continuation(continuation, null);
continuation.registerThread();
clazz.getMethod("test", null).invoke(object, null);
}
protected static void testExtendedContinuable() throws Exception {
ContinuationClassLoader cl = new ContinuationClassLoader(Thread.currentThread().getContextClassLoader());
Continuation continuation = new Continuation(null);
continuation.registerThread();
Class clazz = cl.loadClass("ExtendedContinuable");
Object object = clazz.newInstance();
clazz.getMethod("test", null).invoke(object, null);
continuation = new Continuation(continuation, null);
continuation.registerThread();
clazz.getMethod("test", null).invoke(object, null);
}
}
------------------------- SimpleContinuable.java ------------------------------
import org.apache.cocoon.components.flow.java.Continuable; import org.apache.cocoon.components.flow.java.Continuation;
public class SimpleContinuable implements Continuable {
public void suspend() {
System.out.println("suspending");
Continuation.suspend();
System.out.println("continuing");
}}
------------------------- ExtendedContinuable.java ------------------------------
public class ExtendedContinuable extends SimpleContinuable {
public void test() {
super.suspend();
}}
------------------------- WrapperContinuable.java ------------------------------
import org.apache.cocoon.components.flow.java.Continuable;
public class WrapperContinuable implements Continuable {
SimpleContinuable simple;
public WrapperContinuable() {
simple = new SimpleContinuable();
} public void test() {
simple.suspend();
}}
_________________________________________________________________
Vraag van de week: Welk soort project zou jij financieel ondersteunen? http://www.msn.be/microsoft/potential/default.asp
