mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
parent
30e7adfdae
commit
18018e152a
1 changed files with 33 additions and 1 deletions
|
@ -2,6 +2,7 @@ package org.logstash.ext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import org.jruby.Ruby;
|
import org.jruby.Ruby;
|
||||||
import org.jruby.RubyArray;
|
import org.jruby.RubyArray;
|
||||||
import org.jruby.RubyBoolean;
|
import org.jruby.RubyBoolean;
|
||||||
|
@ -65,9 +66,21 @@ public class JrubyEventExtLibrary implements Library {
|
||||||
|
|
||||||
@JRubyClass(name = "Event")
|
@JRubyClass(name = "Event")
|
||||||
public static final class RubyEvent extends RubyObject {
|
public static final class RubyEvent extends RubyObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sequence number generator, for generating {@link RubyEvent#hash}.
|
||||||
|
*/
|
||||||
|
private static final AtomicLong SEQUENCE_GENERATOR = new AtomicLong(1L);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hashcode of this instance. Used to avoid the more expensive {@link RubyObject#hashCode()}
|
||||||
|
* since we only care about reference equality for this class anyway.
|
||||||
|
*/
|
||||||
|
private final int hash = nextHash();
|
||||||
|
|
||||||
private Event event;
|
private Event event;
|
||||||
|
|
||||||
private RubyEvent(Ruby runtime, RubyClass klass) {
|
private RubyEvent(final Ruby runtime, final RubyClass klass) {
|
||||||
super(runtime, klass);
|
super(runtime, klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,6 +299,16 @@ public class JrubyEventExtLibrary implements Library {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object that) {
|
||||||
|
return this == that;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cold path for the Ruby constructor
|
* Cold path for the Ruby constructor
|
||||||
* {@link JrubyEventExtLibrary.RubyEvent#ruby_initialize(ThreadContext, IRubyObject[])} for
|
* {@link JrubyEventExtLibrary.RubyEvent#ruby_initialize(ThreadContext, IRubyObject[])} for
|
||||||
|
@ -309,5 +332,14 @@ public class JrubyEventExtLibrary implements Library {
|
||||||
private void setEvent(Event event) {
|
private void setEvent(Event event) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a fixed hashcode.
|
||||||
|
* @return HashCode value
|
||||||
|
*/
|
||||||
|
private static int nextHash() {
|
||||||
|
final long sequence = SEQUENCE_GENERATOR.incrementAndGet();
|
||||||
|
return (int) (sequence ^ sequence >>> 32) + 31;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue