Search in sources :

Example 1 with IntegrationMBeanExporter

use of org.springframework.integration.monitor.IntegrationMBeanExporter in project spring-integration by spring-projects.

the class NotificationPublishingMessageHandler method onInit.

@Override
public final void onInit() throws Exception {
    Assert.isTrue(this.getBeanFactory() instanceof ListableBeanFactory, "A ListableBeanFactory is required.");
    Map<String, MBeanExporter> exporters = BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory) this.getBeanFactory(), MBeanExporter.class);
    Assert.isTrue(exporters.size() > 0, "No MBeanExporter is available in the current context.");
    MBeanExporter exporter = null;
    for (MBeanExporter exp : exporters.values()) {
        exporter = exp;
        if (exporter instanceof IntegrationMBeanExporter) {
            break;
        }
    }
    if (this.notificationMapper == null) {
        this.notificationMapper = new DefaultNotificationMapper(this.objectName, this.defaultNotificationType);
    }
    exporter.registerManagedResource(this.delegate, this.objectName);
    if (this.logger.isInfoEnabled()) {
        this.logger.info("Registered JMX notification publisher as MBean with ObjectName: " + this.objectName);
    }
}
Also used : IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 2 with IntegrationMBeanExporter

use of org.springframework.integration.monitor.IntegrationMBeanExporter 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 3 with IntegrationMBeanExporter

use of org.springframework.integration.monitor.IntegrationMBeanExporter in project spring-integration by spring-projects.

the class IntegrationMBeanExportConfiguration method mbeanExporter.

@Bean(name = MBEAN_EXPORTER_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public IntegrationMBeanExporter mbeanExporter() {
    IntegrationMBeanExporter exporter = new IntegrationMBeanExporter();
    exporter.setRegistrationPolicy(this.attributes.getEnum("registration"));
    setupDomain(exporter);
    setupServer(exporter);
    setupComponentNamePatterns(exporter);
    if (this.configurer != null) {
        if (this.configurer.getDefaultCountsEnabled() == null) {
            this.configurer.setDefaultCountsEnabled(true);
        }
        if (this.configurer.getDefaultStatsEnabled() == null) {
            this.configurer.setDefaultStatsEnabled(true);
        }
    }
    return exporter;
}
Also used : IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) Role(org.springframework.context.annotation.Role) Bean(org.springframework.context.annotation.Bean)

Example 4 with IntegrationMBeanExporter

use of org.springframework.integration.monitor.IntegrationMBeanExporter in project spring-integration by spring-projects.

the class MBeanExporterHelper method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (AnnotatedElementUtils.isAnnotated(AopUtils.getTargetClass(bean), IntegrationManagedResource.class.getName())) {
        this.siBeanNames.add(beanName);
        if (!this.mBeanExportersForExcludes.isEmpty()) {
            for (MBeanExporter mBeanExporter : this.mBeanExportersForExcludes) {
                mBeanExporter.addExcludedBean(beanName);
            }
        }
    }
    if (bean instanceof MBeanExporter && !(bean instanceof IntegrationMBeanExporter)) {
        MBeanExporter mBeanExporter = (MBeanExporter) bean;
        this.mBeanExportersForExcludes.add(mBeanExporter);
        for (String siBeanName : this.siBeanNames) {
            mBeanExporter.addExcludedBean(siBeanName);
        }
    }
    return bean;
}
Also used : IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) IntegrationManagedResource(org.springframework.integration.support.management.IntegrationManagedResource)

Example 5 with IntegrationMBeanExporter

use of org.springframework.integration.monitor.IntegrationMBeanExporter in project spring-boot by spring-projects.

the class JmxAutoConfigurationTests method customJmxDomain.

@Test
void customJmxDomain() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(CustomJmxDomainConfiguration.class, JmxAutoConfiguration.class, IntegrationAutoConfiguration.class);
    this.context.refresh();
    IntegrationMBeanExporter mbeanExporter = this.context.getBean(IntegrationMBeanExporter.class);
    assertThat(mbeanExporter).hasFieldOrPropertyWithValue("domain", "foo.my");
}
Also used : IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test)

Aggregations

IntegrationMBeanExporter (org.springframework.integration.monitor.IntegrationMBeanExporter)5 MBeanExporter (org.springframework.jmx.export.MBeanExporter)2 Properties (java.util.Properties)1 MBeanServer (javax.management.MBeanServer)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Role (org.springframework.context.annotation.Role)1 IntegrationManagementConfigurer (org.springframework.integration.config.IntegrationManagementConfigurer)1 AbstractMessageChannelMetrics (org.springframework.integration.support.management.AbstractMessageChannelMetrics)1 AbstractMessageHandlerMetrics (org.springframework.integration.support.management.AbstractMessageHandlerMetrics)1 DefaultMessageChannelMetrics (org.springframework.integration.support.management.DefaultMessageChannelMetrics)1 DefaultMessageHandlerMetrics (org.springframework.integration.support.management.DefaultMessageHandlerMetrics)1 IntegrationManagedResource (org.springframework.integration.support.management.IntegrationManagedResource)1 MessageChannelMetrics (org.springframework.integration.support.management.MessageChannelMetrics)1 MessageHandlerMetrics (org.springframework.integration.support.management.MessageHandlerMetrics)1 MetricsFactory (org.springframework.integration.support.management.MetricsFactory)1