Search in sources :

Example 1 with IntegrationManagementConfigurer

use of org.springframework.integration.config.IntegrationManagementConfigurer in project spring-integration by spring-projects.

the class MBeanExporterParserTests method testMBeanExporterExists.

@Test
public void testMBeanExporterExists() {
    IntegrationMBeanExporter exporter = this.context.getBean(IntegrationMBeanExporter.class);
    MBeanServer server = this.context.getBean("mbs", MBeanServer.class);
    Properties properties = TestUtils.getPropertyValue(exporter, "objectNameStaticProperties", Properties.class);
    assertNotNull(properties);
    assertEquals(2, properties.size());
    assertTrue(properties.containsKey("foo"));
    assertTrue(properties.containsKey("bar"));
    assertEquals(server, exporter.getServer());
    assertSame(context.getBean("keyNamer"), TestUtils.getPropertyValue(exporter, "namingStrategy"));
    MessageChannelMetrics metrics = context.getBean("foo", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    checkCustomized(metrics);
    MessageHandlerMetrics handlerMetrics = context.getBean("transformer.handler", MessageHandlerMetrics.class);
    checkCustomized(handlerMetrics);
    metrics = context.getBean("bar", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    metrics = context.getBean("baz", MessageChannelMetrics.class);
    assertFalse(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    metrics = context.getBean("qux", MessageChannelMetrics.class);
    assertFalse(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    metrics = context.getBean("fiz", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertTrue(metrics.isStatsEnabled());
    metrics = context.getBean("buz", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertTrue(metrics.isStatsEnabled());
    metrics = context.getBean("!excluded", MessageChannelMetrics.class);
    assertFalse(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    checkCustomized(metrics);
    MetricsFactory factory = context.getBean(MetricsFactory.class);
    IntegrationManagementConfigurer configurer = context.getBean(IntegrationManagementConfigurer.class);
    assertSame(factory, TestUtils.getPropertyValue(configurer, "metricsFactory"));
    exporter.destroy();
}
Also used : MessageHandlerMetrics(org.springframework.integration.support.management.MessageHandlerMetrics) AbstractMessageHandlerMetrics(org.springframework.integration.support.management.AbstractMessageHandlerMetrics) DefaultMessageHandlerMetrics(org.springframework.integration.support.management.DefaultMessageHandlerMetrics) IntegrationManagementConfigurer(org.springframework.integration.config.IntegrationManagementConfigurer) IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) DefaultMessageChannelMetrics(org.springframework.integration.support.management.DefaultMessageChannelMetrics) AbstractMessageChannelMetrics(org.springframework.integration.support.management.AbstractMessageChannelMetrics) MessageChannelMetrics(org.springframework.integration.support.management.MessageChannelMetrics) MetricsFactory(org.springframework.integration.support.management.MetricsFactory) Properties(java.util.Properties) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 2 with IntegrationManagementConfigurer

use of org.springframework.integration.config.IntegrationManagementConfigurer in project spring-integration by spring-projects.

the class IntegrationManagementConfigurerTests method testDefaults.

@Test
public void testDefaults() {
    DirectChannel channel = new DirectChannel();
    AbstractMessageHandler handler = new RecipientListRouter();
    AbstractMessageSource<?> source = new AbstractMessageSource<Object>() {

        @Override
        public String getComponentType() {
            return null;
        }

        @Override
        protected Object doReceive() {
            return null;
        }
    };
    assertTrue(channel.isLoggingEnabled());
    assertTrue(handler.isLoggingEnabled());
    assertTrue(source.isLoggingEnabled());
    channel.setCountsEnabled(true);
    channel.setStatsEnabled(true);
    ApplicationContext ctx = mock(ApplicationContext.class);
    Map<String, IntegrationManagement> beans = new HashMap<String, IntegrationManagement>();
    beans.put("foo", channel);
    beans.put("bar", handler);
    beans.put("baz", source);
    when(ctx.getBeansOfType(IntegrationManagement.class)).thenReturn(beans);
    IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
    configurer.setBeanName(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
    configurer.setApplicationContext(ctx);
    configurer.setDefaultLoggingEnabled(false);
    configurer.afterSingletonsInstantiated();
    assertFalse(channel.isLoggingEnabled());
    assertFalse(handler.isLoggingEnabled());
    assertFalse(source.isLoggingEnabled());
    assertTrue(channel.isCountsEnabled());
    assertTrue(channel.isStatsEnabled());
}
Also used : IntegrationManagementConfigurer(org.springframework.integration.config.IntegrationManagementConfigurer) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) EnableIntegrationManagement(org.springframework.integration.config.EnableIntegrationManagement) RecipientListRouter(org.springframework.integration.router.RecipientListRouter) AbstractMessageSource(org.springframework.integration.endpoint.AbstractMessageSource) AbstractMessageHandler(org.springframework.integration.handler.AbstractMessageHandler) Test(org.junit.Test)

Example 3 with IntegrationManagementConfigurer

use of org.springframework.integration.config.IntegrationManagementConfigurer in project spring-integration by spring-projects.

the class IntegrationMBeanExporter method afterSingletonsInstantiated.

@Override
public void afterSingletonsInstantiated() {
    Map<String, MessageHandlerMetrics> messageHandlers = this.applicationContext.getBeansOfType(MessageHandlerMetrics.class);
    for (Entry<String, MessageHandlerMetrics> entry : messageHandlers.entrySet()) {
        String beanName = entry.getKey();
        MessageHandlerMetrics bean = entry.getValue();
        if (this.handlerInAnonymousWrapper(bean) != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Skipping " + beanName + " because it wraps another handler");
            }
            continue;
        }
        // If the handler is proxied, we have to extract the target to expose as an MBean.
        // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
        MessageHandlerMetrics monitor = (MessageHandlerMetrics) extractTarget(bean);
        this.handlers.add(monitor);
    }
    Map<String, MessageSourceMetrics> messageSources = this.applicationContext.getBeansOfType(MessageSourceMetrics.class);
    for (Entry<String, MessageSourceMetrics> entry : messageSources.entrySet()) {
        // If the source is proxied, we have to extract the target to expose as an MBean.
        // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
        MessageSourceMetrics monitor = (MessageSourceMetrics) extractTarget(entry.getValue());
        this.sources.add(monitor);
    }
    Map<String, MessageChannelMetrics> messageChannels = this.applicationContext.getBeansOfType(MessageChannelMetrics.class);
    for (Entry<String, MessageChannelMetrics> entry : messageChannels.entrySet()) {
        // If the channel is proxied, we have to extract the target to expose as an MBean.
        // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
        MessageChannelMetrics monitor = (MessageChannelMetrics) extractTarget(entry.getValue());
        this.channels.add(monitor);
    }
    Map<String, MessageProducer> messageProducers = this.applicationContext.getBeansOfType(MessageProducer.class);
    for (Entry<String, MessageProducer> entry : messageProducers.entrySet()) {
        MessageProducer messageProducer = entry.getValue();
        if (messageProducer instanceof Lifecycle) {
            Lifecycle target = (Lifecycle) extractTarget(messageProducer);
            if (!(target instanceof AbstractMessageProducingHandler)) {
                this.inboundLifecycleMessageProducers.add(target);
            }
        }
    }
    super.afterSingletonsInstantiated();
    try {
        registerChannels();
        registerHandlers();
        registerSources();
        registerEndpoints();
        if (this.applicationContext.containsBean(IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME)) {
            Object messageHistoryConfigurer = this.applicationContext.getBean(IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME);
            if (messageHistoryConfigurer instanceof MessageHistoryConfigurer) {
                registerBeanInstance(messageHistoryConfigurer, IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME);
            }
        }
        if (!this.applicationContext.containsBean(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)) {
            this.managementConfigurer = new IntegrationManagementConfigurer();
            this.managementConfigurer.setDefaultCountsEnabled(true);
            this.managementConfigurer.setDefaultStatsEnabled(true);
            this.managementConfigurer.setApplicationContext(this.applicationContext);
            this.managementConfigurer.setBeanName(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
            this.managementConfigurer.afterSingletonsInstantiated();
        } else {
            this.managementConfigurer = this.applicationContext.getBean(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, IntegrationManagementConfigurer.class);
        }
    } catch (RuntimeException e) {
        unregisterBeans();
        throw e;
    }
}
Also used : IntegrationManagementConfigurer(org.springframework.integration.config.IntegrationManagementConfigurer) MessageChannelMetrics(org.springframework.integration.support.management.MessageChannelMetrics) MessageSourceMetrics(org.springframework.integration.support.management.MessageSourceMetrics) LifecycleTrackableMessageSourceMetrics(org.springframework.integration.support.management.LifecycleTrackableMessageSourceMetrics) LifecycleMessageSourceMetrics(org.springframework.integration.support.management.LifecycleMessageSourceMetrics) MessageHistoryConfigurer(org.springframework.integration.history.MessageHistoryConfigurer) Lifecycle(org.springframework.context.Lifecycle) LifecycleTrackableMessageHandlerMetrics(org.springframework.integration.support.management.LifecycleTrackableMessageHandlerMetrics) LifecycleMessageHandlerMetrics(org.springframework.integration.support.management.LifecycleMessageHandlerMetrics) MessageHandlerMetrics(org.springframework.integration.support.management.MessageHandlerMetrics) AbstractMessageProducingHandler(org.springframework.integration.handler.AbstractMessageProducingHandler) MessageProducer(org.springframework.integration.core.MessageProducer)

Aggregations

IntegrationManagementConfigurer (org.springframework.integration.config.IntegrationManagementConfigurer)3 Test (org.junit.Test)2 MessageChannelMetrics (org.springframework.integration.support.management.MessageChannelMetrics)2 MessageHandlerMetrics (org.springframework.integration.support.management.MessageHandlerMetrics)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 MBeanServer (javax.management.MBeanServer)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Lifecycle (org.springframework.context.Lifecycle)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 EnableIntegrationManagement (org.springframework.integration.config.EnableIntegrationManagement)1 MessageProducer (org.springframework.integration.core.MessageProducer)1 AbstractMessageSource (org.springframework.integration.endpoint.AbstractMessageSource)1 AbstractMessageHandler (org.springframework.integration.handler.AbstractMessageHandler)1 AbstractMessageProducingHandler (org.springframework.integration.handler.AbstractMessageProducingHandler)1 MessageHistoryConfigurer (org.springframework.integration.history.MessageHistoryConfigurer)1 IntegrationMBeanExporter (org.springframework.integration.monitor.IntegrationMBeanExporter)1 RecipientListRouter (org.springframework.integration.router.RecipientListRouter)1 AbstractMessageChannelMetrics (org.springframework.integration.support.management.AbstractMessageChannelMetrics)1