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
This commit is contained in:
Gary Tully 2013-01-10 14:04:40 +00:00
parent 99682093d9
commit aaa81deb40
6 changed files with 33 additions and 31 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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<ObjectName> names = mbeanServer.queryNames(query, null);
boolean found = false;

View File

@ -50,7 +50,7 @@ public class TransportConnectorMBeanTest {
createBroker(allowRemoteAddress);
ActiveMQConnection connection = createConnection();
Set<ObjectName> 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));
}