-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
become_java! does not support concrete class extension #2359
Comments
Looks like this makes using
as you need to pass Java class to |
@paneq can you use dependency injection? i was able to get around this problem that way. |
@mooreniemi Thanks for the suggestion, sounds very good and interesting. Could you elaborate though what you have in mind exactly? Maybe a small contrived example? |
@paneq The basic idea is that rather than inheriting directly on the Ruby object directly, you just delegate forward relevant calls to an embedded Ruby object. My requirement was to have pure Ruby endpoints that all inherited from a Java framework. When I needed to inherit from public class EndpointWrapper extends BaseEndpoint {
// this is the JRuby endpoint we'll inject in
protected static IRubyObject endpoint;
public EndpointWrapper() {
}
// can't inject on construction, so need this setter
public static void setEndpoint(IRubyObject rubyEndpoint) {
endpoint = rubyEndpoint;
}
@Override
protected Map execute(CheetahQuery query) throws Exception {
ThreadContext context = endpoint.getRuntime().getCurrentContext();
// we're forwarding the execute method to our injected dep
IRubyObject called = endpoint.callMethod(
context,
"execute",
JavaObject.wrap(
endpoint.getRuntime(),
query
)
);
return called.convertToHash();
}
} So things are basically like this:
|
I just bumped into this, I would love to be able to provide Ruby-classes to a Java framework (Apache NiFi in this case). But in order for them to work, I need them to be able to subclass from a base class of the Java framework. The workaround I have now, is to have a generated Java-written class, that calls into the ruby class. Quite similar to what @mooreniemi has done. |
This is a long standing issue that will likely require a major overhaul of how we do class extension. Sadly, many things require that same overhaul, and the code involved is very rough.
Original issue: http://jira.codehaus.org/browse/JRUBY-6105
Example code that fails to work:
The text was updated successfully, but these errors were encountered: