https://issues.apache.org/jira/browse/AMQ-4162 - visibility on destination query string options, destinationView.options - useful for user metadata about the destination

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1406210 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2012-11-06 16:30:31 +00:00
parent 19622d36a6
commit 7410257c2f
3 changed files with 43 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package org.apache.activemq.broker.jmx;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -50,6 +51,7 @@ import org.apache.activemq.command.Message;
import org.apache.activemq.filter.BooleanExpression;
import org.apache.activemq.filter.MessageEvaluationContext;
import org.apache.activemq.selector.SelectorParser;
import org.apache.activemq.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -413,4 +415,15 @@ public class DestinationView implements DestinationViewMBean {
return result;
}
public String getOptions() {
Map<String, String> options = destination.getActiveMQDestination().getOptions();
String optionsString = "";
try {
if (options != null) {
optionsString = URISupport.createQueryString(options);
}
} catch (URISyntaxException ignored) {}
return optionsString;
}
}

View File

@ -359,4 +359,10 @@ public interface DestinationViewMBean {
@MBeanInfo("returns the optional slowConsumer handler MBeans for this destination")
ObjectName getSlowConsumerStrategy() throws IOException, MalformedObjectNameException;
/**
* @return A string of destination options, name value pairs as URL queryString.
*/
@MBeanInfo("returns the destination options, name value pairs as URL queryString")
String getOptions();
}

View File

@ -55,6 +55,7 @@ import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTempQueue;
import org.apache.activemq.util.JMXSupport;
import org.apache.activemq.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -76,6 +77,7 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
protected boolean transacted;
protected int authMode = Session.AUTO_ACKNOWLEDGE;
protected static final int MESSAGE_COUNT = 2*BaseDestination.MAX_PAGE_SIZE;
final static String QUEUE_WITH_OPTIONS = "QueueWithOptions";
/**
* When you run this test case from the command line it will pause before
@ -719,6 +721,9 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
policyMap.setDefaultEntry(defaultEntry);
answer.setDestinationPolicy(policyMap);
// allow options to be visible via jmx
answer.setDestinations(new ActiveMQDestination[]{new ActiveMQQueue(QUEUE_WITH_OPTIONS + "?topQueue=true&hasOptions=2")});
answer.addConnector(bindAddress);
return answer;
}
@ -895,6 +900,25 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
assertTrue("dest has some memory usage", queue.getMemoryPercentUsage() > 0);
}
public void testDestinationOptionsAreVisible() throws Exception {
ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":Type=Queue,Destination=" + QUEUE_WITH_OPTIONS + ",BrokerName=localhost");
QueueViewMBean queue = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true);
assertEquals("name match", QUEUE_WITH_OPTIONS, queue.getName());
String options = queue.getOptions();
LOG.info("Got options: " + options);
Map<String, String> optionsMap = URISupport.parseQuery(options);
assertEquals("got a map", 2, optionsMap.size());
assertTrue("matches our options", optionsMap.containsKey("hasOptions"));
assertTrue("matches our options", optionsMap.containsKey("topQueue"));
assertTrue("matches our options", optionsMap.containsValue("true"));
assertTrue("matches our options", optionsMap.containsValue("2"));
}
public void testSubscriptionViewToConnectionMBean() throws Exception {
connection = connectionFactory.createConnection("admin", "admin");