You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2018/08/09 23:36:29 UTC
[1/2] activemq-artemis git commit: ARTEMIS-2017 Eliminate LRUCache
from SelectorParser
Repository: activemq-artemis
Updated Branches:
refs/heads/master 01800233c -> d503bbb1b
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.
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/2d7c5322
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/2d7c5322
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/2d7c5322
Branch: refs/heads/master
Commit: 2d7c5322a79e0ffa45676e50f3453d5530af78c2
Parents: 0180023
Author: Justin Bertram <jb...@apache.org>
Authored: Wed Aug 8 11:10:04 2018 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Aug 9 19:36:22 2018 -0400
----------------------------------------------------------------------
.../artemis/selector/impl/SelectorParser.java | 102 ++++++++-----------
1 file changed, 43 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2d7c5322/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/impl/SelectorParser.java
----------------------------------------------------------------------
diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/impl/SelectorParser.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/impl/SelectorParser.java
index 6812f9a..f169541 100644
--- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/impl/SelectorParser.java
+++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/impl/SelectorParser.java
@@ -24,77 +24,61 @@ 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;
- while (true) {
- if (actual.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
- convertStringExpressions = true;
- actual = actual.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
- continue;
- }
- if (actual.startsWith(HYPHENATED_PROPS_PREFIX)) {
- hyphenatedProps = true;
- actual = actual.substring(HYPHENATED_PROPS_PREFIX.length());
- continue;
- }
- if (actual.startsWith(NO_CONVERT_STRING_EXPRESSIONS_PREFIX)) {
- convertStringExpressions = false;
- actual = actual.substring(NO_CONVERT_STRING_EXPRESSIONS_PREFIX.length());
- continue;
- }
- if (actual.startsWith(NO_HYPHENATED_PROPS_PREFIX)) {
- hyphenatedProps = false;
- actual = actual.substring(NO_HYPHENATED_PROPS_PREFIX.length());
- continue;
- }
- break;
+ String actual = sql;
+ boolean convertStringExpressions = false;
+ boolean hyphenatedProps = false;
+ while (true) {
+ if (actual.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
+ convertStringExpressions = true;
+ actual = actual.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
+ continue;
}
-
- if (convertStringExpressions) {
- ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
+ if (actual.startsWith(HYPHENATED_PROPS_PREFIX)) {
+ hyphenatedProps = true;
+ actual = actual.substring(HYPHENATED_PROPS_PREFIX.length());
+ continue;
}
- try {
- BooleanExpression e = null;
- if (hyphenatedProps) {
- HyphenatedParser parser = new HyphenatedParser(new StringReader(actual));
- e = parser.JmsSelector();
- } else {
- 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) {
- ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
- }
+ if (actual.startsWith(NO_CONVERT_STRING_EXPRESSIONS_PREFIX)) {
+ convertStringExpressions = false;
+ actual = actual.substring(NO_CONVERT_STRING_EXPRESSIONS_PREFIX.length());
+ continue;
}
+ if (actual.startsWith(NO_HYPHENATED_PROPS_PREFIX)) {
+ hyphenatedProps = false;
+ actual = actual.substring(NO_HYPHENATED_PROPS_PREFIX.length());
+ continue;
+ }
+ break;
}
- }
- public static void clearCache() {
- cache.clear();
+ if (convertStringExpressions) {
+ ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
+ }
+ try {
+ BooleanExpression e = null;
+ if (hyphenatedProps) {
+ HyphenatedParser parser = new HyphenatedParser(new StringReader(actual));
+ e = parser.JmsSelector();
+ } else {
+ StrictParser parser = new StrictParser(new StringReader(actual));
+ e = parser.JmsSelector();
+ }
+ return e;
+ } catch (Throwable e) {
+ FilterException fe = new FilterException(actual, e);
+ throw fe;
+ } finally {
+ if (convertStringExpressions) {
+ ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
+ }
+ }
}
}
[2/2] activemq-artemis git commit: This closes #2228
Posted by cl...@apache.org.
This closes #2228
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/d503bbb1
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/d503bbb1
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/d503bbb1
Branch: refs/heads/master
Commit: d503bbb1ba2f42041627edcfda31783aa269fd62
Parents: 0180023 2d7c532
Author: Clebert Suconic <cl...@apache.org>
Authored: Thu Aug 9 19:36:23 2018 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Aug 9 19:36:23 2018 -0400
----------------------------------------------------------------------
.../artemis/selector/impl/SelectorParser.java | 102 ++++++++-----------
1 file changed, 43 insertions(+), 59 deletions(-)
----------------------------------------------------------------------