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
This commit is contained in:
James Strachan 2006-07-10 14:03:24 +00:00
parent b662f6065c
commit 9b07e4323a
2 changed files with 54 additions and 3 deletions

View File

@ -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 {

View File

@ -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;
}