mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
#7318 stop creating a new RubyTimestamp on every timestamp get
Fixes #8334
This commit is contained in:
parent
78e89595ff
commit
6f8c2a0d36
2 changed files with 12 additions and 7 deletions
|
@ -47,7 +47,7 @@ public final class Event implements Cloneable, Queueable {
|
||||||
this.data = new ConvertedMap(10);
|
this.data = new ConvertedMap(10);
|
||||||
this.data.putInterned(VERSION, VERSION_ONE);
|
this.data.putInterned(VERSION, VERSION_ONE);
|
||||||
this.cancelled = false;
|
this.cancelled = false;
|
||||||
this.data.putInterned(TIMESTAMP, new Timestamp());
|
setTimestamp(Timestamp.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +82,7 @@ public final class Event implements Cloneable, Queueable {
|
||||||
Object providedTimestamp = data.get(TIMESTAMP);
|
Object providedTimestamp = data.get(TIMESTAMP);
|
||||||
// keep reference to the parsedTimestamp for tagging below
|
// keep reference to the parsedTimestamp for tagging below
|
||||||
Timestamp parsedTimestamp = initTimestamp(providedTimestamp);
|
Timestamp parsedTimestamp = initTimestamp(providedTimestamp);
|
||||||
data.putInterned(TIMESTAMP, parsedTimestamp == null ? Timestamp.now() : parsedTimestamp);
|
setTimestamp(parsedTimestamp == null ? Timestamp.now() : parsedTimestamp);
|
||||||
// the tag() method has to be called after the Accessors initialization
|
// the tag() method has to be called after the Accessors initialization
|
||||||
if (parsedTimestamp == null) {
|
if (parsedTimestamp == null) {
|
||||||
tag(TIMESTAMP_FAILURE_TAG);
|
tag(TIMESTAMP_FAILURE_TAG);
|
||||||
|
@ -111,16 +111,19 @@ public final class Event implements Cloneable, Queueable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getTimestamp() throws IOException {
|
public Timestamp getTimestamp() throws IOException {
|
||||||
final Timestamp timestamp = (Timestamp) data.get(TIMESTAMP);
|
final JrubyTimestampExtLibrary.RubyTimestamp timestamp =
|
||||||
|
(JrubyTimestampExtLibrary.RubyTimestamp) data.get(TIMESTAMP);
|
||||||
if (timestamp != null) {
|
if (timestamp != null) {
|
||||||
return timestamp;
|
return timestamp.getTimestamp();
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("fails");
|
throw new IOException("fails");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimestamp(Timestamp t) {
|
public void setTimestamp(Timestamp t) {
|
||||||
this.data.putInterned(TIMESTAMP, t);
|
this.data.putInterned(
|
||||||
|
TIMESTAMP, JrubyTimestampExtLibrary.RubyTimestamp.newRubyTimestamp(RubyUtil.RUBY, t)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getField(final String reference) {
|
public Object getField(final String reference) {
|
||||||
|
|
|
@ -288,8 +288,10 @@ public final class JrubyEventExtLibrary implements Library {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JRubyMethod(name = "timestamp")
|
@JRubyMethod(name = "timestamp")
|
||||||
public IRubyObject ruby_timestamp(ThreadContext context) throws IOException {
|
public IRubyObject ruby_timestamp(ThreadContext context) {
|
||||||
return new JrubyTimestampExtLibrary.RubyTimestamp(context.getRuntime(), this.event.getTimestamp());
|
// We can just cast to IRubyObject here, because we know that Event stores a
|
||||||
|
// RubyTimestamp internally.
|
||||||
|
return (IRubyObject) event.getUnconvertedField(FieldReference.TIMESTAMP_REFERENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JRubyMethod(name = "timestamp=", required = 1)
|
@JRubyMethod(name = "timestamp=", required = 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue