JSR 223-Embedded question

Hi,

I have a ruby script

— myScript.rb
def avail
return 1
end

That I can engine.eval () just fine. Also when I do

Invocable inv = (Incovable)engine;
inv.invokeFuntion(“avail”);

this works for a few times and then after some time I get an exception
(below) - any idea what may cause the
engine to “forget” my script ?

Thanks
Heiko

:1: undefined method avail' for main:Object (NoMethodError) org.jruby.embed.InvokeFailedException: undefined methodavail’ for
main:Object
at
org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.call(EmbedRubyObjectAdapterImpl.java:369)
at
org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.callMethod(EmbedRubyObjectAdapterImpl.java:140)
at
org.jruby.embed.ScriptingContainer.callMethod(ScriptingContainer.java:557)
at
org.jruby.embed.jsr223.JRubyEngine.invokeFunction(JRubyEngine.java:276)
at
org.rhq.modules.plugins.script2.ScriptComponent.getAvailability(ScriptComponent.java:59)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.rhq.core.pc.inventory.ResourceContainer$ComponentInvocationThread.call(ResourceContainer.java:525)
at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)
Caused by: org.jruby.exceptions.RaiseException: undefined method avail' for main:Object at Kernel.avail(:1) at (unknown).(unknown)(:1) java.lang.NoSuchMethodException: undefined methodavail’ for
main:Object
at
org.jruby.embed.jsr223.JRubyEngine.wrapMethodException(JRubyEngine.java:266)
at
org.jruby.embed.jsr223.JRubyEngine.invokeFunction(JRubyEngine.java:281)
at
org.rhq.modules.plugins.script2.ScriptComponent.getAvailability(ScriptComponent.java:59)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Dec 8, 2009 at 7:22 AM, Heiko W.Rupp [email protected] wrote:

That I can engine.eval () just fine. Also when I do

Invocable inv = (Incovable)engine;
inv.invokeFuntion(“avail”);

this works for a few times and then after some time I get an exception (below) - any idea what may cause the
engine to “forget” my script ?

This sounds like bug, but let me confirm. Did you used JSR223 engine
with default settings? If you chose threadsafe for a local context
type, you have a slight chance to get this kind of trouble.

-Yoko

   at org.jruby.embed.jsr223.JRubyEngine.invokeFunction(JRubyEngine.java:276)

Caused by: org.jruby.exceptions.RaiseException: undefined method `avail’ for main:Object


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Yoko,

Am 09.12.2009 um 16:29 schrieb Yoko H.:

This sounds like bug, but let me confirm. Did you used JSR223 engine
with default settings? If you chose threadsafe for a local context

Yes. From the 1.4-complete package.

type, you have a slight chance to get this kind of trouble.

Could this come from the fact that perhaps there are 2 invocations
of Invocable.invokeFunction() on different functions in my script
at the same time?

Thanks
Heiko


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Dec 9, 2009 at 11:16 AM, Heiko W.Rupp [email protected] wrote:

Yoko,

Am 09.12.2009 um 16:29 schrieb Yoko H.:

This sounds like bug, but let me confirm. Did you used JSR223 engine
with default settings? If you chose threadsafe for a local context

Yes. From the 1.4-complete package.

Then, a possible reason is that the thread used to ‘evaluate’ avail
method and the thread used to ‘invoke’ avail method are not the same.

type, you have a slight chance to get this kind of trouble.

Could this come from the fact that perhaps there are 2 invocations
of Invocable.invokeFunction() on different functions in my script
at the same time?

This might be the reason. But, if you executed it on a multi-threaded
platform, just one invocation might cause this kind of problem. To
avoid this, I recommend changing it to a class method and using
invokeMethod() of JSR223 API. If you have a receiver returned from an
evaluation, you can invoke the method of the receiver has. This isn’t
usually affected by threads. If you can use Embed Core instead of
JSR223, you have an option to use runtime.getTopSel() to get the
receiver. In this case, you don’t need to rewrite a top level method
to a class method. For example,

    String script =
            "def avail\n" +
            "  return 1\n" +
            "end";
    ScriptingContainer container = new

ScriptingContainer(LocalContextScope.THREADSAFE);
container.runScriptlet(script);
IRubyObject recv = container.getRuntime().getTopSelf();
Long ret = (Long) container.callMethod(recv, “avail”,
Object.class);

-Yoko


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email