You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2006/05/29 12:38:45 UTC

svn commit: r410071 - in /cocoon/branches/BRANCH_2_1_X: src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java status.xml

Author: antonio
Date: Mon May 29 03:38:45 2006
New Revision: 410071

URL: http://svn.apache.org/viewvc?rev=410071&view=rev
Log:
Fix COCOON-1694 Error decommissioning component: org.apache.cocoon.components.store.impl.EHDefaultStore. Thanks to Pier Fumagalli (pier@betaversion.org). We hope we vote him as committer some day in the future! :-D

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java?rev=410071&r1=410070&r2=410071&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java Mon May 29 03:38:45 2006
@@ -27,6 +27,7 @@
 import net.sf.ehcache.CacheException;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Element;
+import net.sf.ehcache.Status;
 
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.util.IOUtils;
@@ -266,8 +267,9 @@
                 this.timeToLiveSeconds, this.timeToIdleSeconds, true, 120);
         this.cacheManager.addCache(this.cache);
         this.storeJanitor.register(this);
+        getLogger().info("EHCache cache \"" + this.cacheName + "\" initialized");
     }
-    
+
     /**
      * Shutdown the CacheManager.
      */
@@ -278,11 +280,33 @@
             this.storeJanitor = null;
         }
         this.manager = null;
-        this.cacheManager.shutdown();
+        /*
+         * EHCache can be a bitch when shutting down. Basically every cache registers
+         * a hook in the Runtime for every persistent cache, that will be executed when
+         * the JVM exit. It might happen (though) that we are shutting down Cocoon
+         * because of the same event (someone sending a TERM signal to the VM).
+         * So what we need to do here is to check if the cache itself is still alive,
+         * then we're going to shutdown EHCache entirely (if there are other caches open
+         * they will be shut down as well), if the cache is not alive, either another
+         * instance of this called the shutdown method on the CacheManager (thanks) or
+         * otherwise the hook had time to run before we got here.
+         */
+        synchronized (this.cache) {
+            if (Status.STATUS_ALIVE == this.cache.getStatus()) {
+                try {
+                    getLogger().info("Disposing EHCache cache \"" + this.cacheName + "\".");
+                    this.cacheManager.shutdown();
+                } catch (IllegalStateException e) {
+                    getLogger().error("Error disposing EHCache cache \"" + this.cacheName + "\".", e);
+                }
+            } else {
+                getLogger().info("EHCache cache \"" + this.cacheName + "\" already disposed.");
+            }
+        }
         this.cacheManager = null;
         this.cache = null;
     }
-    
+
     // ---------------------------------------------------- Store implementation
     
     /* (non-Javadoc)
@@ -427,5 +451,4 @@
             return 0;
         }
     }
-
 }

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=410071&r1=410070&r2=410071&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Mon May 29 03:38:45 2006
@@ -182,6 +182,9 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.10" date="TBD">
+    <action dev="AG" type="fix" fixes-bug="COCOON-1694" due-to="Pier Fumagalli" due-to-email="pier@betaversion.org">
+      Error decommissioning component: org.apache.cocoon.components.store.impl.EHDefaultStore.
+    </action>
     <action dev="AG" type="fix" fixes-bug="COCOON-1839" due-to="Eric Meyer" due-to-email="eric.meyer@quoininc.com">
       exception2html.xslt: &lt;script /&gt; causes IE display problem.
     </action>