mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
parent
84cd0f96f8
commit
c32db3b2f8
2 changed files with 8 additions and 17 deletions
|
@ -2,30 +2,21 @@ package org.logstash;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PathCache {
|
public final class PathCache {
|
||||||
|
|
||||||
private static PathCache instance = null;
|
private static final ConcurrentHashMap<String, FieldReference> cache = new ConcurrentHashMap<>();
|
||||||
private static ConcurrentHashMap<String, FieldReference> cache = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private FieldReference timestamp;
|
private static final FieldReference timestamp = cache(Event.TIMESTAMP);
|
||||||
|
|
||||||
private static final String BRACKETS_TIMESTAMP = "[" + Event.TIMESTAMP + "]";
|
private static final String BRACKETS_TIMESTAMP = "[" + Event.TIMESTAMP + "]";
|
||||||
|
|
||||||
protected PathCache() {
|
static {
|
||||||
// inject @timestamp
|
// inject @timestamp
|
||||||
this.timestamp = cache(Event.TIMESTAMP);
|
cache(BRACKETS_TIMESTAMP, timestamp);
|
||||||
cache(BRACKETS_TIMESTAMP, this.timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathCache getInstance() {
|
public static boolean isTimestamp(String reference) {
|
||||||
if (instance == null) {
|
return cache(reference) == timestamp;
|
||||||
instance = new PathCache();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTimestamp(String reference) {
|
|
||||||
return (cache(reference) == this.timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FieldReference cache(String reference) {
|
public static FieldReference cache(String reference) {
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class JrubyEventExtLibrary implements Library {
|
||||||
{
|
{
|
||||||
String r = reference.asJavaString();
|
String r = reference.asJavaString();
|
||||||
|
|
||||||
if (PathCache.getInstance().isTimestamp(r)) {
|
if (PathCache.isTimestamp(r)) {
|
||||||
if (!(value instanceof JrubyTimestampExtLibrary.RubyTimestamp)) {
|
if (!(value instanceof JrubyTimestampExtLibrary.RubyTimestamp)) {
|
||||||
throw context.runtime.newTypeError("wrong argument type " + value.getMetaClass() + " (expected LogStash::Timestamp)");
|
throw context.runtime.newTypeError("wrong argument type " + value.getMetaClass() + " (expected LogStash::Timestamp)");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue