MINOR: Remove needless singleton use in pathcache

Fixes #7624
This commit is contained in:
Armin 2017-07-09 19:34:10 +02:00 committed by Armin Braun
parent 84cd0f96f8
commit c32db3b2f8
2 changed files with 8 additions and 17 deletions

View file

@ -2,30 +2,21 @@ package org.logstash;
import java.util.concurrent.ConcurrentHashMap;
public class PathCache {
public final class PathCache {
private static PathCache instance = null;
private static ConcurrentHashMap<String, FieldReference> cache = new ConcurrentHashMap<>();
private static final 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 + "]";
protected PathCache() {
static {
// inject @timestamp
this.timestamp = cache(Event.TIMESTAMP);
cache(BRACKETS_TIMESTAMP, this.timestamp);
cache(BRACKETS_TIMESTAMP, timestamp);
}
public static PathCache getInstance() {
if (instance == null) {
instance = new PathCache();
}
return instance;
}
public boolean isTimestamp(String reference) {
return (cache(reference) == this.timestamp);
public static boolean isTimestamp(String reference) {
return cache(reference) == timestamp;
}
public static FieldReference cache(String reference) {

View file

@ -120,7 +120,7 @@ public class JrubyEventExtLibrary implements Library {
{
String r = reference.asJavaString();
if (PathCache.getInstance().isTimestamp(r)) {
if (PathCache.isTimestamp(r)) {
if (!(value instanceof JrubyTimestampExtLibrary.RubyTimestamp)) {
throw context.runtime.newTypeError("wrong argument type " + value.getMetaClass() + " (expected LogStash::Timestamp)");
}