INT-1431, added SimpleMessageProducingHandlerMonitor to maintain semantics of some MessageHandlers also being MessageProducers
This commit is contained in:
@@ -88,7 +88,7 @@ public class MessagePublishingInterceptor implements MethodInterceptor {
|
||||
final StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.addPropertyAccessor(new MapAccessor());
|
||||
Class<?> targetClass = AopUtils.getTargetClass(invocation.getThis());
|
||||
Method method = AopUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
|
||||
final Method method = AopUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
|
||||
String[] argumentNames = this.resolveArgumentNames(method);
|
||||
context.setVariable(PublisherMetadataSource.METHOD_NAME_VARIABLE_NAME, method.getName());
|
||||
if (invocation.getArguments().length > 0 && argumentNames != null) {
|
||||
@@ -114,6 +114,16 @@ public class MessagePublishingInterceptor implements MethodInterceptor {
|
||||
}
|
||||
finally {
|
||||
publishMessage(method, context);
|
||||
// Thread t = new Thread(new Runnable() {
|
||||
// public void run() {
|
||||
// try {
|
||||
// publishMessage(method, context);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace(); }
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// t.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.MessageProducer;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
@@ -78,6 +79,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Helena Edelson
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@ManagedResource
|
||||
public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostProcessor, BeanFactoryAware,
|
||||
@@ -162,7 +164,12 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof MessageHandler) {
|
||||
SimpleMessageHandlerMonitor monitor = new SimpleMessageHandlerMonitor((MessageHandler) bean);
|
||||
SimpleMessageHandlerMonitor monitor = null;
|
||||
if (bean instanceof MessageProducer){ // we need to maintain semantics of the handler also being a producer see INT-1431
|
||||
monitor = new SimpleMessageProducingHandlerMonitor((MessageHandler) bean);
|
||||
} else {
|
||||
monitor = new SimpleMessageHandlerMonitor((MessageHandler) bean);
|
||||
}
|
||||
handlers.add(monitor);
|
||||
return monitor;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Copyright 2002-2010 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
|
||||
*
|
||||
* 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.springframework.integration.monitor;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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
|
||||
*
|
||||
* 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.springframework.integration.monitor;
|
||||
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.MessageProducer;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
@ManagedResource
|
||||
public class SimpleMessageProducingHandlerMonitor extends SimpleMessageHandlerMonitor implements MessageProducer {
|
||||
|
||||
public SimpleMessageProducingHandlerMonitor(MessageHandler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public void setOutputChannel(MessageChannel outputChannel) {
|
||||
((MessageProducer)this.getMessageHandler()).setOutputChannel(outputChannel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:p="http://www.springframework.org/schema/p">
|
||||
|
||||
<int:channel id="controlChannel" />
|
||||
|
||||
<bean id="controlBus" class="org.springframework.integration.control.ControlBus">
|
||||
<constructor-arg ref="mbeanExporter" />
|
||||
<constructor-arg ref="mbeanServer" />
|
||||
<constructor-arg ref="controlChannel" />
|
||||
</bean>
|
||||
|
||||
<bean id="mbeanExporter"
|
||||
class="org.springframework.integration.monitor.IntegrationMBeanExporter"
|
||||
p:server-ref="mbeanServer" p:domain="forum" />
|
||||
|
||||
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"
|
||||
p:locateExistingServerIfPossible="true" />
|
||||
|
||||
<int:chain input-channel="inputChannel">
|
||||
<int:transformer>
|
||||
<bean class="org.springframework.integration.monitor.ChainWithMessageProducingHandlersTests.SampleProducer" />
|
||||
</int:transformer>
|
||||
<int:service-activator>
|
||||
<bean class="org.springframework.integration.monitor.ChainWithMessageProducingHandlersTests.SampleService" />
|
||||
</int:service-activator>
|
||||
</int:chain>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ChainWithMessageProducingHandlersTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testSuccessfullApplicationContext(){
|
||||
// this is all we need to do. Until INT-1431 was solved initialization of this AC would fail.
|
||||
assertNotNull(applicationContext);
|
||||
}
|
||||
|
||||
public static class SampleProducer{
|
||||
public String echo(String value){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
public static class SampleService{
|
||||
public void echo(String value){}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user