INT-3186 Fix Metrics For Direct MessageHandler
When a simple MessageHandler is referenced from a `<service-activator/>`, it is wrapped in an anonymous AbstractReplyProducingMessageHandler to facilitate proper handling of the `<request-handler-advice-chain/>` and so that normal 'produced no reply` messages are logged. Previously, this caused 2 MBeans to be exposed, one for tha actual handler; one for the wrapper. This added more stack frames between the dispatcher and the handler (because 2 sets of statistics were captured). The root cause was that the MBean exporter was not aware of the relationship between these objects. https://jira.springsource.org/browse/INT-3186 Add code to the IntegrationMBeanExporter to suppress adding metrics to the wrapper. This involves detecting that it is a wrapper and not exposing it as an MBean and, when matching handlers with endpoints, checking that the wrapped handler is the actual handler for the endpoint. Update test to reflect the reduced number of stack frames between the dispatcher and handler. Also add tests to verify the detection of multiple references to the same ARPMH. INT-3186: `IntegrationMBeanExporter` optimization
This commit is contained in:
committed by
Artem Bilan
parent
cc434db959
commit
eaa28a9dbf
@@ -27,19 +27,19 @@
|
||||
<service-activator id="replyingHandlerWithStandardMethodTestService"
|
||||
input-channel="replyingHandlerWithStandardMethodTestInputChannel"
|
||||
method="handleMessage">
|
||||
<beans:bean
|
||||
<beans:bean id="innerReplyingHandler"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestReplyingMessageHandler"/>
|
||||
</service-activator>
|
||||
|
||||
<service-activator id="replyingHandlerWithOtherMethodTestService"
|
||||
input-channel="replyingHandlerWithOtherMethodTestInputChannel"
|
||||
method="foo">
|
||||
<beans:bean
|
||||
<beans:bean id="innerReplyingHandlerFoo"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestReplyingMessageHandler"/>
|
||||
</service-activator>
|
||||
|
||||
<service-activator id="handlerTestService" input-channel="handlerTestInputChannel">
|
||||
<beans:bean
|
||||
<beans:bean id="innerHandler"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestMessageHandler"/>
|
||||
</service-activator>
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
|
||||
xsi:schemaLocation="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
|
||||
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">
|
||||
|
||||
<context:mbean-server/>
|
||||
<int-jmx:mbean-export default-domain="test2"/>
|
||||
|
||||
<service-activator id="optimizedRefReplyingHandlerTestService1"
|
||||
input-channel="optimizedRefReplyingHandlerTestInputChannel" ref="testReplyingMessageHandler"/>
|
||||
|
||||
<service-activator id="optimizedRefReplyingHandlerTestService2"
|
||||
input-channel="optimizedRefReplyingHandlerTestInputChannel" ref="testReplyingMessageHandler"/>
|
||||
|
||||
<beans:bean id="testReplyingMessageHandler"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestReplyingMessageHandler"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -18,11 +18,16 @@ package org.springframework.integration.jmx;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -151,6 +156,23 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
assertEquals("processorTestInputChannel,processorTestService", reply.getHeaders().get("history").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailOnDoubleReference() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-context.xml",
|
||||
this.getClass());
|
||||
fail("Expected exception due to 2 endpoints referencing the same bean");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, Matchers.instanceOf(BeanCreationException.class));
|
||||
assertThat(e.getCause(), Matchers.instanceOf(BeanCreationException.class));
|
||||
assertThat(e.getCause().getCause(), Matchers.instanceOf(IllegalArgumentException.class));
|
||||
assertThat(e.getCause().getCause().getMessage(),
|
||||
Matchers.containsString("An AbstractReplyProducingMessageHandler may only be referenced once"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private interface Foo {
|
||||
|
||||
public String foo(String in);
|
||||
@@ -181,7 +203,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
public void handleMessage(Message<?> requestMessage) {
|
||||
Exception e = new RuntimeException();
|
||||
StackTraceElement[] st = e.getStackTrace();
|
||||
assertEquals("doDispatch", st[28].getMethodName());
|
||||
assertEquals("doDispatch", st[16].getMethodName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user