You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2011/08/05 13:24:45 UTC
svn commit: r1154162 - in /activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/broker/jmx/
test/java/org/apache/activemq/broker/jmx/
Author: gtully
Date: Fri Aug 5 11:24:45 2011
New Revision: 1154162
URL: http://svn.apache.org/viewvc?rev=1154162&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3438: Make use of remote port in Connection MBeanNames optional, useful when ephemeral range cycles quickly. added boolean attribute org.apache.activemq.broker.jmx.ManagementContext#allowRemoteAddressInMBeanNames, accessible via xml. when false, a transport connector will only be registered by its clientId (whic defaults to connectionid)
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java (with props)
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java?rev=1154162&r1=1154161&r2=1154162&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagedTransportConnection.java Fri Aug 5 11:24:45 2011
@@ -53,8 +53,10 @@ public class ManagedTransportConnection
this.managementContext = context;
this.connectorName = connectorName;
this.mbean = new ConnectionView(this);
- byAddressName = createByAddressObjectName("address", transport.getRemoteAddress());
- registerMBean(byAddressName);
+ if (managementContext.isAllowRemoteAddressInMBeanNames()) {
+ byAddressName = createByAddressObjectName("address", transport.getRemoteAddress());
+ registerMBean(byAddressName);
+ }
}
public void doStop() throws Exception {
@@ -71,14 +73,6 @@ public class ManagedTransportConnection
super.doStop();
}
- /**
- * Sets the connection ID of this connection. On startup this connection ID
- * is set to an incrementing counter; once the client registers it is set to
- * the clientID of the JMS client.
- */
- public void setConnectionId(String connectionId) throws IOException {
- }
-
public Response processAddConnection(ConnectionInfo info) throws Exception {
Response answer = super.processAddConnection(info);
String clientId = info.getClientId();
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java?rev=1154162&r1=1154161&r2=1154162&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java Fri Aug 5 11:24:45 2011
@@ -65,6 +65,7 @@ public class ManagementContext implement
private ObjectName namingServiceObjectName;
private Registry registry;
private final List<ObjectName> registeredMBeanNames = new CopyOnWriteArrayList<ObjectName>();
+ private boolean allowRemoteAddressInMBeanNames = true;
public ManagementContext() {
this(null);
@@ -301,7 +302,7 @@ public class ManagementContext implement
return result;
}
- public Set queryNames(ObjectName name, QueryExp query) throws Exception{
+ public Set<ObjectName> queryNames(ObjectName name, QueryExp query) throws Exception{
return getMBeanServer().queryNames(name, query);
}
@@ -513,4 +514,12 @@ public class ManagementContext implement
public void setEnvironment(Map environment) {
this.environment = environment;
}
+
+ public boolean isAllowRemoteAddressInMBeanNames() {
+ return allowRemoteAddressInMBeanNames;
+ }
+
+ public void setAllowRemoteAddressInMBeanNames(boolean allowRemoteAddressInMBeanNames) {
+ this.allowRemoteAddressInMBeanNames = allowRemoteAddressInMBeanNames;
+ }
}
Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java?rev=1154162&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java Fri Aug 5 11:24:45 2011
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.broker.jmx;
+
+import java.net.Socket;
+import java.util.Set;
+import javax.management.ObjectName;
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.util.JMXSupport;
+import org.junit.After;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class TransportConnectorMBeanTest {
+ private static final Logger LOG = LoggerFactory.getLogger(TransportConnectorMBeanTest.class);
+
+ BrokerService broker;
+
+ @Test
+ public void verifyRemoteAddressInMbeanName() throws Exception {
+ doVerifyRemoteAddressInMbeanName(true);
+ }
+
+ @Test
+ public void verifyRemoteAddressNotInMbeanName() throws Exception {
+ doVerifyRemoteAddressInMbeanName(false);
+ }
+
+ private void doVerifyRemoteAddressInMbeanName(boolean allowRemoteAddress) throws Exception {
+ createBroker(allowRemoteAddress);
+ ActiveMQConnection connection = createConnection();
+ Set<ObjectName> registeredMbeans = getRegisteredMbeans();
+ assertTrue("found mbean with clientId", match(connection.getClientID(), registeredMbeans));
+ assertEquals("presence of mbean with local port", allowRemoteAddress, match(extractLocalPort(connection), registeredMbeans));
+ }
+
+ @After
+ public void stopBroker() throws Exception {
+ if (broker != null) {
+ broker.stop();
+ }
+ }
+
+ private boolean match(String s, Set<ObjectName> registeredMbeans) {
+ String encodedName = JMXSupport.encodeObjectNamePart(s);
+ for (ObjectName name : registeredMbeans) {
+ LOG.info("checking for match:" + encodedName + ", with: " + name.toString());
+ if (name.toString().contains(encodedName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private String extractLocalPort(ActiveMQConnection connection) throws Exception {
+ Socket socket = (Socket) connection.getTransport().narrow(Socket.class);
+ return String.valueOf(socket.getLocalPort());
+ }
+
+ private Set<ObjectName> getRegisteredMbeans() throws Exception {
+ return broker.getManagementContext().queryNames(null, null);
+ }
+
+ private ActiveMQConnection createConnection() throws Exception {
+ ActiveMQConnection connection = (ActiveMQConnection)
+ new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri()).createConnection();
+ connection.start();
+ return connection;
+ }
+
+ private void createBroker(boolean allowRemoteAddressInMbeanNames) throws Exception {
+ broker = new BrokerService();
+ broker.setPersistent(false);
+ broker.addConnector("tcp://localhost:0");
+ broker.getManagementContext().setAllowRemoteAddressInMBeanNames(allowRemoteAddressInMbeanNames);
+ broker.start();
+ }
+
+}
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date