This commit is contained in:
Howard Gao 2020-10-22 15:11:17 +08:00
commit 94451674fa
2 changed files with 27 additions and 15 deletions

View File

@ -82,7 +82,7 @@ public final class ObjectNameBuilder {
* Returns the ObjectName used by the single {@link ActiveMQServerControl}.
*/
public ObjectName getActiveMQServerObjectName() throws Exception {
return ObjectName.getInstance(domain + ":" + getBrokerProperties());
return ObjectName.getInstance(getActiveMQServerName());
}
/**
@ -91,7 +91,7 @@ public final class ObjectNameBuilder {
* @see AddressControl
*/
public ObjectName getAddressObjectName(final SimpleString address) throws Exception {
return ObjectName.getInstance(String.format("%s:broker=%s,component=addresses,address=%s", domain, ObjectName.quote(brokerName), ObjectName.quote(address.toString())));
return ObjectName.getInstance(String.format("%s,component=addresses,address=%s", getActiveMQServerName(), ObjectName.quote(address.toString())));
}
/**
@ -100,7 +100,7 @@ public final class ObjectNameBuilder {
* @see QueueControl
*/
public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name, RoutingType routingType) throws Exception {
return ObjectName.getInstance(String.format("%s:broker=%s,component=addresses,address=%s,subcomponent=queues,routing-type=%s,queue=%s", domain, ObjectName.quote(brokerName), ObjectName.quote(address.toString()), ObjectName.quote(routingType.toString().toLowerCase()), ObjectName.quote(name.toString())));
return ObjectName.getInstance(String.format("%s,component=addresses,address=%s,subcomponent=queues,routing-type=%s,queue=%s", getActiveMQServerName(), ObjectName.quote(address.toString()), ObjectName.quote(routingType.toString().toLowerCase()), ObjectName.quote(name.toString())));
}
@ -110,7 +110,7 @@ public final class ObjectNameBuilder {
* @see DivertControl
*/
public ObjectName getDivertObjectName(final String name, String address) throws Exception {
return ObjectName.getInstance(String.format("%s:broker=%s,component=addresses,address=%s,subcomponent=diverts,divert=%s", domain, ObjectName.quote(brokerName), ObjectName.quote(address.toString()), ObjectName.quote(name.toString())));
return ObjectName.getInstance(String.format("%s,component=addresses,address=%s,subcomponent=diverts,divert=%s", getActiveMQServerName(), ObjectName.quote(address.toString()), ObjectName.quote(name.toString())));
}
/**
@ -150,15 +150,11 @@ public final class ObjectNameBuilder {
}
private ObjectName createObjectName(final String type, final String name) throws Exception {
return ObjectName.getInstance(String.format("%s:broker=%s,component=%ss,name=%s", domain, ObjectName.quote(brokerName), type, ObjectName.quote(name)));
return ObjectName.getInstance(String.format("%s,component=%ss,name=%s", getActiveMQServerName(), type, ObjectName.quote(name)));
}
private String getBrokerProperties() {
if (jmxUseBrokerName && brokerName != null) {
return String.format("broker=%s", ObjectName.quote(brokerName));
} else {
return "";
}
private String getActiveMQServerName() {
return String.format("%s:broker=%s", domain, (jmxUseBrokerName && brokerName != null) ? ObjectName.quote(brokerName) : "artemis");
}
public ObjectName getManagementContextObjectName() throws Exception {

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.artemis.tests.integration.management;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -28,11 +30,25 @@ import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(value = Parameterized.class)
public class JMXDomainTest extends ManagementTestBase {
ActiveMQServer server_0 = null;
ActiveMQServer server_1 = null;
private ActiveMQServer server_0 = null;
private ActiveMQServer server_1 = null;
private boolean jmxUseBrokerName;
@Parameterized.Parameters(name = "jmxUseBrokerName={0}")
public static Collection<Object[]> getParams() {
return Arrays.asList(new Object[][] {{true}, {false}});
}
public JMXDomainTest(boolean jmxUseBrokerName) {
super();
this.jmxUseBrokerName = jmxUseBrokerName;
}
@Test
public void test2ActiveMQServersManagedFrom1MBeanServer() throws Exception {
@ -42,13 +58,13 @@ public class JMXDomainTest extends ManagementTestBase {
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
Configuration config_1 = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params)).setJMXDomain(jmxDomain_1);
Configuration config_1 = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params)).setJMXDomain(jmxDomain_1).setJMXUseBrokerName(jmxUseBrokerName);
server_0 = addServer(ActiveMQServers.newActiveMQServer(config_0, mbeanServer, false));
server_1 = addServer(ActiveMQServers.newActiveMQServer(config_1, mbeanServer, false));
ObjectNameBuilder builder_0 = ObjectNameBuilder.DEFAULT;
ObjectNameBuilder builder_1 = ObjectNameBuilder.create(jmxDomain_1, "localhost");
ObjectNameBuilder builder_1 = ObjectNameBuilder.create(jmxDomain_1, "localhost", jmxUseBrokerName);
checkNoResource(builder_0.getActiveMQServerObjectName());
checkNoResource(builder_1.getActiveMQServerObjectName());