activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r740375 - in /activemq/trunk: activemq-core/src/main/grammar/ activemq-core/src/main/java/org/apache/activemq/ activemq-core/src/main/java/org/apache/activemq/broker/ activemq-core/src/main/java/org/apache/activemq/broker/jmx/ activemq-core...
Date Tue, 03 Feb 2009 19:05:09 GMT
Author: gnodet
Date: Tue Feb  3 19:05:07 2009
New Revision: 740375

URL: http://svn.apache.org/viewvc?rev=740375&view=rev
Log:
AMQ-2091: Add a cache to the jms selector parser for speed improvements

Modified:
    activemq/trunk/activemq-core/src/main/grammar/SelectorParser.jj
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQInputStream.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/FilteredDestination.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorTest.java
    activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQActivationSpec.java

Modified: activemq/trunk/activemq-core/src/main/grammar/SelectorParser.jj
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/grammar/SelectorParser.jj?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/grammar/SelectorParser.jj (original)
+++ activemq/trunk/activemq-core/src/main/grammar/SelectorParser.jj Tue Feb  3 19:05:07 2009
@@ -57,6 +57,7 @@
 import javax.jms.InvalidSelectorException;
 
 import org.apache.activemq.filter.*;
+import org.apache.activemq.util.LRUCache;
 
 /** 
  * JMS Selector Parser generated by JavaCC
@@ -65,22 +66,46 @@
  */
 public class SelectorParser {
 
-    public SelectorParser() {
-        this(new StringReader(""));
+    private static final LRUCache cache = new LRUCache(100);
+
+    public static BooleanExpression parse(String sql) throws InvalidSelectorException {
+        Object result = cache.get(sql);
+        if (result instanceof InvalidSelectorException) {
+            throw (InvalidSelectorException) result;
+        } else if (result instanceof BooleanExpression) {
+            return (BooleanExpression) result;
+        } else {
+            try {
+                BooleanExpression e = new SelectorParser(sql).parse();
+                cache.put(sql, e);
+                return e;
+            } catch (InvalidSelectorException t) {
+                cache.put(sql, t);
+                throw t;
+            }
+        }
     }
 
-    public BooleanExpression parse(String sql) throws InvalidSelectorException {
-        this.ReInit(new StringReader(sql));
+    public static void clearCache() {
+        cache.clear();
+    }
+
+    private String sql;
 
+    protected SelectorParser(String sql) {
+        this(new StringReader(sql));
+        this.sql = sql;
+    }
+
+    protected BooleanExpression parse() throws InvalidSelectorException {
         try {
             return this.JmsSelector();
-        } 
+        }
         catch (Throwable e) {
-	        throw (InvalidSelectorException)new InvalidSelectorException(sql).initCause(e);
+            throw (InvalidSelectorException) new InvalidSelectorException(sql).initCause(e);
         }
-        
     }
-    
+
     private BooleanExpression asBooleanExpression(Expression value) throws ParseException
 {
         if (value instanceof BooleanExpression) {
             return (BooleanExpression) value;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQInputStream.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQInputStream.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQInputStream.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQInputStream.java
Tue Feb  3 19:05:07 2009
@@ -91,7 +91,7 @@
             selector = "JMSType='org.apache.activemq.Stream'";
         }
 
-        new SelectorParser().parse(selector);
+        SelectorParser.parse(selector);
         this.info.setSelector(selector);
 
         this.info.setPrefetchSize(prefetch);

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
Tue Feb  3 19:05:07 2009
@@ -200,12 +200,12 @@
         this.info.setBrowser(browser);
         if (selector != null && selector.trim().length() != 0) {
             // Validate the selector
-            new SelectorParser().parse(selector);
+            SelectorParser.parse(selector);
             this.info.setSelector(selector);
             this.selector = selector;
         } else if (info.getSelector() != null) {
             // Validate the selector
-            new SelectorParser().parse(this.info.getSelector());
+            SelectorParser.parse(this.info.getSelector());
             this.selector = this.info.getSelector();
         } else {
             this.selector = null;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Tue Feb  3 19:05:07 2009
@@ -35,6 +35,7 @@
 import javax.management.ObjectName;
 import org.apache.activemq.ActiveMQConnectionMetaData;
 import org.apache.activemq.Service;
+import org.apache.activemq.selector.SelectorParser;
 import org.apache.activemq.advisory.AdvisoryBroker;
 import org.apache.activemq.broker.cluster.ConnectionSplitBroker;
 import org.apache.activemq.broker.ft.MasterConnector;
@@ -530,6 +531,8 @@
             }
             stopper.stop(getManagementContext());
         }
+        // Clear SelectorParser cache to free memory
+        SelectorParser.clearCache();
         stopped.set(true);
         stoppedLatch.countDown();
         LOG.info("ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId + ")
stopped");

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
Tue Feb  3 19:05:07 2009
@@ -141,7 +141,7 @@
 
         MessageEvaluationContext ctx = new MessageEvaluationContext();
         ctx.setDestination(destination.getActiveMQDestination());
-        BooleanExpression selectorExpression = selector == null ? null : new SelectorParser().parse(selector);
+        BooleanExpression selectorExpression = selector == null ? null : SelectorParser.parse(selector);
 
         for (int i = 0; i < messages.length; i++) {
             try {
@@ -186,7 +186,7 @@
 
         MessageEvaluationContext ctx = new MessageEvaluationContext();
         ctx.setDestination(destination.getActiveMQDestination());
-        BooleanExpression selectorExpression = selector == null ? null : new SelectorParser().parse(selector);
+        BooleanExpression selectorExpression = selector == null ? null : SelectorParser.parse(selector);
 
         for (int i = 0; i < messages.length; i++) {
             try {
@@ -224,7 +224,7 @@
 
         MessageEvaluationContext ctx = new MessageEvaluationContext();
         ctx.setDestination(destination.getActiveMQDestination());
-        BooleanExpression selectorExpression = selector == null ? null : new SelectorParser().parse(selector);
+        BooleanExpression selectorExpression = selector == null ? null : SelectorParser.parse(selector);
 
         for (int i = 0; i < messages.length; i++) {
             try {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
Tue Feb  3 19:05:07 2009
@@ -60,7 +60,7 @@
     private static BooleanExpression parseSelector(ConsumerInfo info) throws InvalidSelectorException
{
         BooleanExpression rc = null;
         if (info.getSelector() != null) {
-            rc = new SelectorParser().parse(info.getSelector());
+            rc = SelectorParser.parse(info.getSelector());
         }
         if (info.isNoLocal()) {
             if (rc == null) {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
Tue Feb  3 19:05:07 2009
@@ -1105,7 +1105,7 @@
     }
 
     protected MessageReferenceFilter createSelectorFilter(String selector) throws InvalidSelectorException
{
-        final BooleanExpression selectorExpression = new SelectorParser().parse(selector);
+        final BooleanExpression selectorExpression = SelectorParser.parse(selector);
 
         return new MessageReferenceFilter() {
             public boolean evaluate(ConnectionContext context, MessageReference r) throws
JMSException {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/FilteredDestination.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/FilteredDestination.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/FilteredDestination.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/FilteredDestination.java
Tue Feb  3 19:05:07 2009
@@ -66,7 +66,7 @@
      */
     public void setSelector(String selector) throws InvalidSelectorException {
         this.selector = selector;
-        setFilter(new SelectorParser().parse(selector));
+        setFilter(SelectorParser.parse(selector));
     }
 
     public BooleanExpression getFilter() {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorParserTest.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
Tue Feb  3 19:05:07 2009
@@ -68,6 +68,6 @@
     }
 
     protected BooleanExpression parse(String text) throws Exception {
-        return new SelectorParser().parse(text);
+        return SelectorParser.parse(text);
     }
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorTest.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/SelectorTest.java
Tue Feb  3 19:05:07 2009
@@ -352,14 +352,14 @@
 
     protected void assertInvalidSelector(Message message, String text) throws JMSException
{
         try {
-            new SelectorParser().parse(text);
+            SelectorParser.parse(text);
             fail("Created a valid selector");
         } catch (InvalidSelectorException e) {
         }
     }
 
     protected void assertSelector(Message message, String text, boolean expected) throws
JMSException {
-        BooleanExpression selector = new SelectorParser().parse(text);
+        BooleanExpression selector = SelectorParser.parse(text);
         assertTrue("Created a valid selector", selector != null);
         MessageEvaluationContext context = new MessageEvaluationContext();
         context.setMessageReference((org.apache.activemq.command.Message)message);

Modified: activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQActivationSpec.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQActivationSpec.java?rev=740375&r1=740374&r2=740375&view=diff
==============================================================================
--- activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQActivationSpec.java
(original)
+++ activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQActivationSpec.java
Tue Feb  3 19:05:07 2009
@@ -165,7 +165,7 @@
     public boolean isValidMessageSelector(List<String> errorMessages) {
         try {
             if (!isEmpty(messageSelector)) {
-                new SelectorParser().parse(messageSelector);
+                SelectorParser.parse(messageSelector);
             }
             return true;
         } catch (Throwable e) {



Mime
View raw message