You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/10/26 12:48:48 UTC

[GitHub] [dubbo] kylixs commented on a change in pull request #9129: [3.0] Improve resource cleaning

kylixs commented on a change in pull request #9129:
URL: https://github.com/apache/dubbo/pull/9129#discussion_r736501370



##########
File path: dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboSpringInitializer.java
##########
@@ -54,6 +64,42 @@ public static void initialize(BeanDefinitionRegistry registry) {
         initContext(context, registry, beanFactory);
     }
 
+    public static boolean remove(BeanDefinitionRegistry registry) {
+        return contextMap.remove(registry) != null;
+    }
+
+    public static boolean remove(ApplicationContext springContext) {
+        List<BeanDefinitionRegistry> removingKeys = new ArrayList<>();
+        for (Map.Entry<BeanDefinitionRegistry, DubboSpringInitContext> entry : contextMap.entrySet()) {
+            DubboSpringInitContext initContext = entry.getValue();
+            if (initContext.getApplicationContext() == springContext ||
+                initContext.getBeanFactory() == springContext.getAutowireCapableBeanFactory() ||
+                initContext.getRegistry() == springContext.getAutowireCapableBeanFactory()
+            ) {
+                removingKeys.add(entry.getKey());
+            }
+        }
+        for (BeanDefinitionRegistry key : removingKeys) {
+            DubboSpringInitContext context = contextMap.remove(key);
+            logger.info("Unbind dubbo module " + getModelName(context.getModuleModel()) + " from spring container: " +
+                ObjectUtils.identityToString(key));
+        }
+        return contextMap.keySet().removeAll(removingKeys);

Review comment:
       Fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org