activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r414652 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx: DestinationView.java DestinationViewMBean.java
Date Thu, 15 Jun 2006 18:42:53 GMT
Author: chirino
Date: Thu Jun 15 11:42:52 2006
New Revision: 414652

URL: http://svn.apache.org/viewvc?rev=414652&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQ-754

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java?rev=414652&r1=414651&r2=414652&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
Thu Jun 15 11:42:52 2006
@@ -13,11 +13,13 @@
  */
 package org.apache.activemq.broker.jmx;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 
 import javax.jms.Connection;
+import javax.jms.InvalidSelectorException;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.management.openmbean.CompositeData;
@@ -35,8 +37,11 @@
 import org.apache.activemq.command.ActiveMQMessage;
 import org.apache.activemq.command.ActiveMQTextMessage;
 import org.apache.activemq.command.Message;
+import org.apache.activemq.filter.BooleanExpression;
+import org.apache.activemq.filter.MessageEvaluationContext;
+import org.apache.activemq.selector.SelectorParser;
 
-public class DestinationView {
+public class DestinationView implements DestinationViewMBean {
     protected final Destination destination;
     protected final ManagedRegionBroker broker;
 
@@ -91,27 +96,80 @@
     }
 
     public CompositeData[] browse() throws OpenDataException{
+        try {
+            return browse(null);
+        } catch (InvalidSelectorException e) {
+            // should not happen.
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException{
         Message[] messages=destination.browse();
-        CompositeData c[]=new CompositeData[messages.length];
-        for(int i=0;i<c.length;i++){
+        ArrayList c = new ArrayList();
+                
+        MessageEvaluationContext ctx = new MessageEvaluationContext();
+        ctx.setDestination(destination.getActiveMQDestination());
+        BooleanExpression selectorExpression = selector==null ? null : new SelectorParser().parse(selector);
+        
+        for(int i=0;i<messages.length;i++){
             try{
-                c[i]=OpenTypeSupport.convert(messages[i]);
-            }catch(Throwable e){
+                
+                if( selectorExpression==null ) {
+                    c.add(OpenTypeSupport.convert(messages[i]));
+                } else {
+                    ctx.setMessageReference(messages[i]);
+                    if ( selectorExpression.matches(ctx) ) {
+                        c.add(OpenTypeSupport.convert(messages[i]));
+                    }
+                }
+                
+            } catch(Throwable e) {
                 e.printStackTrace();
             }
         }
-        return c;
+        
+        CompositeData rc[]=new CompositeData[c.size()];
+        c.toArray(rc);
+        return rc;
     }
 
     public TabularData browseAsTable() throws OpenDataException{
+        try {
+            return browseAsTable(null);
+        } catch (InvalidSelectorException e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public TabularData browseAsTable(String selector) throws OpenDataException, InvalidSelectorException{
         OpenTypeFactory factory=OpenTypeSupport.getFactory(ActiveMQMessage.class);
         Message[] messages=destination.browse();
         CompositeType ct=factory.getCompositeType();
         TabularType tt=new TabularType("MessageList","MessageList",ct,new String[] { "JMSMessageID"
});
         TabularDataSupport rc=new TabularDataSupport(tt);
+        
+        
+        MessageEvaluationContext ctx = new MessageEvaluationContext();
+        ctx.setDestination(destination.getActiveMQDestination());
+        BooleanExpression selectorExpression = selector==null ? null : new SelectorParser().parse(selector);
+        
         for(int i=0;i<messages.length;i++){
-            rc.put(new CompositeDataSupport(ct,factory.getFields(messages[i])));
+            try {
+                if( selectorExpression==null ) {
+                    rc.put(new CompositeDataSupport(ct,factory.getFields(messages[i])));
+                } else {
+                    ctx.setMessageReference(messages[i]);
+                    if ( selectorExpression.matches(ctx) ) {
+                        rc.put(new CompositeDataSupport(ct,factory.getFields(messages[i])));
+                    }
+                }
+                rc.put(new CompositeDataSupport(ct,factory.getFields(messages[i])));
+            } catch(Throwable e) {
+                e.printStackTrace();
+            }
         }
+        
         return rc;
     }
     

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java?rev=414652&r1=414651&r2=414652&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
Thu Jun 15 11:42:52 2006
@@ -18,6 +18,7 @@
 
 import java.util.Map;
 
+import javax.jms.InvalidSelectorException;
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.OpenDataException;
 import javax.management.openmbean.TabularData;
@@ -64,6 +65,18 @@
      * @return A list of all the messages in the destination's queue.
      */
     public TabularData browseAsTable() throws OpenDataException;
+
+    /**
+     * @return An array of all the messages in the destination's queue.
+     * @throws InvalidSelectorException 
+     */
+    public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException;
+    
+    /**
+     * @return A list of all the messages in the destination's queue.
+     * @throws InvalidSelectorException 
+     */
+    public TabularData browseAsTable(String selector) throws OpenDataException, InvalidSelectorException;
 
     /**
      * Sends a TextMesage to the destination.



Mime
View raw message