Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
JRuby with Spring DM Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JRuby with Spring DM

    Hi,

    I'm trying to run a JRuby script with Spring DM and run into problems.

    Java Base class
    Code:
    package org.codingkata.unit.api; 
    
    public abstract class BaseKataSolution { 
        abstract String reply(); 
    }
    JRuby Class
    Code:
    class MyKata 
      include org.codingkata.unit.api.BaseKataSolution 
    
      def reply 
        return "hello world" 
      end 
    end
    Spring Beans context
    Code:
    [...] 
       <osgi:service 
               ref="kataSolution" 
               interface="org.codingkata.unit.api.BaseKataSolution"/> 
       [...]
    So far so clear - the JRuby class inherits the 'BaseKataSolution' class. In Spring I configure this as the interface (cglib is present, in the java and groovy version everything works flawlessly).

    But when I try to run a test which loads the JRuby class, it results in:
    Exported service object does not implement the given interface: class org.codingkata.unit.MyKata is not assignable to interface org.codingkata.unit.api.BaseKataSolution.

    Then I tried to look at the classes in detail by using a decompiler:

    Decompiled Groovy version
    Code:
    public class MyKata extends BaseKataSolution
      implements GroovyObject 
    { 
      public MyKata() 
      { 
        MyKata this; 
        [...] 
      } 
    
      public String reply() 
      { 
        for (CallSite[] arrayOfCallSite = $getCallSiteArray(); ; return ((String)ScriptBytecodeAdapter.castToType("hello world", $get$$class$java$lang$String()))); 
      } 
      [...] 
    }
    Decompiled JRuby version
    Code:
    public class MyKata extends AbstractScript
    { 
      private final Class $class = Class.forName("org.codingkata.unit.MyKata"); 
    
      public MyKata() 
      { 
        [...] 
      } 
    
      @JRubyMethod(name="reply", frame=true, required=0, optional=0, rest=-1) 
      public static IRubyObject method__1$RUBY$reply(MyKata paramMyKata, ThreadContext paramThreadContext, IRubyObject paramIRubyObject, Block paramBlock) { Ruby localRuby = paramThreadContext.getRuntime(); IRubyObject localIRubyObject = localRuby.getNil(); setPosition(paramThreadContext, 5); return paramMyKata.getString1(localRuby); 
      } 
    
      [...] 
    }
    Obviously Groovy directly inherits the base class while JRuby does not. Bummer. I opened a discussion in the JRuby mailing list if this is the desired behavior.

    Still, I'm wondering if there is anything I can do to make it work with Spring DM - because I expect most of the JSR223 languages to act like JRuby.

    Any ideas?

    Cheers,
    stephanos

  • #2
    Somebody in the JRuby board proposed a Proxy - but I can't think of how to combine this with Spring DM on the one side and a dynamic JSR 223 script on the other.

    Do you? Or is that not a good approach?

    Cheers,
    stephanos

    Comment


    • #3
      You could avoid this problem by using a ServiceFactory which allows one to register a factory rather then the object directly.

      Comment

      Working...
      X