Repository: activemq-6 Updated Branches: refs/heads/master f282c2966 -> 2e1435205
ACTIVEMQ6-61 SelectorParser package conflict with openwire tests The SelectorParser class in amq6 source code conflicts with the same class in activemq 5 client jar. The activemq 5 client jar is needed to run openwire tests where the activemq5 client interacts with amq6 broker. In tests they are usually in the same VM, so depending on the classpath order, whichever class is loaded it will be used by both client and broker. Unfortunately the method parse() in the class has different return types in the client jar and broker side jar. That will cause NoSuchMethod exception. The fix moves the broker side class into a different package, i.e. from org.apache.activemq.selector.SelectorParser to org.apache.activemq.selector.impl.SelectorParser Project: http://git-wip-us.apache.org/repos/asf/activemq-6/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-6/commit/7ffa2379 Tree: http://git-wip-us.apache.org/repos/asf/activemq-6/tree/7ffa2379 Diff: http://git-wip-us.apache.org/repos/asf/activemq-6/diff/7ffa2379 Branch: refs/heads/master Commit: 7ffa23799be0c0e43cc2db5423bac3ffbb06a7a8 Parents: f282c29 Author: Howard Gao <[email protected]> Authored: Wed Dec 17 09:56:11 2014 +0800 Committer: Howard Gao <[email protected]> Committed: Wed Dec 17 10:02:33 2014 +0800 ---------------------------------------------------------------------- .../activemq/jms/client/ActiveMQSession.java | 2 +- .../org/apache/activemq/selector/LRUCache.java | 100 --------------- .../activemq/selector/SelectorParser.java | 123 ------------------- .../apache/activemq/selector/impl/LRUCache.java | 100 +++++++++++++++ .../activemq/selector/impl/SelectorParser.java | 123 +++++++++++++++++++ .../activemq/selector/SelectorParserTest.java | 1 + .../apache/activemq/selector/SelectorTest.java | 1 + .../activemq/core/filter/impl/FilterImpl.java | 2 +- 8 files changed, 227 insertions(+), 225 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQSession.java ---------------------------------------------------------------------- diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQSession.java b/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQSession.java index d027fb3..bb79174 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQSession.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQSession.java @@ -52,7 +52,7 @@ import javax.transaction.xa.XAResource; import org.apache.activemq.api.core.ActiveMQException; import org.apache.activemq.api.core.ActiveMQQueueExistsException; import org.apache.activemq.selector.filter.FilterException; -import org.apache.activemq.selector.SelectorParser; +import org.apache.activemq.selector.impl.SelectorParser; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.client.ClientConsumer; import org.apache.activemq.api.core.client.ClientProducer; http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-selector/src/main/java/org/apache/activemq/selector/LRUCache.java ---------------------------------------------------------------------- diff --git a/activemq-selector/src/main/java/org/apache/activemq/selector/LRUCache.java b/activemq-selector/src/main/java/org/apache/activemq/selector/LRUCache.java deleted file mode 100755 index f454fcf..0000000 --- a/activemq-selector/src/main/java/org/apache/activemq/selector/LRUCache.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.selector; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * A Simple LRU Cache - * - * @param <K> - * @param <V> - */ - -public class LRUCache<K, V> extends LinkedHashMap<K, V> -{ - private static final long serialVersionUID = -342098639681884413L; - protected int maxCacheSize = 10000; - - /** - * Default constructor for an LRU Cache The default capacity is 10000 - */ - public LRUCache() - { - this(0, 10000, 0.75f, true); - } - - /** - * Constructs a LRUCache with a maximum capacity - * - * @param maximumCacheSize - */ - public LRUCache(int maximumCacheSize) - { - this(0, maximumCacheSize, 0.75f, true); - } - - /** - * Constructs an empty <tt>LRUCache</tt> instance with the specified - * initial capacity, maximumCacheSize,load factor and ordering mode. - * - * @param initialCapacity the initial capacity. - * @param maximumCacheSize - * @param loadFactor the load factor. - * @param accessOrder the ordering mode - <tt>true</tt> for access-order, - * <tt>false</tt> for insertion-order. - * @throws IllegalArgumentException if the initial capacity is negative or - * the load factor is non-positive. - */ - - public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) - { - super(initialCapacity, loadFactor, accessOrder); - this.maxCacheSize = maximumCacheSize; - } - - /** - * @return Returns the maxCacheSize. - */ - public int getMaxCacheSize() - { - return maxCacheSize; - } - - /** - * @param maxCacheSize The maxCacheSize to set. - */ - public void setMaxCacheSize(int maxCacheSize) - { - this.maxCacheSize = maxCacheSize; - } - - protected boolean removeEldestEntry(Map.Entry<K, V> eldest) - { - if (size() > maxCacheSize) - { - onCacheEviction(eldest); - return true; - } - return false; - } - - protected void onCacheEviction(Map.Entry<K, V> eldest) - { - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-selector/src/main/java/org/apache/activemq/selector/SelectorParser.java ---------------------------------------------------------------------- diff --git a/activemq-selector/src/main/java/org/apache/activemq/selector/SelectorParser.java b/activemq-selector/src/main/java/org/apache/activemq/selector/SelectorParser.java deleted file mode 100644 index 367d20a..0000000 --- a/activemq-selector/src/main/java/org/apache/activemq/selector/SelectorParser.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.selector; - -import java.io.StringReader; - -import org.apache.activemq.selector.filter.BooleanExpression; -import org.apache.activemq.selector.filter.ComparisonExpression; -import org.apache.activemq.selector.filter.FilterException; -import org.apache.activemq.selector.hyphenated.HyphenatedParser; -import org.apache.activemq.selector.strict.StrictParser; - -/** - */ -public class SelectorParser -{ - - private static final LRUCache 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; - } - - 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(); - } - 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(); - } - } - } - } - - public static void clearCache() - { - cache.clear(); - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-selector/src/main/java/org/apache/activemq/selector/impl/LRUCache.java ---------------------------------------------------------------------- diff --git a/activemq-selector/src/main/java/org/apache/activemq/selector/impl/LRUCache.java b/activemq-selector/src/main/java/org/apache/activemq/selector/impl/LRUCache.java new file mode 100644 index 0000000..4c535d8 --- /dev/null +++ b/activemq-selector/src/main/java/org/apache/activemq/selector/impl/LRUCache.java @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.selector.impl; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A Simple LRU Cache + * + * @param <K> + * @param <V> + */ + +public class LRUCache<K, V> extends LinkedHashMap<K, V> +{ + private static final long serialVersionUID = -342098639681884413L; + protected int maxCacheSize = 10000; + + /** + * Default constructor for an LRU Cache The default capacity is 10000 + */ + public LRUCache() + { + this(0, 10000, 0.75f, true); + } + + /** + * Constructs a LRUCache with a maximum capacity + * + * @param maximumCacheSize + */ + public LRUCache(int maximumCacheSize) + { + this(0, maximumCacheSize, 0.75f, true); + } + + /** + * Constructs an empty <tt>LRUCache</tt> instance with the specified + * initial capacity, maximumCacheSize,load factor and ordering mode. + * + * @param initialCapacity the initial capacity. + * @param maximumCacheSize + * @param loadFactor the load factor. + * @param accessOrder the ordering mode - <tt>true</tt> for access-order, + * <tt>false</tt> for insertion-order. + * @throws IllegalArgumentException if the initial capacity is negative or + * the load factor is non-positive. + */ + + public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) + { + super(initialCapacity, loadFactor, accessOrder); + this.maxCacheSize = maximumCacheSize; + } + + /** + * @return Returns the maxCacheSize. + */ + public int getMaxCacheSize() + { + return maxCacheSize; + } + + /** + * @param maxCacheSize The maxCacheSize to set. + */ + public void setMaxCacheSize(int maxCacheSize) + { + this.maxCacheSize = maxCacheSize; + } + + protected boolean removeEldestEntry(Map.Entry<K, V> eldest) + { + if (size() > maxCacheSize) + { + onCacheEviction(eldest); + return true; + } + return false; + } + + protected void onCacheEviction(Map.Entry<K, V> eldest) + { + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-selector/src/main/java/org/apache/activemq/selector/impl/SelectorParser.java ---------------------------------------------------------------------- diff --git a/activemq-selector/src/main/java/org/apache/activemq/selector/impl/SelectorParser.java b/activemq-selector/src/main/java/org/apache/activemq/selector/impl/SelectorParser.java new file mode 100644 index 0000000..27c9081 --- /dev/null +++ b/activemq-selector/src/main/java/org/apache/activemq/selector/impl/SelectorParser.java @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.selector.impl; + +import java.io.StringReader; + +import org.apache.activemq.selector.filter.BooleanExpression; +import org.apache.activemq.selector.filter.ComparisonExpression; +import org.apache.activemq.selector.filter.FilterException; +import org.apache.activemq.selector.hyphenated.HyphenatedParser; +import org.apache.activemq.selector.strict.StrictParser; + +/** + */ +public class SelectorParser +{ + + private static final LRUCache 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; + } + + 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(); + } + 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(); + } + } + } + } + + public static void clearCache() + { + cache.clear(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java ---------------------------------------------------------------------- diff --git a/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java b/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java index 4699ea2..e48b112 100755 --- a/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java +++ b/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java @@ -22,6 +22,7 @@ import org.apache.activemq.selector.filter.Expression; import org.apache.activemq.selector.filter.LogicExpression; import org.apache.activemq.selector.filter.PropertyExpression; import org.apache.activemq.selector.filter.XPathExpression; +import org.apache.activemq.selector.impl.SelectorParser; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java ---------------------------------------------------------------------- diff --git a/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java b/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java index c0db4a9..0e629de 100755 --- a/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java +++ b/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java @@ -21,6 +21,7 @@ import java.util.HashMap; import org.apache.activemq.selector.filter.BooleanExpression; import org.apache.activemq.selector.filter.FilterException; import org.apache.activemq.selector.filter.Filterable; +import org.apache.activemq.selector.impl.SelectorParser; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/activemq-6/blob/7ffa2379/activemq-server/src/main/java/org/apache/activemq/core/filter/impl/FilterImpl.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/filter/impl/FilterImpl.java b/activemq-server/src/main/java/org/apache/activemq/core/filter/impl/FilterImpl.java index bc843b9..72d84c0 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/filter/impl/FilterImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/filter/impl/FilterImpl.java @@ -21,7 +21,7 @@ import org.apache.activemq.core.server.ActiveMQServerLogger; import org.apache.activemq.selector.filter.BooleanExpression; import org.apache.activemq.selector.filter.FilterException; import org.apache.activemq.selector.filter.Filterable; -import org.apache.activemq.selector.SelectorParser; +import org.apache.activemq.selector.impl.SelectorParser; import org.apache.activemq.api.core.FilterConstants; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.core.filter.Filter;
