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