INT-3664: Rework BPP in the IntMBExporter

JIRA: https://jira.spring.io/browse/INT-3664

Since all metrics are already direct for the integration components, we don't do any proxying from `IntegrationMBeanExporter`,
and even any other adjustments during BPP phases. Hence this stuff is already redundant for `IntegrationMBeanExporter`.
In addition this change fix the `early access to the BeanFactory from BPP` issue.

INT-3664: Address PR comments

Doc Polish

INT-3664: Polishing according the SF changes to the `PostProcessorRegistrationDelegate$BeanPostProcessorChecker`
This commit is contained in:
Artem Bilan
2015-03-03 21:36:14 +02:00
committed by Gary Russell
parent b7ba238860
commit 0f05512e9a
6 changed files with 116 additions and 170 deletions

View File

@@ -190,6 +190,15 @@ public class MBeanExporterIntegrationTests {
}
// Lifecycle method name
assertEquals("start", startName);
context.close();
context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
server = context.getBean(MBeanServer.class);
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
assertEquals(1, names.size());
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
assertEquals(1, names.size());
}
@Test

View File

@@ -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.monitor;
import org.aopalliance.intercept.MethodInterceptor;
@@ -19,9 +20,11 @@ import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.NameMatchMethodPointcutAdvisor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
@@ -32,10 +35,13 @@ import org.springframework.util.ClassUtils;
* @author Tareq Abedrabbo
* @author Dave Syer
* @author Gary Russell
* @author Artem Bilan
* @since 2.0.4
*/
public class MessageMetricsAdviceTests {
private ConfigurableListableBeanFactory beanFactory;
private IntegrationMBeanExporter mBeanExporter;
private MessageHandler handler;
@@ -44,12 +50,16 @@ public class MessageMetricsAdviceTests {
@Before
public void setUp() throws Exception {
channel = new NullChannel();
mBeanExporter = new IntegrationMBeanExporter();
mBeanExporter.setBeanFactory(new DefaultListableBeanFactory());
mBeanExporter.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
mBeanExporter.afterPropertiesSet();
handler = new DummyHandler();
GenericApplicationContext applicationContext = TestUtils.createTestApplicationContext();
this.beanFactory = applicationContext.getBeanFactory();
this.channel = new NullChannel();
this.mBeanExporter = new IntegrationMBeanExporter();
this.mBeanExporter.setApplicationContext(applicationContext);
this.mBeanExporter.setBeanFactory(this.beanFactory);
this.mBeanExporter.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
this.mBeanExporter.afterPropertiesSet();
this.handler = new DummyHandler();
applicationContext.refresh();
}
@Test
@@ -59,11 +69,15 @@ public class MessageMetricsAdviceTests {
NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(interceptor);
advisor.addMethodName("handleMessage");
ProxyFactory factory = new ProxyFactory(handler);
ProxyFactory factory = new ProxyFactory(this.handler);
factory.addAdvisor(advisor);
MessageHandler advised = (MessageHandler) factory.getProxy();
MessageHandler exported = (MessageHandler) mBeanExporter.postProcessAfterInitialization(advised, "test");
this.beanFactory.registerSingleton("test", advised);
this.beanFactory.initializeBean(advised, "test");
mBeanExporter.afterSingletonsInstantiated();
MessageHandler exported = this.beanFactory.getBean("test", MessageHandler.class);
exported.handleMessage(MessageBuilder.withPayload("test").build());
}
@@ -78,7 +92,11 @@ public class MessageMetricsAdviceTests {
factory.addAdvisor(advisor);
MessageChannel advised = (MessageChannel) factory.getProxy();
MessageChannel exported = (MessageChannel) mBeanExporter.postProcessAfterInitialization(advised, "test");
this.beanFactory.registerSingleton("test", advised);
this.beanFactory.initializeBean(advised, "test");
mBeanExporter.afterSingletonsInstantiated();
MessageChannel exported = this.beanFactory.getBean("test", MessageChannel.class);
exported.send(MessageBuilder.withPayload("test").build());
}
@@ -91,6 +109,7 @@ public class MessageMetricsAdviceTests {
public void handleMessage(Message<?> message) throws MessagingException {
invoked = true;
}
}
private static class DummyInterceptor implements MethodInterceptor {
@@ -107,5 +126,7 @@ public class MessageMetricsAdviceTests {
public String toString() {
return super.toString() + "{" + "invoked=" + invoked + '}';
}
}
}