You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Valery Silaev <vs...@gmail.com> on 2005/11/15 15:16:32 UTC
JavaFlow & Groovy
Hi all,
Is is possible to use JavaFlow with Groovy classes (at least, generated by
groovyc, dynamic loading will be superior)?
I'm trying to use Groovy JSR (RC03) with JavaFlow and instantly receives
some mysterious errors, like
"Cannot invoke method null() on object null".
For example, the test case is simple Runnable (in Groovy) with loop and
Continuation.suspend() inside loop. After the first iteration I get error
mentioned.
---
package mygroovy;
import java.io.Serializable;
import org.apache.commons.javaflow.Continuation;
class Scenario implements Runnable, Serializable {
void run() {
println "Hellow, Groovy!!!"
def i = 1
while ( i <= 10 ) {
step(i);
i = i + 1;
}
}
private void step(int i) {
println "Iteration ${i}" ;
Continuation.suspend();
}
}
-----------
Valery Silaev
EPAM Systems
Re: JavaFlow & Groovy
Posted by Torsten Curdt <tc...@apache.org>.
<snip/>
Thanks for the details. I will have a look into it ASAP.
As for now please have a look into the provided ANT task
and try rewriting at build time. (So no need of the class
loader) Just to see whether that makes a difference.
In case it doesn't I need both, the unmodified and the
rewritten class files.
With jci you can point a file alteration monitor to e.g.
your eclipse output dir and it will rewrite and reload
the classes through the ReloadingClassLoader.
Let me know if you if need further help.
cheers
--
Torsten
Re: JavaFlow & Groovy
Posted by Valery Silaev <vs...@gmail.com>.
Torsten,
First, thanks for your reply.
Here is my problem step-by step:
1. I created Groovy class, statically compile it with groovyc compiler and
package resulted classes into JAR archive:
---------- <src of mygroovy.Scenario> --------------
package mygroovy;
import java.io.Serializable;
import org.apache.commons.javaflow.Continuation;
class Scenario implements Runnable, Serializable
{
void run()
{
println "Hellow, Groovy!!!"
def i = 1
while ( i <= 10 )
{
step(i);
i = i + 1;
}
}
private void step(int i)
{
println "Iteration ${i}" ;
Continuation.suspend();
}
}
---------- </src of mygroovy.Scenario> --------------
2. I created sample Java class to test this file (byte code enhancement via
class loader):
---------- <src of sample.Sample> --------------
package sample;
import java.io.File;
import java.net.URL;
import org.apache.commons.javaflow.Continuation;
import org.apache.commons.javaflow.ContinuationClassLoader;
public class Sample
{
public static void main(final String[] args) throws Exception
{
final File jar = new File("../Groovy/mg.jar").getCanonicalFile();
final URL url = new URL("file", "", jar.getCanonicalPath() );
final ContinuationClassLoader classLoader = new ContinuationClassLoader
(
new URL[]{url}, ClassLoader.getSystemClassLoader()
);
//classLoader.setIsolated( true );
//classLoader.addLoaderPackageRoot("mygroovy");
//classLoader.addLoaderPackageRoot("groovy");
//classLoader.addLoaderPackageRoot("org.codehaus.groovy");
final Class clsScript = classLoader.loadClass( "mygroovy.Scenario" );
final Runnable script = (Runnable)clsScript.newInstance();
Continuation c = Continuation.startSuspendedWith( script );
c = Continuation.continueWith( c, script );
System.out.println( "PAUSE" ) ;
c = Continuation.continueWith( c, script );
System.out.println( "PAUSE" ) ;
}
}
---------- </src of sample.Sample> --------------
3. You may notice that at least 2 iterations should be executed
successfully, however here is output:
----------------------------------------------------------------------
Hellow, Groovy!!!
Iteration 1
PAUSE
16.11.2005 11:55:34 org.apache.commons.javaflow.bytecode.StackRecorderexecute
SEVERE: Cannot invoke method null() on null object
java.lang.NullPointerException: Cannot invoke method null() on null object
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:130)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java
:104)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(
ScriptBytecodeAdapter.java:85)
at mygroovy.Scenario.run(Unknown Source)
at org.apache.commons.javaflow.bytecode.StackRecorder.execute(
StackRecorder.java:95)
at org.apache.commons.javaflow.Continuation.execute(Continuation.java:173)
at org.apache.commons.javaflow.Continuation.continueWith(Continuation.java
:169)
at sample.Sample.main(Sample.java:32)
java.lang.NullPointerException: Cannot invoke method null() on null object
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:130)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java
:104)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(
ScriptBytecodeAdapter.java:85)
at mygroovy.Scenario.run(Unknown Source)
at org.apache.commons.javaflow.bytecode.StackRecorder.execute(
StackRecorder.java:95)
at org.apache.commons.javaflow.Continuation.execute(Continuation.java:173)
at org.apache.commons.javaflow.Continuation.continueWith(Continuation.java
:169)
at sample.Sample.main(Sample.java:32)
Exception in thread "main"
----------------------------------------------------------------------
Any thoughts?
Regards,
Valery Silaev
EPAM Systems
P.S. Btw, what is jci option? How it can be used?
Re: JavaFlow & Groovy
Posted by Torsten Curdt <tc...@apache.org>.
> Is is possible to use JavaFlow with Groovy classes (at least,
> generated by
> groovyc, dynamic loading will be superior)?
In theory it should also work with groovy classes. I personally
haven't tested
it but it's also on my TODO list to make sure that's working.
Aside: You can have also have dynamic loading with java (as we have
in cocoon-trunk)
> I'm trying to use Groovy JSR (RC03) with JavaFlow and instantly
> receives
> some mysterious errors, like
> "Cannot invoke method null() on object null".
Can you please exactly describe how you are using it
and please provide a stack trace?
> For example, the test case is simple Runnable (in Groovy) with loop
> and
> Continuation.suspend() inside loop. After the first iteration I get
> error
> mentioned.
How do you do the rewriting?
At build time, through jci or through the classloader?
cheers
--
Torsten