From aaa81deb4061c84fcd2fb2184cb23833b7b4cf40 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Thu, 10 Jan 2013 14:04:40 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3438 - keep both mbean names, by remoteaddress and by clientid - as navigation between subs and connections uses the clientid but remote connection info based on address has real value to opts. https://issues.apache.org/jira/browse/AMQ-4237 - partition both address types using connectionViewType=remoteAddress|clientId and add clientId to connetionView - now easier to see connections under a clientConnector git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1431369 13f79535-47bb-0310-9956-ffa450edef68 --- .../broker/jmx/BrokerMBeanSuppurt.java | 16 ++++--------- .../activemq/broker/jmx/ConnectionView.java | 5 ++++ .../broker/jmx/ConnectionViewMBean.java | 10 +++++++- .../jmx/ManagedTransportConnection.java | 23 ++++++------------- .../apache/activemq/broker/jmx/MBeanTest.java | 8 +++++-- .../jmx/TransportConnectorMBeanTest.java | 2 +- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerMBeanSuppurt.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerMBeanSuppurt.java index f484e8f089..585d2d7d10 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerMBeanSuppurt.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerMBeanSuppurt.java @@ -151,16 +151,10 @@ public class BrokerMBeanSuppurt { return objectName; } - public static ObjectName createConnectionViewByAddressName(ObjectName connectorName, String type, String address) throws MalformedObjectNameException { + public static ObjectName createConnectionViewByType(ObjectName connectorName, String type, String name) throws MalformedObjectNameException { String objectNameStr = connectorName.toString(); objectNameStr += ",connectionViewType=" + JMXSupport.encodeObjectNamePart(type); - objectNameStr += ",connectionName="+ JMXSupport.encodeObjectNamePart(address); - return new ObjectName(objectNameStr); - } - - public static ObjectName createConnectionViewByClientIdName(ObjectName connectorName, String clientId) throws MalformedObjectNameException { - String objectNameStr = connectorName.toString(); - objectNameStr += ",connectionName="+JMXSupport.encodeObjectNamePart(clientId); + objectNameStr += ",connectionName="+ JMXSupport.encodeObjectNamePart(name); return new ObjectName(objectNameStr); } @@ -216,11 +210,11 @@ public class BrokerMBeanSuppurt { // MBean Query Creation - public static ObjectName createConnectionQuery(String jmxDomainName, String brokerName, String clientId) throws MalformedObjectNameException { + public static ObjectName createConnectionQuery(String jmxDomainName, String brokerName, String name) throws MalformedObjectNameException { return new ObjectName(jmxDomainName + ":type=Broker,brokerName=" + JMXSupport.encodeObjectNamePart(brokerName) + "," - + "connector=*," + "connectorName=*," - + "connectionName=" + JMXSupport.encodeObjectNamePart(clientId)); + + "connector=*," + "connectorName=*," + "connectionViewType=*," + + "connectionName=" + JMXSupport.encodeObjectNamePart(name)); } public static ObjectName createConsumerQueury(String jmxDomainName, String clientId) throws MalformedObjectNameException { diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionView.java index c1161c5a6d..49351fe5f9 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionView.java @@ -99,6 +99,11 @@ public class ConnectionView implements ConnectionViewMBean { return connection.getRemoteAddress(); } + @Override + public String getClientId() { + return connection.getConnectionId(); + } + public String getConnectionId() { return connection.getConnectionId(); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionViewMBean.java index 54c9215fd5..a435428918 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectionViewMBean.java @@ -56,9 +56,17 @@ public interface ConnectionViewMBean extends Service { * * @return the source address for this connection */ - @MBeanInfo("Source address for this connection") + @MBeanInfo("source address for this connection") String getRemoteAddress(); + /** + * Returns the client identifier for this connection + * + * @return the the client identifier for this connection + */ + @MBeanInfo("client id for this connection") + String getClientId(); + /** * Returns the number of messages to be dispatched to this connection * @return the number of messages pending dispatch diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java index 4cec026ec3..62fb5921da 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java @@ -56,7 +56,7 @@ public class ManagedTransportConnection extends TransportConnection { this.mbean = new ConnectionView(this, managementContext); this.populateUserName = broker.getBrokerService().isPopulateUserNameInMBeans(); if (managementContext.isAllowRemoteAddressInMBeanNames()) { - byAddressName = createByAddressObjectName("address", transport.getRemoteAddress()); + byAddressName = createObjectName("remoteAddress", transport.getRemoteAddress()); registerMBean(byAddressName); } } @@ -81,12 +81,10 @@ public class ManagedTransportConnection extends TransportConnection { if (populateUserName) { ((ConnectionView) mbean).setUserName(info.getUserName()); } - if (!managementContext.isAllowRemoteAddressInMBeanNames()) { - if (clientId != null) { - if (byClientIdName == null) { - byClientIdName = createByClientIdObjectName(clientId); - registerMBean(byClientIdName); - } + if (clientId != null) { + if (byClientIdName == null) { + byClientIdName = createObjectName("clientId", clientId); + registerMBean(byClientIdName); } } return answer; @@ -116,19 +114,12 @@ public class ManagedTransportConnection extends TransportConnection { } } - protected ObjectName createByAddressObjectName(String type, String value) throws IOException { + protected ObjectName createObjectName(String type, String value) throws IOException { try { - return BrokerMBeanSuppurt.createConnectionViewByAddressName(connectorName, type, value); + return BrokerMBeanSuppurt.createConnectionViewByType(connectorName, type, value); } catch (Throwable e) { throw IOExceptionSupport.create(e); } } - protected ObjectName createByClientIdObjectName(String value) throws IOException { - try { - return BrokerMBeanSuppurt.createConnectionViewByClientIdName(connectorName, value); - } catch (Throwable e) { - throw IOExceptionSupport.create(e); - } - } } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java index 283287903d..5ccb51bf37 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java @@ -678,7 +678,8 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { bindAddress = "tcp://localhost:0"; useTopic = false; super.setUp(); - mbeanServer = broker.getManagementContext().getMBeanServer(); + ManagementContext managementContext = broker.getManagementContext(); + mbeanServer = managementContext.getMBeanServer(); } protected void tearDown() throws Exception { @@ -953,6 +954,8 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { // Our consumer plus one advisory consumer. assertEquals(2, connectionView.getConsumers().length); + assertEquals("client id match", "MBeanTest", connectionView.getClientId()); + // Check that the subscription view we found earlier is in this list. boolean found = false; for (ObjectName name : connectionView.getConsumers()) { @@ -1077,7 +1080,8 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertNull(subscriberView.getUserName()); } } - ObjectName query = new ObjectName(domain + ":type=Broker,brokerName=localhost,connector=*," + "connectorName=*,connectionName=MBeanTest"); + ObjectName query = //new ObjectName(domain + ":type=Broker,brokerName=localhost,connector=*," + "connectorName=*,connectionName=MBeanTest"); + BrokerMBeanSuppurt.createConnectionQuery(domain, "localhost", connection.getClientID()); Set names = mbeanServer.queryNames(query, null); boolean found = false; diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java index fd3b0b993d..72a422d2ba 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java @@ -50,7 +50,7 @@ public class TransportConnectorMBeanTest { createBroker(allowRemoteAddress); ActiveMQConnection connection = createConnection(); Set registeredMbeans = getRegisteredMbeans(); - assertEquals("presence of mbean with clientId", !allowRemoteAddress, match(connection.getClientID(), registeredMbeans)); + assertEquals("presence of mbean with clientId", true, match(connection.getClientID(), registeredMbeans)); assertEquals("presence of mbean with local port", allowRemoteAddress, match(extractLocalPort(connection), registeredMbeans)); }