mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
parent
1f004c646f
commit
0004f9cfb2
3 changed files with 14 additions and 24 deletions
|
@ -71,7 +71,7 @@ public class JrubyAckedBatchExtLibrary implements Library {
|
|||
public IRubyObject ruby_get_elements(ThreadContext context)
|
||||
{
|
||||
RubyArray result = context.runtime.newArray();
|
||||
this.batch.getElements().forEach(e -> result.add(new JrubyEventExtLibrary.RubyEvent(context.runtime, (Event)e)));
|
||||
this.batch.getElements().forEach(e -> result.add(JrubyEventExtLibrary.RubyEvent.newRubyEvent(context.runtime, (Event)e)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.jruby.anno.JRubyMethod;
|
|||
import org.jruby.exceptions.RaiseException;
|
||||
import org.jruby.java.proxies.MapJavaProxy;
|
||||
import org.jruby.javasupport.JavaUtil;
|
||||
import org.jruby.runtime.ObjectAllocator;
|
||||
import org.jruby.runtime.ThreadContext;
|
||||
import org.jruby.runtime.builtin.IRubyObject;
|
||||
import org.jruby.runtime.load.Library;
|
||||
|
@ -35,12 +34,9 @@ public class JrubyEventExtLibrary implements Library {
|
|||
public void load(Ruby runtime, boolean wrap) throws IOException {
|
||||
RubyModule module = runtime.defineModule("LogStash");
|
||||
|
||||
RubyClass clazz = runtime.defineClassUnder("Event", runtime.getObject(), new ObjectAllocator() {
|
||||
@Override
|
||||
public IRubyObject allocate(Ruby runtime, RubyClass rubyClass) {
|
||||
return new RubyEvent(runtime, rubyClass);
|
||||
}
|
||||
}, module);
|
||||
RubyClass clazz = runtime.defineClassUnder(
|
||||
"Event", runtime.getObject(), RubyEvent::new, module
|
||||
);
|
||||
|
||||
clazz.setConstant("METADATA", runtime.newString(Event.METADATA));
|
||||
clazz.setConstant("METADATA_BRACKETS", runtime.newString(Event.METADATA_BRACKETS));
|
||||
|
@ -70,31 +66,21 @@ public class JrubyEventExtLibrary implements Library {
|
|||
public static final class RubyEvent extends RubyObject {
|
||||
private Event event;
|
||||
|
||||
public RubyEvent(Ruby runtime, RubyClass klass) {
|
||||
private RubyEvent(Ruby runtime, RubyClass klass) {
|
||||
super(runtime, klass);
|
||||
}
|
||||
|
||||
public RubyEvent(Ruby runtime) {
|
||||
this(runtime, runtime.getModule("LogStash").getClass("Event"));
|
||||
}
|
||||
|
||||
public RubyEvent(Ruby runtime, Event event) {
|
||||
this(runtime);
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public static RubyEvent newRubyEvent(Ruby runtime, Event event) {
|
||||
return new RubyEvent(runtime, event);
|
||||
final RubyEvent ruby =
|
||||
new RubyEvent(runtime, runtime.getModule("LogStash").getClass("Event"));
|
||||
ruby.setEvent(event);
|
||||
return ruby;
|
||||
}
|
||||
|
||||
public Event getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public void setEvent(Event event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
// def initialize(data = {})
|
||||
@JRubyMethod(name = "initialize", optional = 1)
|
||||
public IRubyObject ruby_initialize(ThreadContext context, IRubyObject[] args) {
|
||||
|
@ -312,5 +298,9 @@ public class JrubyEventExtLibrary implements Library {
|
|||
throw context.runtime.newTypeError("wrong argument type " + data.getMetaClass() + " (expected Hash)");
|
||||
}
|
||||
}
|
||||
|
||||
private void setEvent(Event event) {
|
||||
this.event = event;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class JrubyTimestampExtLibrary implements Library {
|
|||
return clazz;
|
||||
}
|
||||
|
||||
@JRubyClass(name = "Timestamp", parent = "Object")
|
||||
@JRubyClass(name = "Timestamp")
|
||||
public static class RubyTimestamp extends RubyObject {
|
||||
|
||||
private Timestamp timestamp;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue