GH-3425: Remove mngmt gauges from CtxClosedEvent
Fixes https://github.com/spring-projects/spring-integration/issues/3425 It turns out that `IntegrationManagementConfigurer.destroy()` is still too late to remove `gauges` and Micrometer tries to gather them on application context close, when many beans are already destroyed * Catch `ContextClosedEvent` in the `IntegrationManagementConfigurer` and removed `gauges` from there * Remove `destroy()` impl since it is out of use already: the `IntegrationManagementConfigurer` is not supposed to be in the target application directly, so it looks safe to remove the `DisposableBean` altogether **Cherry-pick to `5.3.x` & `5.2.x`** # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java
This commit is contained in:
@@ -28,11 +28,12 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
import org.springframework.beans.factory.BeanNameAware;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
|
||||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||||
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
|
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.event.ContextClosedEvent;
|
||||||
import org.springframework.integration.core.MessageSource;
|
import org.springframework.integration.core.MessageSource;
|
||||||
import org.springframework.integration.support.management.AbstractMessageChannelMetrics;
|
import org.springframework.integration.support.management.AbstractMessageChannelMetrics;
|
||||||
import org.springframework.integration.support.management.AbstractMessageHandlerMetrics;
|
import org.springframework.integration.support.management.AbstractMessageHandlerMetrics;
|
||||||
@@ -64,7 +65,7 @@ import org.springframework.util.StringUtils;
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class IntegrationManagementConfigurer
|
public class IntegrationManagementConfigurer
|
||||||
implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware,
|
implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware,
|
||||||
DestructionAwareBeanPostProcessor, DisposableBean {
|
DestructionAwareBeanPostProcessor, ApplicationListener<ContextClosedEvent> {
|
||||||
|
|
||||||
private static final Log LOGGER = LogFactory.getLog(IntegrationManagementConfigurer.class);
|
private static final Log LOGGER = LogFactory.getLog(IntegrationManagementConfigurer.class);
|
||||||
|
|
||||||
@@ -464,6 +465,13 @@ public class IntegrationManagementConfigurer
|
|||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void onApplicationEvent(ContextClosedEvent event) {
|
||||||
|
if (event.getApplicationContext().equals(this.applicationContext)) {
|
||||||
|
this.gauges.forEach(MeterFacade::remove);
|
||||||
|
this.gauges.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String[] getChannelNames() {
|
public String[] getChannelNames() {
|
||||||
return this.channelsByName.keySet().toArray(new String[0]);
|
return this.channelsByName.keySet().toArray(new String[0]);
|
||||||
}
|
}
|
||||||
@@ -514,10 +522,4 @@ public class IntegrationManagementConfigurer
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
this.gauges.forEach(MeterFacade::remove);
|
|
||||||
this.gauges.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user