logstash icon indicating copy to clipboard operation
logstash copied to clipboard

Support unwrapping (native) Java objects

Open kares opened this issue 5 years ago • 0 comments

JRuby has the notion of some_ruby_obj.to_java, which on the native (ext) end translates to: public <T> T toJava(Class<T> target)

LS should implement these for efficiency but also potentially using its "internals" in some cases (does not necessarily need to be an official documented feature).

The issue came up from the tcp plugin doing :

@logger.to_java(org.apache.logging.log4j.Logger)

... in this case LogStash::Logging::Logger instance being a log4j logger wrapper it make sense to return the underlying logger instance instead of generating a Java proxy that implements the org.apache.logging.log4j.Logger interface.

~~Same for other wrapped pieces such as LogStash::Event wrapping a Java event object (in some cases having co.elastic.logstash.api.Event provides richer APIs). The current API event.to_java.getEvent() is a bit unfortunate esp. since to_java proxying a ext JRuby object has the implication of "self-reflecting" JRuby's ext classes and should be avoided.~~

kares avatar Apr 06 '20 09:04 kares