ARTEMIS-2017 Eliminate LRUCache from SelectorParser

The LRUCache is not thread-safe and it's usage in SelectorParser could
cause growth beyond its configured max size. Instead of modifying the
LRUCache to be thread-safe or synchronizing access to it in
SelectorParser it should just be removed since it's not on a hot path.
This commit is contained in:
Justin Bertram 2018-08-08 11:10:04 -05:00 committed by Clebert Suconic
parent 01800233c3
commit 2d7c5322a7
1 changed files with 43 additions and 59 deletions

View File

@ -24,23 +24,14 @@ import org.apache.activemq.artemis.selector.filter.FilterException;
import org.apache.activemq.artemis.selector.hyphenated.HyphenatedParser;
import org.apache.activemq.artemis.selector.strict.StrictParser;
/**
*/
public class SelectorParser {
private static final LRUCache<String, Object> cache = new LRUCache<>(100);
private static final String CONVERT_STRING_EXPRESSIONS_PREFIX = "convert_string_expressions:";
private static final String HYPHENATED_PROPS_PREFIX = "hyphenated_props:";
private static final String NO_CONVERT_STRING_EXPRESSIONS_PREFIX = "no_convert_string_expressions:";
private static final String NO_HYPHENATED_PROPS_PREFIX = "no_hyphenated_props:";
public static BooleanExpression parse(String sql) throws FilterException {
Object result = cache.get(sql);
if (result instanceof FilterException) {
throw (FilterException) result;
} else if (result instanceof BooleanExpression) {
return (BooleanExpression) result;
} else {
String actual = sql;
boolean convertStringExpressions = false;
boolean hyphenatedProps = false;
@ -80,11 +71,9 @@ public class SelectorParser {
StrictParser parser = new StrictParser(new StringReader(actual));
e = parser.JmsSelector();
}
cache.put(sql, e);
return e;
} catch (Throwable e) {
FilterException fe = new FilterException(actual, e);
cache.put(sql, fe);
throw fe;
} finally {
if (convertStringExpressions) {
@ -92,9 +81,4 @@ public class SelectorParser {
}
}
}
}
public static void clearCache() {
cache.clear();
}
}