Skip to content

Commit e3ce37c

Browse files
artembilangaryrussell
authored andcommitted
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>`
1 parent 40ba72b commit e3ce37c

File tree

62 files changed

+766
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+766
-498
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void afterPropertiesSet() throws Exception {
145145
}
146146

147147
@Override
148-
public SourcePollingChannelAdapter getObject() throws Exception {
148+
public SourcePollingChannelAdapter getObject() {
149149
if (this.adapter == null) {
150150
initializeAdapter();
151151
}
@@ -169,15 +169,18 @@ private void initializeAdapter() {
169169
}
170170
Assert.notNull(this.source, "source is required");
171171

172+
SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
173+
spca.setSource(this.source);
174+
172175
if (StringUtils.hasText(this.outputChannelName)) {
173176
Assert.isNull(this.outputChannel, "'outputChannelName' and 'outputChannel' are mutually exclusive.");
174-
this.outputChannel = this.channelResolver.resolveDestination(this.outputChannelName);
177+
spca.setOutputChannelName(this.outputChannelName);
178+
}
179+
else {
180+
Assert.notNull(this.outputChannel, "outputChannel is required");
181+
spca.setOutputChannel(this.outputChannel);
175182
}
176183

177-
Assert.notNull(this.outputChannel, "outputChannel is required");
178-
SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
179-
spca.setSource(this.source);
180-
spca.setOutputChannel(this.outputChannel);
181184
if (this.pollerMetadata == null) {
182185
this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
183186
Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '"

spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private Object registerBean(Object bean, String beanName, String parentName) {
134134
BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) bean.getClass(), () -> bean)
135135
.getRawBeanDefinition();
136136

137-
((BeanDefinitionRegistry) this.beanFactory).registerBeanDefinition(beanName, beanDefinition);
137+
this.beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition);
138138

139139
if (parentName != null) {
140140
this.beanFactory.registerDependentBean(parentName, beanName);

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcJmxManagedBeanTests-context.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
1010
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
1111

12-
<context:mbean-server />
13-
<context:mbean-export default-domain="org.springframework.integration.jdbc.test" />
12+
<context:mbean-server id="mbeanServer"/>
13+
14+
<context:mbean-export server="mbeanServer" default-domain="org.springframework.integration.jdbc.test" />
1415

1516
<import resource="classpath:derby-stored-procedures-setup-context.xml"/>
1617

0 commit comments

Comments
 (0)