openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1723999 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/WebBeansContext.java container/BeanManagerImpl.java
Date Mon, 11 Jan 2016 10:43:13 GMT
Author: struberg
Date: Mon Jan 11 10:43:13 2016
New Revision: 1723999

URL: http://svn.apache.org/viewvc?rev=1723999&view=rev
Log:
OWB-1108 destroy all SPI servicec which implement the Closeable interface

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1723999&r1=1723998&r2=1723999&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Mon Jan 11 10:43:13 2016
@@ -18,12 +18,17 @@
  */
 package org.apache.webbeans.config;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.webbeans.annotation.AnnotationManager;
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -38,6 +43,7 @@ import org.apache.webbeans.inject.impl.I
 import org.apache.webbeans.intercept.InterceptorResolutionService;
 import org.apache.webbeans.intercept.InterceptorUtil;
 import org.apache.webbeans.intercept.InterceptorsManager;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.plugins.PluginLoader;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.portable.events.ExtensionLoader;
@@ -64,6 +70,8 @@ import org.apache.webbeans.util.WebBeans
  */
 public class WebBeansContext
 {
+    private static final Logger logger = WebBeansLoggerFacade.getLogger(WebBeansContext.class);
+
     private final Map<Class<?>, Object> managerMap = new HashMap<Class<?>,
Object>();
 
     private final Map<Class<?>, Object> serviceMap = new HashMap<Class<?>,
Object>();
@@ -446,9 +454,35 @@ public class WebBeansContext
         }
     }
 
+    /**
+     * Clear and destroy the whole WebBeansContext.
+     * This will also properly destroy all SPI services
+     */
     public void clear()
     {
+        destroyServices(managerMap.values());
+        destroyServices(serviceMap.values());
+
         managerMap.clear();
+        serviceMap.clear();
+    }
+
+    private void destroyServices(Collection<Object> services)
+    {
+        for (Object spiService : services)
+        {
+            if (spiService instanceof Closeable)
+            {
+                try
+                {
+                    ((Closeable) spiService).close();
+                }
+                catch (IOException e)
+                {
+                    logger.log(Level.SEVERE, "Error while destroying SPI service " + spiService.getClass().getName(),
e);
+                }
+            }
+        }
     }
 
     public LoaderService getLoaderService()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1723999&r1=1723998&r2=1723999&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Mon Jan 11 10:43:13 2016
@@ -1413,6 +1413,9 @@ public class BeanManagerImpl implements
         passivationBeans.clear();
         webBeansContext.getInterceptorsManager().clear();
         webBeansContext.getDecoratorsManager().clear();
+
+        // finally destroy all SPI services
+        webBeansContext.clear();
     }
 
     public void clearCacheProxies()



Mime
View raw message