Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ public static String getDefaultHapolicyBackupStrategy() {
// true means that the management API is available via JMX
private static boolean DEFAULT_JMX_MANAGEMENT_ENABLED = true;

// true means that management notifications are reproduced as JMX notifications
private static boolean DEFAULT_JMX_NOTIFICATION_ENABLED = true;

// the JMX domain used to registered Apache Artemis MBeans in the MBeanServer
private static String DEFAULT_JMX_DOMAIN = "org.apache.activemq.artemis";

Expand Down Expand Up @@ -900,6 +903,13 @@ public static boolean isDefaultJmxManagementEnabled() {
return DEFAULT_JMX_MANAGEMENT_ENABLED;
}

/**
* {@code true} means that management notifications are reproduced as JMX notifications
*/
public static boolean isDefaultJmxNotificationEnabled() {
return DEFAULT_JMX_NOTIFICATION_ENABLED;
}

/**
* the JMX domain used to registered Apache Artemis MBeans in the MBeanServer
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ public interface Configuration {
*/
Configuration setJMXManagementEnabled(boolean enabled);

/**
* {@return whether management notifications are reproduced as JMX notifications; default is {@link
* ActiveMQDefaultConfiguration#DEFAULT_JMX_NOTIFICATION_ENABLED}}
*/
boolean isJMXNotificationEnabled();

/**
* Sets whether management notifications are reproduced as JMX notifications; default is
* {@link ActiveMQDefaultConfiguration#DEFAULT_JMX_NOTIFICATION_ENABLED}}
*/
Configuration setJMXNotificationEnabled(boolean enabled);

/**
* {@return the domain used by JMX MBeans (provided JMX management is enabled); default is {@link
* ActiveMQDefaultConfiguration#DEFAULT_JMX_DOMAIN}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public class ConfigurationImpl extends javax.security.auth.login.Configuration i

protected boolean jmxManagementEnabled = ActiveMQDefaultConfiguration.isDefaultJmxManagementEnabled();

protected boolean jmxNotificationEnabled = ActiveMQDefaultConfiguration.isDefaultJmxNotificationEnabled();

protected String jmxDomain = ActiveMQDefaultConfiguration.getDefaultJmxDomain();

protected boolean jmxUseBrokerName = ActiveMQDefaultConfiguration.isDefaultJMXUseBrokerName();
Expand Down Expand Up @@ -2173,6 +2175,17 @@ public ConfigurationImpl setJMXManagementEnabled(final boolean enabled) {
return this;
}

@Override
public boolean isJMXNotificationEnabled() {
return jmxNotificationEnabled;
}

@Override
public ConfigurationImpl setJMXNotificationEnabled(final boolean enabled) {
jmxNotificationEnabled = enabled;
return this;
}

@Override
public String getJMXDomain() {
return jmxDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ public void parseMainConfig(final Element e, final Configuration config) throws

config.setJMXManagementEnabled(getBoolean(e, "jmx-management-enabled", config.isJMXManagementEnabled()));

config.setJMXNotificationEnabled(getBoolean(e, "jmx-notification-enabled", config.isJMXNotificationEnabled()));

config.setJMXDomain(getString(e, "jmx-domain", config.getJMXDomain(), NOT_NULL_OR_EMPTY));

config.setJMXUseBrokerName(getBoolean(e, "jmx-use-broker-name", config.isJMXUseBrokerName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4226,6 +4226,9 @@ public String listNetworkTopology() throws Exception {
public void removeNotificationListener(final NotificationListener listener,
final NotificationFilter filter,
final Object handback) throws ListenerNotFoundException {
if (broadcaster == null) {
return;
}
if (AuditLogger.isBaseLoggingEnabled()) {
AuditLogger.removeNotificationListener(this.server, listener, filter, handback);
}
Expand All @@ -4239,6 +4242,9 @@ public void removeNotificationListener(final NotificationListener listener,

@Override
public void removeNotificationListener(final NotificationListener listener) throws ListenerNotFoundException {
if (broadcaster == null) {
return;
}
if (AuditLogger.isBaseLoggingEnabled()) {
AuditLogger.removeNotificationListener(this.server, listener);
}
Expand All @@ -4254,6 +4260,9 @@ public void removeNotificationListener(final NotificationListener listener) thro
public void addNotificationListener(final NotificationListener listener,
final NotificationFilter filter,
final Object handback) throws IllegalArgumentException {
if (broadcaster == null) {
return;
}
if (AuditLogger.isBaseLoggingEnabled()) {
AuditLogger.addNotificationListener(this.server, listener, filter, handback);
}
Expand Down Expand Up @@ -4438,6 +4447,9 @@ private void checkStarted() {

@Override
public void onNotification(org.apache.activemq.artemis.core.server.management.Notification notification) {
if (broadcaster == null) {
return;
}
if (!(notification.getType() instanceof CoreNotificationType type))
return;
if (type == CoreNotificationType.SESSION_CREATED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public ManagementServiceImpl(final MBeanServer mbeanServer, final Configuration
messageCounterEnabled = configuration.isMessageCounterEnabled();
managementAddress = configuration.getManagementAddress();
managementNotificationAddress = configuration.getManagementNotificationAddress();
broadcaster = new NotificationBroadcasterSupport();
broadcaster = configuration.isJMXNotificationEnabled() ? new NotificationBroadcasterSupport() : null;
notificationsEnabled = true;
objectNameBuilder = ObjectNameBuilder.create(configuration.getJMXDomain(), configuration.getName(), configuration.isJMXUseBrokerName());
managementMessageRbacResourceNamePrefix = configuration.isManagementMessageRbac() ? SimpleString.of(configuration.getManagementRbacPrefix()).concat('.') : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@
</xsd:annotation>
</xsd:element>

<xsd:element name="jmx-notification-enabled" type="xsd:boolean" default="true" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
whether management notifications are reproduced as JMX notifications
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="jmx-domain" type="xsd:string" default="org.apache.activemq" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,31 @@ public void testDeprecatedConfigsAreNotExportedAsProperties() throws Exception {
assertTrue(properties.containsKey("addressConfigurations.test.queueConfigs.test.name"));
}

@Test
public void testParseJMXEnabledOnProperties() throws Exception {
Properties properties = new Properties();

properties.put("JMXNotificationEnabled", "false");
ConfigurationImpl configuration = new ConfigurationImpl();
configuration.parsePrefixedProperties(properties, null);

assertFalse(configuration.isJMXNotificationEnabled());

File outputProperty = new File(getTestDirfile(), "broker.properties");
configuration.exportAsProperties(outputProperty);

Properties brokerProperties = new Properties();

try (FileInputStream is = new FileInputStream(outputProperty)) {
BufferedInputStream bis = new BufferedInputStream(is);
brokerProperties.load(bis);
}

assertEquals("false", brokerProperties.get("JMXNotificationEnabled"));
}



/**
* Verifies the lock coordinator configuration parsing and export process:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public void testDefaults() {

assertEquals(ActiveMQDefaultConfiguration.isDefaultJmxManagementEnabled(), conf.isJMXManagementEnabled());

assertEquals(ActiveMQDefaultConfiguration.isDefaultJmxNotificationEnabled(), conf.isJMXNotificationEnabled());

assertEquals(ActiveMQDefaultConfiguration.getDefaultJmxDomain(), conf.getJMXDomain());

assertEquals(0, conf.getIncomingInterceptorClassNames().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private void validateFullConfig(Configuration configInstance, boolean fromProper
assertEquals("Frog", configInstance.getClusterUser());
assertEquals("Wombat", configInstance.getClusterPassword());
assertFalse(configInstance.isJMXManagementEnabled());
assertFalse(configInstance.isJMXNotificationEnabled());
assertEquals("gro.qtenroh", configInstance.getJMXDomain());
assertTrue(configInstance.isMessageCounterEnabled());
assertEquals(5, configInstance.getMessageCounterMaxDayHistory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.activemq.artemis.core.server.management.impl;

import java.lang.reflect.Field;
import javax.management.MBeanServer;

import org.apache.activemq.artemis.api.core.RoutingType;
Expand All @@ -40,6 +41,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

public class ManagementServiceImplTest {

MBeanServer mBeanServer = Mockito.mock(MBeanServer.class);
Expand Down Expand Up @@ -190,6 +194,22 @@ public void testInvokeSecurityCheck() throws Exception {

}

@Test
public void testBroadcasterNullWhenJMXNotificationDisabled() throws Exception {
Field broadcasterField = ManagementServiceImpl.class.getDeclaredField("broadcaster");
broadcasterField.setAccessible(true);

FileConfiguration enabledConfig = new FileConfiguration();
enabledConfig.setJMXNotificationEnabled(true);
ManagementServiceImpl enabledService = new ManagementServiceImpl(mBeanServer, enabledConfig);
assertNotNull(broadcasterField.get(enabledService));

FileConfiguration disabledConfig = new FileConfiguration();
disabledConfig.setJMXNotificationEnabled(false);
ManagementServiceImpl disabledService = new ManagementServiceImpl(mBeanServer, disabledConfig);
assertNull(broadcasterField.get(disabledService));
}

@Test
public void testGetAttributeNoSecurityCheck() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<mask-password>true</mask-password>
<log-delegate-factory-class-name>com.foo</log-delegate-factory-class-name>
<jmx-management-enabled>false</jmx-management-enabled>
<jmx-notification-enabled>false</jmx-notification-enabled>
<jmx-domain>gro.qtenroh</jmx-domain>
<message-counter-enabled>true</message-counter-enabled>
<message-counter-sample-period>123456</message-counter-sample-period>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<mask-password>true</mask-password>
<log-delegate-factory-class-name>com.foo</log-delegate-factory-class-name>
<jmx-management-enabled>false</jmx-management-enabled>
<jmx-notification-enabled>false</jmx-notification-enabled>
<jmx-domain>gro.qtenroh</jmx-domain>
<message-counter-enabled>true</message-counter-enabled>
<message-counter-sample-period>123456</message-counter-sample-period>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<mask-password>true</mask-password>
<log-delegate-factory-class-name>com.foo</log-delegate-factory-class-name>
<jmx-management-enabled>false</jmx-management-enabled>
<jmx-notification-enabled>false</jmx-notification-enabled>
<jmx-domain>gro.qtenroh</jmx-domain>
<message-counter-enabled>true</message-counter-enabled>
<message-counter-sample-period>123456</message-counter-sample-period>
Expand Down