From 9b07e4323a2d37b5f30f592f39b75b1e4fed7473 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Mon, 10 Jul 2006 14:03:24 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@420527 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/broker/jmx/DestinationView.java | 42 ++++++++++++++++++- .../broker/jmx/DestinationViewMBean.java | 15 ++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java index 92bab6707f..b2499c3abc 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java @@ -16,6 +16,7 @@ package org.apache.activemq.broker.jmx; 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 class DestinationView implements DestinationViewMBean { 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); @@ -133,6 +134,45 @@ public class DestinationView implements DestinationViewMBean { 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{ try { diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java index 7b7cb92a0d..14068d7345 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java @@ -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 { @@ -99,4 +100,14 @@ public interface DestinationViewMBean { 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; + } \ No newline at end of file