You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2012/07/25 23:28:26 UTC
svn commit: r1365771 - in /activemq/activemq-apollo/trunk: apollo-broker/
apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/
apollo-distro/src/main/descriptors/ apollo-selector/
apollo-selector/src/main/java/org/apache/activemq/apollo/filt...
Author: chirino
Date: Wed Jul 25 21:28:25 2012
New Revision: 1365771
URL: http://svn.apache.org/viewvc?rev=1365771&view=rev
Log:
Eliminated most of the dependencies of the apollo-selector module so it can more easily be re-used by other projects.
Added:
activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/
activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/LRUCache.java (with props)
Modified:
activemq/activemq-apollo/trunk/apollo-broker/pom.xml
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
activemq/activemq-apollo/trunk/apollo-distro/src/main/descriptors/common-bin.xml
activemq/activemq-apollo/trunk/apollo-selector/pom.xml
activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XPathExpression.java
activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XalanXPathEvaluator.java (contents, props changed)
activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
Modified: activemq/activemq-apollo/trunk/apollo-broker/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/pom.xml?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/pom.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/pom.xml Wed Jul 25 21:28:25 2012
@@ -85,6 +85,12 @@
<version>${snakeyaml-version}</version>
</dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.6.0</version>
+ </dependency>
+
<!-- for optional web admin -->
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala Wed Jul 25 21:28:25 2012
@@ -38,6 +38,8 @@ import security.SecuredResource.BrokerKi
import reflect.BeanProperty
import java.net.InetSocketAddress
import org.fusesource.hawtdispatch.util.BufferPools
+import org.apache.activemq.apollo.filter.{Filterable, XPathExpression, XalanXPathEvaluator}
+import org.xml.sax.InputSource
/**
* <p>
@@ -156,6 +158,22 @@ object Broker extends Log {
private val SERVICE_TIMEOUT = 1000*5;
val buffer_pools = new BufferPools
+ // Make sure XPATH selector support is enabled and optimize a little.
+ XPathExpression.XPATH_EVALUATOR_FACTORY = new XPathExpression.XPathEvaluatorFactory {
+ def create(xpath: String): XPathExpression.XPathEvaluator = {
+ new XalanXPathEvaluator(xpath) {
+ override def evaluate(m: Filterable): Boolean = {
+ val body: Buffer = m.getBodyAs(classOf[Buffer])
+ if (body != null) {
+ evaluate(new InputSource(new BufferInputStream(body)))
+ } else {
+ super.evaluate(m)
+ }
+ }
+ }
+ }
+ }
+
def class_loader:ClassLoader = ClassFinder.class_loader
@volatile
Modified: activemq/activemq-apollo/trunk/apollo-distro/src/main/descriptors/common-bin.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/descriptors/common-bin.xml?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/descriptors/common-bin.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/descriptors/common-bin.xml Wed Jul 25 21:28:25 2012
@@ -40,6 +40,9 @@
<include>org.fusesource.leveldbjni:*</include>
<include>org.fusesource.hawtjni:*</include>
+ <!-- for XPATH selector support -->
+ <include>xalan:xalan</include>
+
<!-- security stuff -->
<include>org.jasypt:jasypt</include>
<include>commons-lang:commons-lang</include>
Modified: activemq/activemq-apollo/trunk/apollo-selector/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/pom.xml?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/pom.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/pom.xml Wed Jul 25 21:28:25 2012
@@ -28,7 +28,6 @@
<groupId>org.apache.activemq</groupId>
<artifactId>apollo-selector</artifactId>
<version>99-trunk-SNAPSHOT</version>
- <!-- <packaging>bundle</packaging> -->
<name>${project.artifactId}</name>
@@ -39,31 +38,6 @@
<dependencies>
<dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>apollo-util</artifactId>
- <version>99-trunk-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.fusesource.hawtbuf</groupId>
- <artifactId>hawtbuf</artifactId>
- <version>${hawtbuf-version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j-version}</version>
- </dependency>
-
- <!-- TODO: try to remove this dependency -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>${spring-version}</version>
- </dependency>
-
- <dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.6.0</version>
Modified: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XPathExpression.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XPathExpression.java?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XPathExpression.java (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XPathExpression.java Wed Jul 25 21:28:25 2012
@@ -16,76 +16,42 @@
*/
package org.apache.activemq.apollo.filter;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
/**
* Used to evaluate an XPath Expression in a JMS selector.
*/
public final class XPathExpression implements BooleanExpression {
- private static final Logger LOG = LoggerFactory.getLogger(XPathExpression.class);
- private static final String EVALUATOR_SYSTEM_PROPERTY = "org.apache.activemq.XPathEvaluatorClassName";
- private static final String DEFAULT_EVALUATOR_CLASS_NAME = XalanXPathEvaluator.class.getName();
-
- private static final Constructor EVALUATOR_CONSTRUCTOR;
-
+ public static XPathEvaluatorFactory XPATH_EVALUATOR_FACTORY = null;
static {
- String cn = System.getProperty(EVALUATOR_SYSTEM_PROPERTY, DEFAULT_EVALUATOR_CLASS_NAME);
- Constructor m = null;
+ // Install the xalan xpath evaluator if it available.
+ new XalanXPathEvaluator("//root").evaluate("<root></root>");
try {
- try {
- m = getXPathEvaluatorConstructor(cn);
- } catch (Throwable e) {
- LOG.warn("Invalid " + XPathEvaluator.class.getName() + " implementation: " + cn + ", reason: " + e, e);
- cn = DEFAULT_EVALUATOR_CLASS_NAME;
- try {
- m = getXPathEvaluatorConstructor(cn);
- } catch (Throwable e2) {
- LOG.error("Default XPath evaluator could not be loaded", e);
+ XPATH_EVALUATOR_FACTORY = new XPathExpression.XPathEvaluatorFactory() {
+ public XPathExpression.XPathEvaluator create(String xpath) {
+ return new XalanXPathEvaluator(xpath);
}
- }
- } finally {
- EVALUATOR_CONSTRUCTOR = m;
+ };
+ } catch(Throwable e) {
}
}
private final String xpath;
private final XPathEvaluator evaluator;
+ public static interface XPathEvaluatorFactory {
+ XPathEvaluator create(String xpath);
+ }
+
public static interface XPathEvaluator {
boolean evaluate(Filterable message) throws FilterException;
}
XPathExpression(String xpath) {
- this.xpath = xpath;
- this.evaluator = createEvaluator(xpath);
- }
-
- private static Constructor getXPathEvaluatorConstructor(String cn) throws ClassNotFoundException, SecurityException, NoSuchMethodException {
- Class c = XPathExpression.class.getClassLoader().loadClass(cn);
- if (!XPathEvaluator.class.isAssignableFrom(c)) {
- throw new ClassCastException("" + c + " is not an instance of " + XPathEvaluator.class);
- }
- return c.getConstructor(new Class[] {String.class});
- }
-
- private XPathEvaluator createEvaluator(String xpath2) {
- try {
- return (XPathEvaluator)EVALUATOR_CONSTRUCTOR.newInstance(new Object[] {xpath});
- } catch (InvocationTargetException e) {
- Throwable cause = e.getCause();
- if (cause instanceof RuntimeException) {
- throw (RuntimeException)cause;
- }
- throw new RuntimeException("Invalid XPath Expression: " + xpath + " reason: " + e.getMessage(), e);
- } catch (Throwable e) {
- throw new RuntimeException("Invalid XPath Expression: " + xpath + " reason: " + e.getMessage(), e);
+ if( XPATH_EVALUATOR_FACTORY == null ) {
+ throw new IllegalArgumentException("XPATH support not enabled.");
}
+ this.xpath = xpath;
+ this.evaluator = XPATH_EVALUATOR_FACTORY.create(xpath);
}
public Object evaluate(Filterable message) throws FilterException {
Modified: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XalanXPathEvaluator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XalanXPathEvaluator.java?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XalanXPathEvaluator.java (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XalanXPathEvaluator.java Wed Jul 25 21:28:25 2012
@@ -17,19 +17,16 @@
package org.apache.activemq.apollo.filter;
-import java.io.StringReader;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.fusesource.hawtbuf.Buffer;
-import org.fusesource.hawtbuf.BufferInputStream;
import org.apache.xpath.CachedXPathAPI;
import org.apache.xpath.objects.XObject;
import org.w3c.dom.Document;
import org.w3c.dom.traversal.NodeIterator;
import org.xml.sax.InputSource;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.StringReader;
+
public class XalanXPathEvaluator implements XPathExpression.XPathEvaluator {
@@ -44,42 +41,15 @@ public class XalanXPathEvaluator impleme
if (stringBody!=null) {
return evaluate(stringBody);
}
-
- Buffer bufferBody = m.getBodyAs(Buffer.class);
- if (bufferBody!=null) {
- return evaluate(bufferBody);
- }
return false;
}
- private boolean evaluate(Buffer data) {
- try {
-
- InputSource inputSource = new InputSource(new BufferInputStream(data));
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder dbuilder = factory.newDocumentBuilder();
- Document doc = dbuilder.parse(inputSource);
-
- CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
- XObject result = cachedXPathAPI.eval(doc, xpath);
- if (result.bool())
- return true;
- else {
- NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
- return (iterator.nextNode() != null);
- }
-
- } catch (Throwable e) {
- return false;
- }
+ protected boolean evaluate(String text) {
+ return evaluate(new InputSource(new StringReader(text)));
}
- private boolean evaluate(String text) {
+ protected boolean evaluate(InputSource inputSource) {
try {
- InputSource inputSource = new InputSource(new StringReader(text));
-
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder dbuilder = factory.newDocumentBuilder();
@@ -89,7 +59,7 @@ public class XalanXPathEvaluator impleme
//eval() is a better way to determine the boolean value of the exp.
//For compliance with legacy behavior where selecting an empty node returns true,
//selectNodeIterator is attempted in case of a failure.
-
+
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
XObject result = cachedXPathAPI.eval(doc, xpath);
if (result.bool())
@@ -97,8 +67,8 @@ public class XalanXPathEvaluator impleme
else {
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
return (iterator.nextNode() != null);
- }
-
+ }
+
} catch (Throwable e) {
return false;
}
Propchange: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/XalanXPathEvaluator.java
('svn:executable' removed)
Added: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/LRUCache.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/LRUCache.java?rev=1365771&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/LRUCache.java (added)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/LRUCache.java Wed Jul 25 21:28:25 2012
@@ -0,0 +1,91 @@
+/**
+ * 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.apollo.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) {
+ }
+}
Propchange: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/LRUCache.java
------------------------------------------------------------------------------
svn:executable = *
Modified: activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj?rev=1365771&r1=1365770&r2=1365771&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj Wed Jul 25 21:28:25 2012
@@ -53,7 +53,6 @@ import java.io.*;
import java.util.*;
import org.apache.activemq.apollo.filter.*;
-import org.apache.activemq.apollo.util.LRUCache;
/**
* JMS Selector Parser generated by JavaCC