You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/07/10 16:03:25 UTC

svn commit: r420527 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx: DestinationView.java DestinationViewMBean.java

Author: jstrachan
Date: Mon Jul 10 07:03:24 2006
New Revision: 420527

URL: http://svn.apache.org/viewvc?rev=420527&view=rev
Log:
added a helper method to make it easier to browse messages as JMS Message objects. See: http://www.nabble.com/ActiveMQ-JMX-Questions..-tf1917262.html#a5248649

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=420527&r1=420526&r2=420527&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 Mon Jul 10 07:03:24 2006
@@ -16,6 +16,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.jms.Connection;
@@ -107,7 +108,7 @@
     public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException{
         Message[] messages=destination.browse();
         ArrayList c = new ArrayList();
-                
+        
         MessageEvaluationContext ctx = new MessageEvaluationContext();
         ctx.setDestination(destination.getActiveMQDestination());
         BooleanExpression selectorExpression = selector==null ? null : new SelectorParser().parse(selector);
@@ -132,6 +133,45 @@
         CompositeData rc[]=new CompositeData[c.size()];
         c.toArray(rc);
         return rc;
+    }
+    
+    /**
+     * Browses the current destination returning a list of messages
+     */
+    public List browseMessages() throws InvalidSelectorException {
+        return browseMessages(null);
+    }    
+    
+    /**
+     * Browses the current destination with the given selector returning a list of messages
+     */
+    public List browseMessages(String selector) throws InvalidSelectorException {
+        Message[] messages = destination.browse();
+        ArrayList answer = 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 {
+                Message message = messages[i];
+                if (selectorExpression == null) {
+                    answer.add(OpenTypeSupport.convert(message));
+                }
+                else {
+                    ctx.setMessageReference(message);
+                    if (selectorExpression.matches(ctx)) {
+                        answer.add(message);
+                    }
+                }
+
+            }
+            catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+        return answer;
     }
 
     public TabularData browseAsTable() throws OpenDataException{

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=420527&r1=420526&r2=420527&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 Mon Jul 10 07:03:24 2006
@@ -16,13 +16,14 @@
  */
 package org.apache.activemq.broker.jmx;
 
-import java.util.Map;
-
 import javax.jms.InvalidSelectorException;
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.OpenDataException;
 import javax.management.openmbean.TabularData;
 
+import java.util.List;
+import java.util.Map;
+
 
 public interface DestinationViewMBean {
     
@@ -98,5 +99,15 @@
     public int getMemoryPercentageUsed();
     public long getMemoryLimit();
     public void setMemoryLimit(long limit);
+
+    /**
+     * Browses the current destination returning a list of messages
+     */
+    public List browseMessages() throws InvalidSelectorException;
+
+    /**
+     * Browses the current destination with the given selector returning a list of messages
+     */
+    public List browseMessages(String selector) throws InvalidSelectorException;
 
 }