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:39:40 UTC
svn commit: r410072 -
/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
Author: antonio
Date: Mon May 29 03:39:39 2006
New Revision: 410072
URL: http://svn.apache.org/viewvc?rev=410072&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/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java?rev=410072&r1=410071&r2=410072&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java Mon May 29 03:39:39 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,6 +267,7 @@
this.timeToLiveSeconds, this.timeToIdleSeconds, true, 120);
this.cacheManager.addCache(this.cache);
this.storeJanitor.register(this);
+ getLogger().info("EHCache cache \"" + this.cacheName + "\" initialized");
}
/**
@@ -278,10 +280,30 @@
this.storeJanitor = null;
}
this.manager = null;
- if ( this.cacheManager != null ) {
- this.cacheManager.shutdown();
- this.cacheManager = null;
+ /*
+ * 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;
}