You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2015/05/26 00:28:16 UTC

svn commit: r1681661 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/context/ webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/ webbeans-web/src/main/java/org/apache/webbeans/web/context/

Author: struberg
Date: Mon May 25 22:28:16 2015
New Revision: 1681661

URL: http://svn.apache.org/r1681661
Log:
OWB-1061 mark ApplicationContext as already destroyed

We cannot immediately kill out the whole ApplicationContext and not even set it to inactive
as it is needed for delivering @BeforeShutdown events.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java?rev=1681661&r1=1681660&r2=1681661&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java Mon May 25 22:28:16 2015
@@ -36,6 +36,12 @@ public class ApplicationContext extends
 {
     private static final long serialVersionUID = -8254441824647652312L;
 
+    /**
+     * used to prevent us firing the Destroyed event twice.
+     * We cannot just use setActive(false) as this would trash @BeforeShutdown
+     */
+    private boolean destroyed = false;
+
     public ApplicationContext()
     {
         super(ApplicationScoped.class);
@@ -66,6 +72,8 @@ public class ApplicationContext extends
 
             destroyInstance(contextual);
         }
+
+        destroyed = true;
     }
 
     /**
@@ -78,5 +86,11 @@ public class ApplicationContext extends
         setActive(false);
     }
 
-
+    /**
+     * @return @{code true} if custom beans already got destroyed
+     */
+    public boolean isDestroyed()
+    {
+        return destroyed;
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java?rev=1681661&r1=1681660&r2=1681661&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java Mon May 25 22:28:16 2015
@@ -296,7 +296,7 @@ public class DefaultContextsService exte
     
     private void startApplicationContext()
     {
-        if (applicationContext != null)
+        if (applicationContext != null && !applicationContext.isDestroyed())
         {
             // applicationContext is already started
             return;
@@ -368,7 +368,7 @@ public class DefaultContextsService exte
     
     private void stopApplicationContext()
     {
-        if(applicationContext != null)
+        if(applicationContext != null && !applicationContext.isDestroyed())
         {
             applicationContext.destroy();
 

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1681661&r1=1681660&r2=1681661&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java (original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java Mon May 25 22:28:16 2015
@@ -581,7 +581,7 @@ public class WebContextsService extends
      */
     protected void initApplicationContext(Object startupObject)
     {
-        if (applicationContext != null)
+        if (applicationContext != null && !applicationContext.isDestroyed())
         {
             applicationContext.setActive(true);
             return;
@@ -604,7 +604,7 @@ public class WebContextsService extends
     protected void destroyApplicationContext(Object endObject)
     {
         //Destroy context
-        if(applicationContext != null)
+        if(applicationContext != null && !applicationContext.isDestroyed())
         {
             applicationContext.destroy();
             // this is needed to get rid of ApplicationScoped beans which are cached inside the proxies...