INT-2541: Fix @ManagedResource JMX registration
JIRA: https://jira.spring.io/browse/INT-2541 The `IntegrationMBeanExporter` doesn't register any `@ManagedResource` automatically. Its `autoDetection` is disabled by default. Hence such a components like `AbstractMessageGroupStore` or `WireTap` aren't exposed to the JMX by the `IntegrationMBeanExporter`. From other side `MBeanExporterHelper` aims to help to avoid duplicate exposing if an `MBeanExporter` is presented in the CTX. But `MBeanExporterHelper` did that unconditionally just for the whole `org.springframework.integration` package. Therefore components which aren't EIP ones aren't exposed to the JMX at all. * Fix `MBeanExporterHelper` to deal for exclusion based on the `@IntegrationManagedResource` annotation. * Remove `@IntegrationManagedResource` from those components which aren't EIP. * Make some polishing in the JMX tests.
This commit is contained in:
committed by
Gary Russell
parent
f049541b00
commit
ccc1568b89
@@ -1,21 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/jmx
|
||||
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
|
||||
|
||||
<context:mbean-server id="mbs" />
|
||||
|
||||
<context:mbean-server id="mbs"/>
|
||||
|
||||
<context:mbean-export server="mbs" default-domain="test.MessageStore"/>
|
||||
|
||||
<jmx:mbean-export server="mbs" default-domain="test.MessageStore"/>
|
||||
|
||||
<bean id="messageStore" class="org.springframework.integration.store.SimpleMessageStore"/>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
http://www.springframework.org/schema/integration/jmx
|
||||
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
|
||||
|
||||
<context:mbean-export default-domain="#{T(java.util.UUID).randomUUID().toString()}"/>
|
||||
<context:mbean-server/>
|
||||
|
||||
<context:mbean-export default-domain="#{T(java.util.UUID).randomUUID().toString()}"/>
|
||||
|
||||
<jmx:mbean-export default-domain="#{T(java.util.UUID).randomUUID().toString()}"/>
|
||||
|
||||
<si:message-history/>
|
||||
@@ -26,7 +28,7 @@
|
||||
object-name="test.publisher:name=publisher"
|
||||
default-notification-type="default.type">
|
||||
<jmx:request-handler-advice-chain>
|
||||
<bean class="org.springframework.integration.jmx.config.NotificationPublishingChannelAdapterParserTests$FooADvice"/>
|
||||
<bean class="org.springframework.integration.jmx.config.NotificationPublishingChannelAdapterParserTests.FooAdvice"/>
|
||||
</jmx:request-handler-advice-chain>
|
||||
</jmx:notification-publishing-channel-adapter>
|
||||
|
||||
|
||||
@@ -173,14 +173,14 @@ public class NotificationPublishingChannelAdapterParserTests {
|
||||
|
||||
}
|
||||
|
||||
public static class FooADvice extends AbstractRequestHandlerAdvice {
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@Override
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
|
||||
adviceCalled++;
|
||||
new RuntimeException("foo").printStackTrace();
|
||||
return callback.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
@@ -10,6 +10,7 @@
|
||||
* 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.springframework.integration_.mbeanexporterhelper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -23,11 +24,9 @@ import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerFactory;
|
||||
import javax.management.ObjectInstance;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.test.support.LongRunningIntegrationTest;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
|
||||
@@ -35,17 +34,13 @@ import org.springframework.jmx.export.MBeanExporter;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
*/
|
||||
public class Int2307Tests {
|
||||
|
||||
@Rule
|
||||
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testInt2307_DefaultMBeanExporter() throws Exception{
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("single-config.xml", this.getClass());
|
||||
public void testInt2307_DefaultMBeanExporter() throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("single-config.xml", getClass());
|
||||
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
|
||||
assertEquals(1, servers.size());
|
||||
MBeanServer server = servers.get(0);
|
||||
@@ -53,12 +48,13 @@ public class Int2307Tests {
|
||||
int bits = 0;
|
||||
int count = 0;
|
||||
for (ObjectInstance mbean : mbeans) {
|
||||
Thread.sleep(500); //Added in order to pass test with Java 8
|
||||
if (mbean.toString().startsWith("org.springframework.integration.support.management.LifecycleTrackableMessageHandlerMetrics[test.domain:type=MessageHandler,name=rlr,bean=endpoint,random=")) {
|
||||
if (mbean.toString()
|
||||
.startsWith("org.springframework.integration.support.management.LifecycleTrackableMessageHandlerMetrics[test.domain:type=MessageHandler,name=rlr,bean=endpoint,random=")) {
|
||||
bits |= 2;
|
||||
count++;
|
||||
}
|
||||
else if (mbean.toString().startsWith("org.springframework.integration.support.management.TrackableRouterMetrics[test.domain:type=MessageHandler,name=hvr,bean=endpoint,random=")) {
|
||||
else if (mbean.toString()
|
||||
.startsWith("org.springframework.integration.support.management.TrackableRouterMetrics[test.domain:type=MessageHandler,name=hvr,bean=endpoint,random=")) {
|
||||
bits |= 8;
|
||||
count++;
|
||||
}
|
||||
@@ -67,7 +63,8 @@ public class Int2307Tests {
|
||||
assertEquals(2, count);
|
||||
|
||||
Class<?> clazz = Class.forName("org.springframework.integration.jmx.config.MBeanExporterHelper");
|
||||
List<Object> beanPostProcessors = TestUtils.getPropertyValue(context, "beanFactory.beanPostProcessors", List.class);
|
||||
List<Object> beanPostProcessors =
|
||||
TestUtils.getPropertyValue(context, "beanFactory.beanPostProcessors", List.class);
|
||||
Object mBeanExporterHelper = null;
|
||||
for (Object beanPostProcessor : beanPostProcessors) {
|
||||
if (clazz.isAssignableFrom(beanPostProcessor.getClass())) {
|
||||
@@ -78,24 +75,22 @@ public class Int2307Tests {
|
||||
assertNotNull(mBeanExporterHelper);
|
||||
assertTrue(TestUtils.getPropertyValue(mBeanExporterHelper, "siBeanNames", Set.class).contains("z"));
|
||||
assertTrue(TestUtils.getPropertyValue(mBeanExporterHelper, "siBeanNames", Set.class).contains("zz"));
|
||||
|
||||
// make sure there are no duplicate MBean ObjectNames if 2 contexts loaded from same config
|
||||
new ClassPathXmlApplicationContext("single-config.xml", this.getClass()).close();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testInt2307_CustomMBeanExporter() throws Exception{
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("single-config-custom-exporter.xml", this.getClass());
|
||||
public void testInt2307_CustomMBeanExporter() throws Exception {
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("single-config-custom-exporter.xml", getClass());
|
||||
MBeanExporter exporter = context.getBean("myExporter", MBeanExporter.class);
|
||||
Set<String> excludedBeanNames = TestUtils.getPropertyValue(exporter, "excludedBeans", Set.class);
|
||||
assertTrue(excludedBeanNames.contains("rlr"));
|
||||
assertTrue(excludedBeanNames.contains("hvr"));
|
||||
assertTrue(excludedBeanNames.contains("x"));
|
||||
assertTrue(excludedBeanNames.contains("y"));
|
||||
assertTrue(excludedBeanNames.contains("foo")); // non SI bean
|
||||
Class<?> clazz = Class.forName("org.springframework.integration.jmx.config.MBeanExporterHelper");
|
||||
List<Object> beanPostProcessors = TestUtils.getPropertyValue(context, "beanFactory.beanPostProcessors", List.class);
|
||||
List<Object> beanPostProcessors =
|
||||
TestUtils.getPropertyValue(context, "beanFactory.beanPostProcessors", List.class);
|
||||
Object mBeanExporterHelper = null;
|
||||
for (Object beanPostProcessor : beanPostProcessors) {
|
||||
if (clazz.isAssignableFrom(beanPostProcessor.getClass())) {
|
||||
@@ -105,7 +100,11 @@ public class Int2307Tests {
|
||||
}
|
||||
assertNotNull(mBeanExporterHelper);
|
||||
assertTrue(TestUtils.getPropertyValue(mBeanExporterHelper, "siBeanNames", Set.class).contains("z"));
|
||||
context.close();
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
}
|
||||
|
||||
public static class Foo{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user