mirror of https://github.com/apache/activemq.git
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:
parent
b662f6065c
commit
9b07e4323a
|
@ -16,6 +16,7 @@ package org.apache.activemq.broker.jmx;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
|
@ -107,7 +108,7 @@ public class DestinationView implements DestinationViewMBean {
|
||||||
public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException{
|
public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException{
|
||||||
Message[] messages=destination.browse();
|
Message[] messages=destination.browse();
|
||||||
ArrayList c = new ArrayList();
|
ArrayList c = new ArrayList();
|
||||||
|
|
||||||
MessageEvaluationContext ctx = new MessageEvaluationContext();
|
MessageEvaluationContext ctx = new MessageEvaluationContext();
|
||||||
ctx.setDestination(destination.getActiveMQDestination());
|
ctx.setDestination(destination.getActiveMQDestination());
|
||||||
BooleanExpression selectorExpression = selector==null ? null : new SelectorParser().parse(selector);
|
BooleanExpression selectorExpression = selector==null ? null : new SelectorParser().parse(selector);
|
||||||
|
@ -133,6 +134,45 @@ public class DestinationView implements DestinationViewMBean {
|
||||||
c.toArray(rc);
|
c.toArray(rc);
|
||||||
return 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{
|
public TabularData browseAsTable() throws OpenDataException{
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,13 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.jmx;
|
package org.apache.activemq.broker.jmx;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.jms.InvalidSelectorException;
|
import javax.jms.InvalidSelectorException;
|
||||||
import javax.management.openmbean.CompositeData;
|
import javax.management.openmbean.CompositeData;
|
||||||
import javax.management.openmbean.OpenDataException;
|
import javax.management.openmbean.OpenDataException;
|
||||||
import javax.management.openmbean.TabularData;
|
import javax.management.openmbean.TabularData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public interface DestinationViewMBean {
|
public interface DestinationViewMBean {
|
||||||
|
|
||||||
|
@ -99,4 +100,14 @@ public interface DestinationViewMBean {
|
||||||
public long getMemoryLimit();
|
public long getMemoryLimit();
|
||||||
public void setMemoryLimit(long limit);
|
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;
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue