INT-4544: Allow runtime MBeans (un)registered (#2601)

* INT-4544: Allow runtime MBeans (un)registered

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

* Fix `SourcePollingChannelAdapterFactoryBean` to register an
`outputChannelName` into the `SourcePollingChannelAdapter` for late
binding, especially in case of dynamic `IntegrationFlow` registrations.
This must be back-ported to `5.0.x`
* Implement `DestructionAwareBeanPostProcessor` in the
`IntegrationMBeanExporter` for the runtime beans tracking, e.g. via
dynamic `IntegrationFlow` registrations
* Refactor `IntegrationMBeanExporter` for static and dynamic beans
registration and destruction
* Remove unused properties; introduce some new for tracking beans and
their relationship

* * Move `IntegrationMBeanExporter.registerProducer()` after
`postProcessAfterInitialization()`
* Refactor JMX test configurations to reuse MBeanServer as much as
possible and destroy the server whenever it is necessary

* * More JMX tests polishing

* * And more JMX tests polishing

* * `try...catch` in the `IntegrationMBeanExporter.postProcessAfterInitialization()`
to avoid breaking changes for the current GA phase
* Do not unregister those MBeans explicitly which weren't created at
runtime

* * Log ObjectNames in the `MBeanExporterIntegrationTests`

* * Fix `MessageMetricsAdviceTests` to rely on the application context
* Do not use a cst in the `StandardIntegrationFlowContext` for
`BeanFactory`, but an explicit `BeanDefinitionRegistry`
* Extract targets from proxies in the
`IntegrationMBeanExporter.postProcessAfterInitialization()`
* Remove logging in the `MBeanExporterIntegrationTests`

* * Fix `NotificationListeningMessageProducerTests` to reuse existing `MBeanServer`

* * Change JMX `domain` in the `DslMBeanTests` to `dsl` do not clash with
similar in the `foo` in the `MessageSourceTests`
* Use `MBeanServer` bean in the `Int2307Tests`
* Use JUnit 5ctor injection injection in the `MessageMetricsAdviceTests`

* * Fix JMX tests do not reuse existing `MBeanServer` and make them rely
on the server provided by the managed `MBeanServerFactoryBean` which
destroys a server on application context close
* Fix `StoredProcJmxManagedBeanTests-context.xml` to use `MBeanServer`
from the `<context:mbean-server>`
This commit is contained in:
Artem Bilan
2018-10-19 09:51:25 -04:00
committed by Gary Russell
parent 40ba72b84a
commit e3ce37ca36
62 changed files with 769 additions and 501 deletions

View File

@@ -145,7 +145,7 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean<Sourc
}
@Override
public SourcePollingChannelAdapter getObject() throws Exception {
public SourcePollingChannelAdapter getObject() {
if (this.adapter == null) {
initializeAdapter();
}
@@ -169,15 +169,18 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean<Sourc
}
Assert.notNull(this.source, "source is required");
if (StringUtils.hasText(this.outputChannelName)) {
Assert.isNull(this.outputChannel, "'outputChannelName' and 'outputChannel' are mutually exclusive.");
this.outputChannel = this.channelResolver.resolveDestination(this.outputChannelName);
}
Assert.notNull(this.outputChannel, "outputChannel is required");
SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
spca.setSource(this.source);
spca.setOutputChannel(this.outputChannel);
if (StringUtils.hasText(this.outputChannelName)) {
Assert.isNull(this.outputChannel, "'outputChannelName' and 'outputChannel' are mutually exclusive.");
spca.setOutputChannelName(this.outputChannelName);
}
else {
Assert.notNull(this.outputChannel, "outputChannel is required");
spca.setOutputChannel(this.outputChannel);
}
if (this.pollerMetadata == null) {
this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '"

View File

@@ -134,7 +134,7 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont
BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) bean.getClass(), () -> bean)
.getRawBeanDefinition();
((BeanDefinitionRegistry) this.beanFactory).registerBeanDefinition(beanName, beanDefinition);
this.beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition);
if (parentName != null) {
this.beanFactory.registerDependentBean(parentName, beanName);

View File

@@ -9,8 +9,9 @@
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 />
<context:mbean-export default-domain="org.springframework.integration.jdbc.test" />
<context:mbean-server id="mbeanServer"/>
<context:mbean-export server="mbeanServer" default-domain="org.springframework.integration.jdbc.test" />
<import resource="classpath:derby-stored-procedures-setup-context.xml"/>

View File

@@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EmbeddedValueResolverAware;
@@ -49,7 +50,10 @@ import org.springframework.integration.config.IntegrationManagementConfigurer;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.context.OrderlyShutdownCapable;
import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.IntegrationConsumer;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.gateway.MessagingGatewaySupport;
import org.springframework.integration.handler.AbstractMessageProducingHandler;
import org.springframework.integration.history.MessageHistoryConfigurer;
@@ -114,7 +118,7 @@ import org.springframework.util.StringValueResolver;
*/
@org.springframework.jmx.export.annotation.ManagedResource
public class IntegrationMBeanExporter extends MBeanExporter implements ApplicationContextAware,
EmbeddedValueResolverAware {
EmbeddedValueResolverAware, DestructionAwareBeanPostProcessor {
private static final Log logger = LogFactory.getLog(IntegrationMBeanExporter.class);
@@ -138,27 +142,32 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
private final Map<String, MessageChannelMetrics> allChannelsByName = new HashMap<>();
private final Map<String, MessageHandlerMetrics> allHandlersByName = new HashMap<>();
private final Map<String, MessageSourceMetrics> allSourcesByName = new HashMap<>();
private final Map<String, String> beansByEndpointName = new HashMap<>();
private final Map<Object, String> endpointsByMonitor = new HashMap<>();
private String domain = DEFAULT_DOMAIN;
private final Map<Object, ObjectName> objectNames = new HashMap<>();
private final Set<String> endpointNames = new HashSet<>();
private final AtomicBoolean shuttingDown = new AtomicBoolean();
private final Properties objectNameStaticProperties = new Properties();
private final Set<Object> runtimeBeans = new HashSet<>();
private final MetadataNamingStrategy defaultNamingStrategy =
new IntegrationMetadataNamingStrategy(this.attributeSource);
private String domain = DEFAULT_DOMAIN;
private String[] componentNamePatterns = { "*" };
private IntegrationManagementConfigurer managementConfigurer;
private volatile long shutdownDeadline;
private final AtomicBoolean shuttingDown = new AtomicBoolean();
private volatile boolean singletonsInstantiated;
public IntegrationMBeanExporter() {
super();
@@ -257,10 +266,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
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);
}
registerProducer(messageProducer);
}
}
super.afterSingletonsInstantiated();
@@ -292,12 +298,114 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
this.applicationContext.getBean(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME,
IntegrationManagementConfigurer.class);
}
this.singletonsInstantiated = true;
}
catch (RuntimeException e) {
unregisterBeans();
throw e;
}
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (this.singletonsInstantiated) {
try {
if (bean instanceof MessageChannelMetrics) {
MessageChannelMetrics monitor = (MessageChannelMetrics) extractTarget(bean);
this.channels.add(monitor);
registerChannel(monitor);
this.runtimeBeans.add(bean);
}
else if (bean instanceof MessageProducer && bean instanceof Lifecycle) {
registerProducer((MessageProducer) bean);
this.runtimeBeans.add(bean);
}
else if (bean instanceof AbstractEndpoint) {
if (bean instanceof IntegrationConsumer) {
IntegrationConsumer integrationConsumer = (IntegrationConsumer) bean;
MessageHandler handler = integrationConsumer.getHandler();
if (handler instanceof MessageHandlerMetrics) {
MessageHandlerMetrics messageHandlerMetrics =
(MessageHandlerMetrics) extractTarget(handler);
registerHandler(messageHandlerMetrics);
this.handlers.add(messageHandlerMetrics);
this.runtimeBeans.add(messageHandlerMetrics);
return bean;
}
}
else if (bean instanceof SourcePollingChannelAdapter) {
SourcePollingChannelAdapter pollingChannelAdapter = (SourcePollingChannelAdapter) bean;
MessageSource<?> messageSource = pollingChannelAdapter.getMessageSource();
if (messageSource instanceof MessageSourceMetrics) {
MessageSourceMetrics messageSourceMetrics =
(MessageSourceMetrics) extractTarget(messageSource);
registerSource(messageSourceMetrics);
this.sources.add(messageSourceMetrics);
this.runtimeBeans.add(messageSourceMetrics);
return bean;
}
}
registerEndpoint((AbstractEndpoint) bean);
this.runtimeBeans.add(bean);
}
}
catch (Exception e) {
logger.error("Could not register an MBean for: " + beanName, e);
}
}
return bean;
}
private void registerProducer(MessageProducer messageProducer) {
Lifecycle target = (Lifecycle) extractTarget(messageProducer);
if (!(target instanceof AbstractMessageProducingHandler)) {
this.inboundLifecycleMessageProducers.add(target);
}
}
@Override
public boolean requiresDestruction(Object bean) {
return bean instanceof MessageChannelMetrics ||
bean instanceof MessageHandlerMetrics ||
bean instanceof MessageSourceMetrics ||
(bean instanceof MessageProducer && bean instanceof Lifecycle) ||
bean instanceof AbstractEndpoint;
}
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
if (this.runtimeBeans.remove(bean)) {
ObjectName objectName = this.objectNames.remove(bean);
if (objectName != null) {
doUnregister(objectName);
if (bean instanceof AbstractEndpoint) {
this.endpointNames.remove(((AbstractEndpoint) bean).getComponentName());
}
else {
this.endpointsByMonitor.remove(bean);
if (bean instanceof MessageChannelMetrics) {
this.channels.remove(bean);
this.allChannelsByName.remove(((NamedComponent) bean).getComponentName());
}
else if (bean instanceof MessageHandlerMetrics) {
this.handlers.remove(bean);
this.endpointNames.remove(((NamedComponent) bean).getComponentName());
}
else if (bean instanceof MessageSourceMetrics) {
this.sources.remove(bean);
this.endpointNames.remove(((NamedComponent) bean).getComponentName());
String managedName = ((MessageSourceMetrics) bean).getManagedName();
this.allSourcesByName.remove(managedName);
}
}
}
else if (bean instanceof MessageProducer && bean instanceof Lifecycle) {
this.inboundLifecycleMessageProducers.remove(bean);
}
}
}
private MessageHandler handlerInAnonymousWrapper(final Object bean) {
@@ -629,89 +737,94 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
private void registerChannels() {
for (MessageChannelMetrics monitor : this.channels) {
String name = ((NamedComponent) monitor).getComponentName();
this.allChannelsByName.put(name, monitor);
if (!matches(this.componentNamePatterns, name)) {
continue;
}
this.channels.forEach(this::registerChannel);
}
private void registerChannel(MessageChannelMetrics monitor) {
String name = ((NamedComponent) monitor).getComponentName();
this.allChannelsByName.put(name, monitor);
if (matches(this.componentNamePatterns, name)) {
String beanKey = getChannelBeanKey(name);
if (logger.isInfoEnabled()) {
logger.info("Registering MessageChannel " + name);
}
registerBeanNameOrInstance(monitor, beanKey);
ObjectName objectName = registerBeanNameOrInstance(monitor, beanKey);
this.objectNames.put(monitor, objectName);
}
}
private void registerHandlers() {
for (MessageHandlerMetrics handler : this.handlers) {
MessageHandlerMetrics monitor = enhanceHandlerMonitor(handler);
String name = monitor.getManagedName();
this.allHandlersByName.put(name, monitor);
if (!matches(this.componentNamePatterns, name)) {
continue;
}
this.handlers.forEach(this::registerHandler);
}
private void registerHandler(MessageHandlerMetrics handler) {
MessageHandlerMetrics monitor = enhanceHandlerMonitor(handler);
String name = monitor.getManagedName();
if (matches(this.componentNamePatterns, name)) {
String beanKey = getHandlerBeanKey(monitor);
if (logger.isInfoEnabled()) {
logger.info("Registering MessageHandler " + name);
}
registerBeanNameOrInstance(monitor, beanKey);
ObjectName objectName = registerBeanNameOrInstance(monitor, beanKey);
this.objectNames.put(handler, objectName);
}
}
private void registerSources() {
for (MessageSourceMetrics source : this.sources) {
MessageSourceMetrics monitor = enhanceSourceMonitor(source);
String name = monitor.getManagedName();
this.allSourcesByName.put(name, monitor);
if (!matches(this.componentNamePatterns, name)) {
continue;
}
this.sources.forEach(this::registerSource);
}
private void registerSource(MessageSourceMetrics source) {
MessageSourceMetrics monitor = enhanceSourceMonitor(source);
String name = monitor.getManagedName();
this.allSourcesByName.put(name, monitor);
if (matches(this.componentNamePatterns, name)) {
String beanKey = getSourceBeanKey(monitor);
if (logger.isInfoEnabled()) {
logger.info("Registering MessageSource " + name);
}
registerBeanNameOrInstance(monitor, beanKey);
ObjectName objectName = registerBeanNameOrInstance(monitor, beanKey);
this.objectNames.put(source, objectName);
}
}
private void registerEndpoints() {
String[] names = this.applicationContext.getBeanNamesForType(AbstractEndpoint.class);
Set<String> endpointNames = new HashSet<>();
for (String name : names) {
if (!this.beansByEndpointName.values().contains(name)) {
if (!this.endpointsByMonitor.values().contains(name)) {
AbstractEndpoint endpoint = this.applicationContext.getBean(name, AbstractEndpoint.class);
String beanKey;
name = endpoint.getComponentName();
String source;
if (name.startsWith("_org.springframework.integration")) {
name = getInternalComponentName(name);
source = "internal";
}
else {
name = endpoint.getComponentName();
source = "endpoint";
}
if (!matches(this.componentNamePatterns, name)) {
continue;
}
if (endpointNames.contains(name)) {
int count = 0;
String unique = name + "#" + count;
while (endpointNames.contains(unique)) {
unique = name + "#" + (++count);
}
name = unique;
}
endpointNames.add(name);
beanKey = getEndpointBeanKey(endpoint, name, source);
ObjectName objectName = registerBeanInstance(new ManagedEndpoint(endpoint), beanKey);
if (logger.isInfoEnabled()) {
logger.info("Registered endpoint without MessageSource: " + objectName);
registerEndpoint(endpoint);
}
}
}
private void registerEndpoint(AbstractEndpoint endpoint) {
String beanKey;
String name = endpoint.getComponentName();
String source;
if (name.startsWith("_org.springframework.integration")) {
name = getInternalComponentName(name);
source = "internal";
}
else {
source = "endpoint";
}
if (matches(this.componentNamePatterns, name)) {
if (this.endpointNames.contains(name)) {
int count = 0;
String unique = name + "#" + count;
while (this.endpointNames.contains(unique)) {
unique = name + "#" + (++count);
}
name = unique;
}
this.endpointNames.add(name);
beanKey = getEndpointBeanKey(endpoint, name, source);
ObjectName objectName = registerBeanInstance(new ManagedEndpoint(endpoint), beanKey);
this.objectNames.put(endpoint, objectName);
if (logger.isInfoEnabled()) {
logger.info("Registered endpoint without MessageSource: " + objectName);
}
}
}
@@ -806,19 +919,19 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
// Assignment algorithm and bean id, with bean id pulled reflectively out of enclosing endpoint if possible
String[] names = this.applicationContext.getBeanNamesForType(AbstractEndpoint.class);
String[] names = this.applicationContext.getBeanNamesForType(IntegrationConsumer.class);
String name = null;
String endpointName = null;
String source = "endpoint";
Object endpoint = null;
IntegrationConsumer endpoint = null;
for (String beanName : names) {
endpoint = this.applicationContext.getBean(beanName);
endpoint = this.applicationContext.getBean(beanName, IntegrationConsumer.class);
try {
Object field = extractTarget(getField(endpoint, "handler"));
if (field == monitor ||
this.extractTarget(this.handlerInAnonymousWrapper(field)) == monitor) {
MessageHandler handler = endpoint.getHandler();
if (handler == monitor ||
extractTarget(handlerInAnonymousWrapper(handler)) == monitor) {
name = beanName;
endpointName = beanName;
break;
@@ -826,6 +939,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
catch (Exception e) {
logger.trace("Could not get handler from bean = " + beanName);
endpoint = null;
}
}
if (name != null && endpoint != null && name.startsWith("_org.springframework.integration")) {
@@ -833,33 +947,22 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
source = "internal";
}
if (name != null && endpoint != null && name.startsWith("org.springframework.integration")) {
Object target = endpoint;
if (endpoint instanceof Advised) {
TargetSource targetSource = ((Advised) endpoint).getTargetSource();
if (targetSource != null) {
try {
target = targetSource.getTarget();
}
catch (Exception e) {
logger.error("Could not get handler from bean = " + name);
}
MessageChannel inputChannel = endpoint.getInputChannel();
if (inputChannel != null) {
if (!this.anonymousHandlerCounters.containsKey(inputChannel)) {
this.anonymousHandlerCounters.put(inputChannel, new AtomicLong());
}
}
Object field = getField(target, "inputChannel");
if (field != null) {
if (!this.anonymousHandlerCounters.containsKey(field)) {
this.anonymousHandlerCounters.put(field, new AtomicLong());
}
AtomicLong count = this.anonymousHandlerCounters.get(field);
AtomicLong count = this.anonymousHandlerCounters.get(inputChannel);
long total = count.incrementAndGet();
String suffix = "";
/*
* Short hack to makes sure object names are unique if more than one endpoint has the same input channel
* Short hack to makes sure object names are unique if more than one endpoint has the same input
* channel
*/
if (total > 1) {
suffix = "#" + total;
}
name = field + suffix;
name = inputChannel + suffix;
source = "anonymous";
}
}
@@ -868,7 +971,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
// Wrap the monitor in a lifecycle so it exposes the start/stop operations
if (monitor instanceof MappingMessageRouterManagement) {
if (monitor instanceof TrackableComponent) {
result = new TrackableRouterMetrics((Lifecycle) endpoint, (MappingMessageRouterManagement) monitor);
result = new TrackableRouterMetrics((Lifecycle) endpoint,
(MappingMessageRouterManagement) monitor);
}
else {
result = new RouterMetrics((Lifecycle) endpoint, (MappingMessageRouterManagement) monitor);
@@ -895,11 +999,11 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
if (endpointName != null) {
this.beansByEndpointName.put(name, endpointName);
this.endpointsByMonitor.put(monitor, endpointName);
}
monitor.setManagedType(source);
monitor.setManagedName(name);
result.setManagedType(source);
result.setManagedName(name);
return result;
@@ -910,7 +1014,6 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
private MessageSourceMetrics enhanceSourceMonitor(MessageSourceMetrics monitor) {
MessageSourceMetrics result = monitor;
if (monitor.getManagedName() != null) {
@@ -937,6 +1040,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
catch (Exception e) {
logger.trace("Could not get source from bean = " + beanName);
endpoint = null;
}
}
@@ -972,7 +1076,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
outputChannel = ((MessagingGatewaySupport) target).getRequestChannel();
}
else {
outputChannel = getField(target, "outputChannel");
outputChannel = ((SourcePollingChannelAdapter) target).getOutputChannel();
}
if (outputChannel != null) {
@@ -983,7 +1087,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
long total = count.incrementAndGet();
String suffix = "";
/*
* Short hack to makes sure object names are unique if more than one endpoint has the same input channel
* Short hack to makes sure object names are unique if more than one endpoint has the same input
* channel
*/
if (total > 1) {
suffix = "#" + total;
@@ -1021,7 +1126,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
if (endpointName != null) {
this.beansByEndpointName.put(name, endpointName);
this.endpointsByMonitor.put(monitor, endpointName);
}
monitor.setManagedType(source);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -23,52 +23,47 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.management.MBeanServer;
import org.junit.Before;
import org.junit.Test;
import org.springframework.messaging.Message;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.messaging.Message;
/**
* @author Mark Fisher
* @author Artem Bilan
*
* @since 2.0
*/
public class AttributePollingMessageSourceTests {
private final TestCounter counter = new TestCounter();
private volatile MBeanServer server;
@Before
public void setup() throws Exception {
MBeanServerFactoryBean factoryBean = new MBeanServerFactoryBean();
factoryBean.setLocateExistingServerIfPossible(true);
factoryBean.afterPropertiesSet();
this.server = factoryBean.getObject();
this.server.registerMBean(this.counter, ObjectNameManager.getInstance("test:name=counter"));
}
@Test
public void basicPolling() {
public void basicPolling() throws Exception {
MBeanServerFactoryBean factoryBean = new MBeanServerFactoryBean();
factoryBean.afterPropertiesSet();
MBeanServer server = factoryBean.getObject();
TestCounter counter = new TestCounter();
server.registerMBean(counter, ObjectNameManager.getInstance("test:name=counter"));
AttributePollingMessageSource source = new AttributePollingMessageSource();
source.setAttributeName("Count");
source.setObjectName("test:name=counter");
source.setServer(this.server);
source.setServer(server);
Message<?> message1 = source.receive();
assertNotNull(message1);
assertEquals(0, message1.getPayload());
this.counter.increment();
counter.increment();
Message<?> message2 = source.receive();
assertNotNull(message2);
assertEquals(1, message2.getPayload());
factoryBean.destroy();
}
public interface TestCounterMBean {
int getCount();
}
@@ -83,6 +78,7 @@ public class AttributePollingMessageSourceTests {
public void increment() {
this.counter.incrementAndGet();
}
}
}

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
<context:mbean-export/>
<context:mbean-server/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export default-domain="#{@domain}" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 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.
@@ -25,30 +25,38 @@ import java.util.Map;
import javax.management.MBeanServer;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.jmx.support.MBeanServerFactoryBean;
/**
* @author Stuart Williams
* @author Artem Bilan
*
*/
public class MBeanTreePollingMessageSourceTests {
private MBeanServer server;
private static MBeanServerFactoryBean factoryBean;
@Before
public void setup() {
MBeanServerFactoryBean factoryBean = new MBeanServerFactoryBean();
private static MBeanServer server;
@BeforeClass
public static void setup() {
factoryBean = new MBeanServerFactoryBean();
factoryBean.setLocateExistingServerIfPossible(true);
factoryBean.afterPropertiesSet();
this.server = factoryBean.getObject();
server = factoryBean.getObject();
}
@AfterClass
public static void tearDown() {
factoryBean.destroy();
}
@Test
public void testDefaultPoll() {
MBeanObjectConverter converter = new DefaultMBeanObjectConverter();
MBeanTreePollingMessageSource source = new MBeanTreePollingMessageSource(converter);
source.setServer(server);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
@@ -29,7 +29,9 @@ import javax.management.Notification;
import javax.management.ObjectName;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
@@ -47,25 +49,31 @@ import org.springframework.messaging.Message;
/**
* @author Mark Fisher
* @author Artem Bilan
*
* @since 2.0
*/
public class NotificationListeningMessageProducerTests {
private volatile MBeanServer server;
private volatile ObjectName objectName;
private static MBeanServerFactoryBean serverFactoryBean;
private final NumberHolder numberHolder = new NumberHolder();
private MBeanServer server;
private ObjectName objectName;
@BeforeClass
public static void setupClass() {
serverFactoryBean = new MBeanServerFactoryBean();
serverFactoryBean.afterPropertiesSet();
}
@Before
public void setup() throws Exception {
MBeanServerFactoryBean serverFactoryBean = new MBeanServerFactoryBean();
serverFactoryBean.setLocateExistingServerIfPossible(true);
serverFactoryBean.afterPropertiesSet();
this.server = serverFactoryBean.getObject();
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetect(false);
exporter.setServer(this.server);
exporter.afterPropertiesSet();
this.objectName = ObjectNameManager.getInstance("si:name=numberHolder");
exporter.registerManagedResource(this.numberHolder, this.objectName);
@@ -76,8 +84,13 @@ public class NotificationListeningMessageProducerTests {
this.server.unregisterMBean(this.objectName);
}
@AfterClass
public static void tearDown() {
serverFactoryBean.destroy();
}
@Test
public void simpleNotification() throws Exception {
public void simpleNotification() {
QueueChannel outputChannel = new QueueChannel();
NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer();
adapter.setServer(this.server);
@@ -98,7 +111,7 @@ public class NotificationListeningMessageProducerTests {
}
@Test
public void notificationWithHandback() throws Exception {
public void notificationWithHandback() {
QueueChannel outputChannel = new QueueChannel();
NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer();
adapter.setServer(this.server);
@@ -122,7 +135,7 @@ public class NotificationListeningMessageProducerTests {
@Test
@SuppressWarnings("serial")
public void notificationWithFilter() throws Exception {
public void notificationWithFilter() {
QueueChannel outputChannel = new QueueChannel();
NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer();
adapter.setServer(this.server);
@@ -170,6 +183,7 @@ public class NotificationListeningMessageProducerTests {
Notification notification = new Notification("testType", this, sequence.getAndIncrement(), message);
this.notificationPublisher.sendNotification(notification);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2018 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.
@@ -29,16 +29,21 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.monitor.IntegrationMBeanExporter;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.support.GenericMessage;
/**
* @author Mark Fisher
* @author Artem Bilan
*
* @since 2.0
*/
public class NotificationPublishingMessageHandlerTests {
@@ -49,14 +54,14 @@ public class NotificationPublishingMessageHandlerTests {
private volatile ObjectName publisherObjectName;
@Before
public void setup() throws Exception {
this.publisherObjectName = ObjectNameManager.getInstance("test:type=publisher");
// deliberately registering two exporters (one SI specific and one generic)
// should not fail INT-1816
context.registerSingleton("exporter", IntegrationMBeanExporter.class);
context.registerSingleton("anotherExporter", MBeanExporter.class);
this.context.registerBean("mbeanServer", MBeanServerFactoryBean.class, MBeanServerFactoryBean::new);
this.context.registerSingleton("exporter", IntegrationMBeanExporter.class,
new MutablePropertyValues()
.add("server", new RuntimeBeanReference("mbeanServer")));
this.context.registerSingleton("anotherExporter", MBeanExporter.class);
RootBeanDefinition publisherDefinition = new RootBeanDefinition(NotificationPublishingMessageHandler.class);
publisherDefinition.getConstructorArgumentValues().addGenericArgumentValue(this.publisherObjectName);
@@ -88,7 +93,7 @@ public class NotificationPublishingMessageHandlerTests {
public static class TestNotificationListener implements NotificationListener {
private final List<Notification> notifications = new ArrayList<Notification>();
private final List<Notification> notifications = new ArrayList<>();
public void handleNotification(Notification notification, Object handback) {
this.notifications.add(notification);
@@ -97,6 +102,7 @@ public class NotificationPublishingMessageHandlerTests {
void clearNotifications() {
this.notifications.clear();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -28,7 +28,9 @@ import java.util.Map;
import javax.management.MBeanServer;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
@@ -42,45 +44,58 @@ import org.springframework.messaging.MessagingException;
/**
* See DynamicRouterTests for additional tests where the MBean is registered by the Spring exporter.
* @see DynamicRouterTests
*
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0
*
* @see DynamicRouterTests
*/
public class OperationInvokingMessageHandlerTests {
private static MBeanServerFactoryBean factoryBean;
private static MBeanServer server;
private final String objectName = "si:name=test";
private volatile MBeanServer server;
@BeforeClass
public static void setupClass() {
factoryBean = new MBeanServerFactoryBean();
factoryBean.afterPropertiesSet();
server = factoryBean.getObject();
}
@AfterClass
public static void tearDown() {
factoryBean.destroy();
}
@Before
public void setup() throws Exception {
MBeanServerFactoryBean factoryBean = new MBeanServerFactoryBean();
factoryBean.setLocateExistingServerIfPossible(true);
factoryBean.afterPropertiesSet();
this.server = factoryBean.getObject();
this.server.registerMBean(new TestOps(), ObjectNameManager.getInstance(this.objectName));
server.registerMBean(new TestOps(), ObjectNameManager.getInstance(this.objectName));
}
@After
public void cleanup() throws Exception {
this.server.unregisterMBean(ObjectNameManager.getInstance(this.objectName));
server.unregisterMBean(ObjectNameManager.getInstance(this.objectName));
}
@Test
public void invocationWithMapPayload() throws Exception {
public void invocationWithMapPayload() {
QueueChannel outputChannel = new QueueChannel();
OperationInvokingMessageHandler handler = new OperationInvokingMessageHandler();
handler.setServer(this.server);
handler.setServer(server);
handler.setObjectName(this.objectName);
handler.setOutputChannel(outputChannel);
handler.setOperationName("x");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
params.put("p1", "foo");
params.put("p2", "bar");
Message<?> message = MessageBuilder.withPayload(params).build();
@@ -91,10 +106,10 @@ public class OperationInvokingMessageHandlerTests {
}
@Test
public void invocationWithPayloadNoReturnValue() throws Exception {
public void invocationWithPayloadNoReturnValue() {
QueueChannel outputChannel = new QueueChannel();
OperationInvokingMessageHandler handler = new OperationInvokingMessageHandler();
handler.setServer(this.server);
handler.setServer(server);
handler.setObjectName(this.objectName);
handler.setOutputChannel(outputChannel);
handler.setOperationName("y");
@@ -105,16 +120,16 @@ public class OperationInvokingMessageHandlerTests {
}
@Test(expected = MessagingException.class)
public void invocationWithMapPayloadNotEnoughParameters() throws Exception {
public void invocationWithMapPayloadNotEnoughParameters() {
QueueChannel outputChannel = new QueueChannel();
OperationInvokingMessageHandler handler = new OperationInvokingMessageHandler();
handler.setServer(this.server);
handler.setServer(server);
handler.setObjectName(this.objectName);
handler.setOutputChannel(outputChannel);
handler.setOperationName("x");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
params.put("p1", "foo");
Message<?> message = MessageBuilder.withPayload(params).build();
handler.handleMessage(message);
@@ -124,16 +139,16 @@ public class OperationInvokingMessageHandlerTests {
}
@Test
public void invocationWithListPayload() throws Exception {
public void invocationWithListPayload() {
QueueChannel outputChannel = new QueueChannel();
OperationInvokingMessageHandler handler = new OperationInvokingMessageHandler();
handler.setServer(this.server);
handler.setServer(server);
handler.setObjectName(this.objectName);
handler.setOutputChannel(outputChannel);
handler.setOperationName("x");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<Object> params = Arrays.asList(new Object[] { "foo", new Integer(123) });
List<Object> params = Arrays.asList(new Object[] { "foo", 123 });
Message<?> message = MessageBuilder.withPayload(params).build();
handler.handleMessage(message);
Message<?> reply = outputChannel.receive(0);
@@ -148,8 +163,8 @@ public class OperationInvokingMessageHandlerTests {
String x(String s, Integer i);
void y(String s);
}
}
public static class TestOps implements TestOpsMBean {
@@ -164,7 +179,9 @@ public class OperationInvokingMessageHandlerTests {
}
@Override
public void y(String s) { }
public void y(String s) {
}
}
}

View File

@@ -1,15 +1,14 @@
<?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:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<beans:bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-server/>
<int-jmx:mbean-export/>
<message-history/>

View File

@@ -1,15 +1,14 @@
<?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
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<beans:bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-server/>
<int-jmx:mbean-export default-domain="test2"/>
<service-activator id="optimizedRefReplyingHandlerTestService1"

View File

@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<context:mbean-server />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export default-domain="update.mapping.domain"/>

View File

@@ -13,8 +13,9 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-export/>
<context:mbean-server/>
<context:mbean-export server="mbeanServer"/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<si:channel id="channel">
<si:queue/>

View File

@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
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">
<context:mbean-server id="mbs"/>
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<si:channel id="testChannel"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@@ -44,14 +43,12 @@ public class ControlBusParserTests {
private ApplicationContext context;
@Test
public void testControlMessageToChannelMetrics() throws InterruptedException {
public void testControlMessageToChannelMetrics() {
MessageChannel control = this.context.getBean("controlChannel", MessageChannel.class);
MessagingTemplate messagingTemplate = new MessagingTemplate();
Object value = messagingTemplate.convertSendAndReceive(control,
"@integrationMbeanExporter.getChannelSendRate('testChannel').count", Object.class);
assertEquals(0, value);
MBeanExporter exporter = this.context.getBean(MBeanExporter.class);
exporter.destroy();
}
}

View File

@@ -11,7 +11,7 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:mbean-server id="mbs"/>
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.custom"/>

View File

@@ -10,15 +10,16 @@
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx">
<context:mbean-export />
<context:mbean-server />
<context:mbean-export server="mbeanServer"/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:operation-invoking-channel-adapter
id="controlChannel"
object-name="org.springframework.integration.jmx.config:type=SimpleDynamicRouter,name=dynamicRouter"
operation-name="addChannelMapping" />
<int:router input-channel="routingChannel" ref="dynamicRouter" method="route"
<int:router input-channel="routingChannel" ref="dynamicRouter" method="route"
default-output-channel="errorChannel"/>
<bean id="dynamicRouter"

View File

@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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">
@@ -11,9 +10,9 @@
<constructor-arg value="dummy" />
</bean>
<context:mbean-server id="mbs" />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.MBeanAutoDetectFirst" />
<context:mbean-export server="mbeanServer" default-domain="test.MBeanAutoDetectFirst" />
<bean id="router" class="org.springframework.integration.config.RouterFactoryBean">
<property name="expressionString" value="payload instanceof String ? 'stringChannel' : 'intChannel'" />

View File

@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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 id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.MBeanAutoDetectFirst" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -24,13 +24,14 @@ import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Dave Syer
* @author Artem Bilan
*
* @since 2.0
*/
public class MBeanAutoDetectTests {
@@ -57,7 +58,6 @@ public class MBeanAutoDetectTests {
}
@Test
@Ignore // Fails because the MBeanExporter is created before the router
public void testRouterMBeanExistsWhenDefinedSecond() throws Exception {
context = new ClassPathXmlApplicationContext("MBeanAutoDetectSecondTests-context.xml", getClass());
server = context.getBean(MBeanServer.class);

View File

@@ -14,16 +14,16 @@
<jmx:mbean-export id="mbeanExporter" server="mbs" default-domain="test.MBeanExporterName"/>
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.MBeanExporterName"/>
<int:channel id="testChannel" />
<int:service-activator id="service" input-channel="testChannel" method="get">
<bean class="org.springframework.integration.jmx.config.MBeanExporterNameTests$Source"/>
</int:service-activator>
<int:logging-channel-adapter id="logger" channel="testChannel"/>
</beans>

View File

@@ -1,22 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:util="http://www.springframework.org/schema/util"
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/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:mbean-server id="mbs"/>
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<si:channel id="testChannel"/>
<jmx:mbean-export id="integratioMbeanExporter"
server="mbs"
<jmx:mbean-export id="integratioMbeanExporter"
server="mbs"
default-domain="tests.MBeanExpoerterParser"
object-name-static-properties="appProperties"
object-naming-strategy="keyNamer"
@@ -29,7 +27,7 @@
counts-enabled-patterns="foo, !baz, ba*"
stats-enabled-patterns="fiz, buz"
metrics-factory="mf" />
<util:properties id="appProperties">
<prop key="foo">foo</prop>
<prop key="bar">bar</prop>

View File

@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jmx
@@ -17,16 +15,16 @@
<bean id="namer" class="org.springframework.integration.jmx.config.MBeanRegistrationCustomNamingTests$Namer" />
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int:channel id="testChannel" />
<int:service-activator id="service" input-channel="testChannel" method="get">
<bean class="org.springframework.integration.jmx.config.MBeanRegistrationCustomNamingTests$Source"/>
</int:service-activator>
<int:logging-channel-adapter id="logger" channel="testChannel"/>
<int:chain id="chain" input-channel="chainin">
<int:transformer id="t1" expression="'foo'"/>
<int:filter id="f1" expression="true"/>

View File

@@ -14,7 +14,7 @@
<jmx:mbean-export id="integrationMbeanExporter" server="mbs" default-domain="test.MBeanRegistration"/>
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.MBeanRegistration"/>

View File

@@ -13,8 +13,11 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-export/>
<context:mbean-server/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true"/>
</bean>
<context:mbean-export server="mbeanServer"/>
<jmx:tree-polling-channel-adapter id="adapter-default"
channel="channel1"
@@ -30,7 +33,7 @@
channel="channel2"
auto-startup="false">
<si:poller max-messages-per-poll="1" fixed-rate="5000"/>
<bean class="org.springframework.integration.jmx.DefaultMBeanObjectConverter"></bean>
<bean class="org.springframework.integration.jmx.DefaultMBeanObjectConverter"/>
</jmx:tree-polling-channel-adapter>
<si:channel id="channel2">

View File

@@ -10,7 +10,7 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-server id="mbs"/>
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.MessageStore"/>

View File

@@ -1,10 +1,9 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:si="http://www.springframework.org/schema/integration"
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
xmlns:si="http://www.springframework.org/schema/integration"
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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<si:channel id="echos" />
<si:publish-subscribe-channel id="hyphens" />
@@ -15,7 +14,8 @@
<si:mapping value="underscore" channel="underscores" />
</si:header-value-router>
<context:mbean-server id="mbeanServer" />
<int-jmx:mbean-export server="mbeanServer" default-domain="test.MethodInvoker" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
</beans>
<int-jmx:mbean-export server="mbs" default-domain="test.MethodInvoker" />
</beans>

View File

@@ -11,8 +11,10 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:mbean-export/>
<context:mbean-server/>
<context:mbean-export server="mbeanServer"/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<si:channel id="channel">
<si:queue/>

View File

@@ -13,7 +13,7 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-server/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export default-domain="#{T(java.util.UUID).randomUUID().toString()}"/>

View File

@@ -13,8 +13,9 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-export/>
<context:mbean-server/>
<context:mbean-export server="mbeanServer"/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<jmx:operation-invoking-channel-adapter id="input"
object-name="org.springframework.integration.jmx.config:type=TestBean,name=testBeanAdapter"

View File

@@ -13,8 +13,9 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-export/>
<context:mbean-server/>
<context:mbean-export server="mbeanServer"/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<si:channel id="withReplyChannel">
<si:queue/>

View File

@@ -12,7 +12,9 @@
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<!--<property name="locateExistingServerIfPossible" value="true"/>-->
</bean>
<context:mbean-export server="mbs" default-domain="test.PollingAdapterMBean"/>

View File

@@ -1,28 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
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">
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int:channel id="testChannel">
<int:priority-queue/>
</int:channel>
<int:service-activator id="service" input-channel="testChannel" method="get">
<bean class="org.springframework.integration.jmx.config.PriorityChannelTests$Source"/>
<int:poller fixed-rate="100"/>
</int:service-activator>
<jmx:mbean-export id="integrationMbeanExporter" server="mbs" default-domain="test.PriorityChannel"/>
</beans>

View File

@@ -20,7 +20,7 @@
<int:router id="ptRouter" input-channel="testChannel" expression="payload instanceof String ? 'stringChannel' : 'intChannel'" />
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.RouterMBean" />

View File

@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jmx
@@ -17,7 +15,7 @@
<int:router id="ptRouter" input-channel="testChannel" expression="payload instanceof String ? 'stringChannel' : 'intChannel'"/>
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<!-- Same as RouterMBeanTests-context.xml but no Core MBeanExporter -->
<jmx:mbean-export server="mbs" default-domain="test.RouterMBean" />

View File

@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jmx
@@ -20,6 +18,6 @@
<!-- Same as RouterMBeanTests-context.xml but switched order of MBeanExporters -->
<jmx:mbean-export server="mbs" default-domain="test.RouterMBean" />
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
</beans>

View File

@@ -17,7 +17,7 @@
<int:router id="ptRouter" input-channel="testChannel" expression="payload instanceof String ? 'stringChannel' : 'intChannel'"/>
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.RouterMBean" />

View File

@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="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
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/integration/spring-integration.xsd">
<int:channel id="testChannel" />
<int:channel id="intChannel" />
@@ -17,7 +15,7 @@
<int:router id="ptRouter" input-channel="testChannel" expression="payload instanceof String ? 'stringChannel' : 'intChannel'"/>
<context:mbean-server id="mbs" />
<bean id="mbs" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export server="mbs" default-domain="test.RouterMBeanVanilla" />

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2018 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.jmx.configuration;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.context.IntegrationFlowContext;
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.1
*
*/
@SpringJUnitConfig
@DirtiesContext
public class DslMBeanTests {
@Autowired
private MBeanServer server;
@Test
void testRuntimeBeanRegistration(@Autowired IntegrationFlowContext context) throws Exception {
Set<ObjectName> query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null);
assertThat(query).hasSize(3);
query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null);
assertThat(query).hasSize(2);
query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null);
assertThat(query).hasSize(0);
IntegrationFlow dynamicFlow =
IntegrationFlows.from(() -> "foo", e -> e.poller(p -> p.fixedDelay(1000)))
.channel("channelTwo")
.nullChannel();
IntegrationFlowContext.IntegrationFlowRegistration registration =
context.registration(dynamicFlow)
.id("dynamic")
.register();
query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null);
assertThat(query).hasSize(4);
query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null);
assertThat(query).hasSize(3);
query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null);
assertThat(query).hasSize(1);
registration.destroy();
query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null);
assertThat(query).hasSize(3);
query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null);
assertThat(query).hasSize(2);
query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null);
assertThat(query).hasSize(0);
}
@Configuration
@EnableIntegrationMBeanExport(defaultDomain = "dsl", server = "mbeanServer")
@EnableIntegration
public static class Config {
@Bean
public static MBeanServerFactoryBean mbeanServer() {
return new MBeanServerFactoryBean();
}
@Bean
public IntegrationFlow staticFlow() {
return IntegrationFlows.from("channelOne")
.nullChannel();
}
}
}

View File

@@ -133,9 +133,7 @@ public class EnableMBeanExportTests {
@Bean
public MBeanServerFactoryBean mbeanServer() {
MBeanServerFactoryBean mBeanServerFactoryBean = new MBeanServerFactoryBean();
mBeanServerFactoryBean.setLocateExistingServerIfPossible(true);
return mBeanServerFactoryBean;
return new MBeanServerFactoryBean();
}
@Bean

View File

@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
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">
<context:mbean-server />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export />

View File

@@ -10,8 +10,7 @@
class="org.springframework.integration.monitor.IntegrationMBeanExporter"
p:server-ref="mbeanServer" p:defaultDomain="forum" />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"
p:locateExistingServerIfPossible="true" />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int:chain input-channel="inputChannel">
<int:transformer>

View File

@@ -18,9 +18,7 @@
<property name="defaultDomain" value="test.ChannelIntegrationTests"/>
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int:inbound-channel-adapter id="source" channel="sourceChannel" expression="''">
<int:poller fixed-delay="10" />

View File

@@ -242,9 +242,7 @@ public class IdempotentReceiverIntegrationTests {
@Bean
public static MBeanServerFactoryBean mBeanServer() {
MBeanServerFactoryBean mBeanServerFactoryBean = new MBeanServerFactoryBean();
mBeanServerFactoryBean.setLocateExistingServerIfPossible(true);
return mBeanServerFactoryBean;
return new MBeanServerFactoryBean();
}
@Bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016 the original author or authors.
* Copyright 2009-2018 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.
@@ -39,6 +39,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.QueueChannel;
@@ -51,11 +52,18 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.util.Assert;
/**
* @author Dave Syer
* @author Gary Russell
* @author Artem Bilan
*
*/
public class MBeanExporterIntegrationTests {
private IntegrationMBeanExporter messageChannelsMonitor;
@@ -70,21 +78,21 @@ public class MBeanExporterIntegrationTests {
}
@Test
public void testCircularReferenceNoChannel() throws Exception {
public void testCircularReferenceNoChannel() {
context = new GenericXmlApplicationContext(getClass(), "oref-nonchannel.xml");
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
}
@Test
public void testCircularReferenceNoChannelInFactoryBean() throws Exception {
public void testCircularReferenceNoChannelInFactoryBean() {
context = new GenericXmlApplicationContext(getClass(), "oref-factory-nonchannel.xml");
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
}
@Test
public void testCircularReferenceWithChannel() throws Exception {
public void testCircularReferenceWithChannel() {
context = new GenericXmlApplicationContext(getClass(), "oref-channel.xml");
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
@@ -98,11 +106,13 @@ public class MBeanExporterIntegrationTests {
assertTrue(Arrays.asList(messageChannelsMonitor.getChannelNames()).contains("anonymous"));
MBeanServer server = context.getBean(MBeanServer.class);
assertEquals(1, server.queryNames(ObjectName.getInstance("com.foo:*"), null).size());
assertEquals(1, server.queryNames(ObjectName.getInstance("org.springframework.integration:name=anonymous,*"), null).size());
assertEquals(1,
server.queryNames(ObjectName.getInstance("org.springframework.integration:name=anonymous,*"), null)
.size());
}
@Test
public void testCircularReferenceWithChannelInFactoryBeanAutodetected() throws Exception {
public void testCircularReferenceWithChannelInFactoryBeanAutodetected() {
context = new GenericXmlApplicationContext(getClass(), "oref-factory-channel-autodetect.xml");
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
@@ -114,7 +124,9 @@ public class MBeanExporterIntegrationTests {
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
Set<ObjectName> names =
server.queryNames(
ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
assertEquals(2, names.size());
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=explicit,*"), null);
assertEquals(1, names.size());
@@ -129,7 +141,7 @@ public class MBeanExporterIntegrationTests {
// Lifecycle method name
assertEquals("start", startName);
assertTrue((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
messageChannelsMonitor.stopActiveComponents(3000);
messageChannelsMonitor.stopActiveComponents(100);
assertFalse((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
ActiveChannel activeChannel = context.getBean("activeChannel", ActiveChannel.class);
assertTrue(activeChannel.isStopCalled());
@@ -144,7 +156,7 @@ public class MBeanExporterIntegrationTests {
QueueChannel input2 = (QueueChannel) extractTarget(context.getBean("input2"));
input.purge(null);
input2.purge(null);
input.send(new GenericMessage<String>("foo"));
input.send(new GenericMessage<>("foo"));
assertNotNull(input2.receive(10000));
}
@@ -185,7 +197,9 @@ public class MBeanExporterIntegrationTests {
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
Set<ObjectName> 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());
@@ -204,7 +218,8 @@ public class MBeanExporterIntegrationTests {
context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
server = context.getBean(MBeanServer.class);
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
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());
@@ -216,10 +231,13 @@ public class MBeanExporterIntegrationTests {
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=MessageChannel,*"), null);
Set<ObjectName> names =
server.queryNames(
ObjectName.getInstance("org.springframework.integration:type=MessageChannel,*"), null);
// Only one registered (out of >2 available)
assertEquals(1, names.size());
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=MessageHandler,*"), null);
names = server.queryNames(
ObjectName.getInstance("org.springframework.integration:type=MessageHandler,*"), null);
assertEquals(0, names.size());
}
@@ -229,7 +247,9 @@ public class MBeanExporterIntegrationTests {
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
Set<ObjectName> names =
server.queryNames(
ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
assertEquals(2, names.size());
}
@@ -247,12 +267,26 @@ public class MBeanExporterIntegrationTests {
@EnableIntegrationMBeanExport(defaultDomain = "config1")
public static class Config1 {
@Bean
public MBeanServerFactoryBean fb() {
MBeanServerFactoryBean fb = new MBeanServerFactoryBean();
fb.setLocateExistingServerIfPossible(true);
return fb;
}
}
@EnableIntegration
@EnableIntegrationMBeanExport(defaultDomain = "config2")
public static class Config2 {
@Bean
public MBeanServerFactoryBean fb() {
MBeanServerFactoryBean fb = new MBeanServerFactoryBean();
fb.setLocateExistingServerIfPossible(true);
return fb;
}
}
public static class BogusEndpoint extends AbstractEndpoint {
@@ -313,7 +347,7 @@ public class MBeanExporterIntegrationTests {
}
@Override
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
Assert.state(date != null, "A date must be provided");
}
@@ -322,6 +356,7 @@ public class MBeanExporterIntegrationTests {
public static class MetricFactoryBean implements FactoryBean<Metric> {
private MessageChannel channel;
private final Metric date = new Metric();
public void setChannel(MessageChannel channel) {
@@ -329,7 +364,7 @@ public class MBeanExporterIntegrationTests {
}
@Override
public Metric getObject() throws Exception {
public Metric getObject() {
Assert.state(channel != null, "A channel must be provided");
return date;
}
@@ -367,11 +402,15 @@ public class MBeanExporterIntegrationTests {
}
public interface Service {
String execute() throws Exception;
int getCounter();
}
public static class SimpleService implements Service {
private int counter;
@Override
@@ -385,10 +424,13 @@ public class MBeanExporterIntegrationTests {
public int getCounter() {
return counter;
}
}
public interface ActiveChannel {
boolean isStopCalled();
}
public static class ActiveChannelImpl extends AbstractMessageChannel implements Lifecycle, ActiveChannel {
@@ -418,6 +460,7 @@ public class MBeanExporterIntegrationTests {
public boolean isStopCalled() {
return this.stopCalled;
}
}
public static class OtherActiveComponent extends MessageProducerSupport
@@ -446,9 +489,11 @@ public class MBeanExporterIntegrationTests {
this.afterCalled = true;
return 0;
}
}
public static class AMessageProducer extends MessageProducerSupport {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2017 the original author or authors.
* Copyright 2011-2018 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.
@@ -18,22 +18,27 @@ package org.springframework.integration.monitor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.NameMatchMethodPointcutAdvisor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.util.ClassUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Tareq Abedrabbo
@@ -43,75 +48,62 @@ import org.springframework.util.ClassUtils;
*
* @since 2.0.4
*/
@SpringJUnitConfig
@DirtiesContext
public class MessageMetricsAdviceTests {
private GenericApplicationContext applicationContext;
private BeanFactory beanFactory;
private ConfigurableListableBeanFactory beanFactory;
private BeanDefinitionRegistry beanDefinitionRegistry;
private IntegrationMBeanExporter mBeanExporter;
private MessageHandler handler;
private MessageChannel channel;
@Before
public void setUp() throws Exception {
this.applicationContext = TestUtils.createTestApplicationContext();
this.beanFactory = this.applicationContext.getBeanFactory();
this.channel = new NullChannel();
this.mBeanExporter = new IntegrationMBeanExporter();
this.mBeanExporter.setApplicationContext(this.applicationContext);
this.mBeanExporter.setBeanFactory(this.beanFactory);
this.mBeanExporter.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
this.mBeanExporter.afterPropertiesSet();
this.handler = new DummyHandler();
applicationContext.refresh();
}
@After
public void tearDown() throws Exception {
if (this.applicationContext != null) {
this.applicationContext.close();
}
@Autowired
MessageMetricsAdviceTests(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
this.beanDefinitionRegistry = (BeanDefinitionRegistry) beanFactory;
}
@Test
public void exportAdvisedHandler() throws Exception {
void exportAdvisedHandler() {
DummyInterceptor interceptor = new DummyInterceptor();
NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(interceptor);
advisor.addMethodName("handleMessage");
ProxyFactory factory = new ProxyFactory(this.handler);
MessageHandler handler = new DummyHandler();
ProxyFactory factory = new ProxyFactory(handler);
factory.addAdvisor(advisor);
MessageHandler advised = (MessageHandler) factory.getProxy();
this.beanFactory.registerSingleton("test", advised);
this.beanFactory.initializeBean(advised, "test");
this.beanDefinitionRegistry.registerBeanDefinition("test",
BeanDefinitionBuilder.genericBeanDefinition(MessageHandler.class, () -> advised)
.getRawBeanDefinition());
mBeanExporter.afterSingletonsInstantiated();
MessageHandler exported = this.beanFactory.getBean("test", MessageHandler.class);
exported.handleMessage(MessageBuilder.withPayload("test").build());
this.beanDefinitionRegistry.removeBeanDefinition("test");
}
@Test
public void exportAdvisedChannel() throws Exception {
void exportAdvisedChannel() {
DummyInterceptor interceptor = new DummyInterceptor();
NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(interceptor);
advisor.addMethodName("send");
MessageChannel channel = new NullChannel();
ProxyFactory factory = new ProxyFactory(channel);
factory.addAdvisor(advisor);
MessageChannel advised = (MessageChannel) factory.getProxy();
this.beanFactory.registerSingleton("test", advised);
this.beanFactory.initializeBean(advised, "test");
this.beanDefinitionRegistry.registerBeanDefinition("test",
BeanDefinitionBuilder.genericBeanDefinition(MessageChannel.class, () -> advised)
.getRawBeanDefinition());
mBeanExporter.afterSingletonsInstantiated();
MessageChannel exported = this.beanFactory.getBean("test", MessageChannel.class);
exported.send(MessageBuilder.withPayload("test").build());
this.beanDefinitionRegistry.removeBeanDefinition("test");
}
private static class DummyHandler implements MessageHandler {
@@ -151,4 +143,16 @@ public class MessageMetricsAdviceTests {
}
@Configuration
@EnableIntegrationMBeanExport
@EnableIntegration
public static class Config {
@Bean
public MBeanServerFactoryBean fb() {
return new MBeanServerFactoryBean();
}
}
}

View File

@@ -73,15 +73,13 @@ public class MessageSourceTests {
}
@Configuration
@EnableIntegrationMBeanExport(defaultDomain = "foo")
@EnableIntegrationMBeanExport(server = "mbeanServer", defaultDomain = "foo")
@EnableIntegration
public static class Config {
@Bean
public MBeanServerFactoryBean fb() {
MBeanServerFactoryBean fb = new MBeanServerFactoryBean();
fb.setLocateExistingServerIfPossible(true);
return fb;
public MBeanServerFactoryBean mbeanServer() {
return new MBeanServerFactoryBean();
}
@Bean

View File

@@ -66,7 +66,7 @@ public class MessagingGatewaySupportRegistrationTests {
@Configuration
@EnableIntegration
@EnableIntegrationMBeanExport
@EnableIntegrationMBeanExport(server = "mbeanServer")
public static class ContextConfiguration {
@Bean
@@ -100,10 +100,8 @@ public class MessagingGatewaySupportRegistrationTests {
}
@Bean
public static MBeanServerFactoryBean server() {
MBeanServerFactoryBean fb = new MBeanServerFactoryBean();
fb.setLocateExistingServerIfPossible(true);
return fb;
public static MBeanServerFactoryBean mbeanServer() {
return new MBeanServerFactoryBean();
}
}

View File

@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="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
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
<context:mbean-server />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export />

View File

@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
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/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:mbean-server />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export default-domain="foo" />
<bean id="test" class="org.springframework.integration.monitor.RemoteMBeanServerTests$Tester" />

View File

@@ -128,9 +128,7 @@ public class ScatterGatherHandlerIntegrationTests {
@Bean
public static MBeanServerFactoryBean mBeanServer() {
MBeanServerFactoryBean mBeanServerFactoryBean = new MBeanServerFactoryBean();
mBeanServerFactoryBean.setLocateExistingServerIfPossible(true);
return mBeanServerFactoryBean;
return new MBeanServerFactoryBean();
}
@Bean

View File

@@ -1,20 +1,18 @@
<?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:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
<context:mbean-server/>
<beans:bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export default-domain="transformers" />
<channel id="input"/>
<recipient-list-router input-channel="input"> <!-- INT-3565 ClassCastException with DEBUG -->
<recipient channel="input1" selector-expression="true" />
</recipient-list-router>
@@ -40,7 +38,7 @@
<beans:bean class="org.springframework.integration.monitor.TransformerContextTests$FooAdvice" />
</request-handler-advice-chain>
</transformer>
<beans:bean id="trans" class="org.springframework.integration.monitor.TransformerContextTests$Bar"/>
<service-activator input-channel="service" method="qux">

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
@@ -19,9 +19,10 @@ package org.springframework.integration.monitor;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.integration.support.MessageBuilder;
@@ -29,45 +30,49 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class TransformerContextTests {
private static volatile int adviceCalled;
private static volatile int bazCalled;
@Autowired
private ApplicationContext context;
@Test
public void methodInvokingTransformer() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"transformerContextTests.xml", this.getClass());
MessageChannel input = context.getBean("input", MessageChannel.class);
PollableChannel output = context.getBean("output", PollableChannel.class);
input.send(new GenericMessage<String>("foo"));
MessageChannel input = this.context.getBean("input", MessageChannel.class);
PollableChannel output = this.context.getBean("output", PollableChannel.class);
input.send(new GenericMessage<>("foo"));
Message<?> reply = output.receive(0);
assertEquals("FOO", reply.getPayload());
assertEquals(1, adviceCalled);
input = context.getBean("direct", MessageChannel.class);
input.send(new GenericMessage<String>("foo"));
input = this.context.getBean("direct", MessageChannel.class);
input.send(new GenericMessage<>("foo"));
reply = output.receive(0);
assertEquals("FOO", reply.getPayload());
input = context.getBean("directRef", MessageChannel.class);
input.send(new GenericMessage<String>("foo"));
input = this.context.getBean("directRef", MessageChannel.class);
input.send(new GenericMessage<>("foo"));
reply = output.receive(0);
assertEquals("FOO", reply.getPayload());
assertEquals(2, adviceCalled);
input = context.getBean("service", MessageChannel.class);
input.send(new GenericMessage<String>("foo"));
input = this.context.getBean("service", MessageChannel.class);
input.send(new GenericMessage<>("foo"));
assertEquals(1, bazCalled);
assertEquals(3, adviceCalled);
context.close();
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -1,16 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.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">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="integrationExecutions" class="org.springframework.integration.monitor.IntegrationMBeanExporter">
<property name="server" ref="mbeanServer" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="false" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
</beans>

View File

@@ -9,9 +9,7 @@
<property name="server" ref="mbeanServer" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="false" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<bean id="parent" class="org.springframework.integration.monitor.MBeanExporterIntegrationTests$BogusEndpoint" />

View File

@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.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">
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="integrationExecutions" class="org.springframework.integration.monitor.IntegrationMBeanExporter">
<property name="server" ref="mbeanServer" />
<property name="componentNamePatterns" value="input" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="false" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int:channel id="input">
<int:queue />

View File

@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:inbound-channel-adapter channel="toControlBus" auto-startup="false"
expression="@integrationMbeanExporter.stopActiveComponents(1000)" />
expression="@integrationMbeanExporter.stopActiveComponents(100)" />
<int:channel id="toControlBus" />
@@ -21,9 +19,9 @@
<int-jmx:mbean-export id="integrationMbeanExporter"
default-domain="self-destruct" />
<context:mbean-server />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int:poller default="true" fixed-delay="500" />
<int:poller default="true" fixed-delay="100" />
<bean id="activeChannel" class="org.springframework.integration.monitor.MBeanExporterIntegrationTests$ActiveChannelImpl" />

View File

@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:int="http://www.springframework.org/schema/integration"
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
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.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 />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<context:mbean-export />
<int:recipient-list-router input-channel="command"

View File

@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectInstance;
import org.junit.Test;
@@ -44,9 +43,7 @@ public class Int2307Tests {
@Test
public void testInt2307_DefaultMBeanExporter() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("single-config.xml", getClass());
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
assertEquals(1, servers.size());
MBeanServer server = servers.get(0);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectInstance> mbeans = server.queryMBeans(null, null);
int bits = 0;
int count = 0;

View File

@@ -1,16 +1,14 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xmlns:util="http://www.springframework.org/schema/util"
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/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:mbean-server/>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export
default-domain="test.domain"

View File

@@ -10,7 +10,7 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:mbean-server />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
<int-jmx:mbean-export
default-domain="test.domain"