You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by un...@apache.org on 2004/09/28 16:07:24 UTC

svn commit: rev 47396 - in cocoon/branches/BRANCH_2_1_X: legal lib src/blocks/scratchpad/conf src/blocks/scratchpad/java/org/apache/cocoon/components/store src/blocks/scratchpad/lib

Author: unico
Date: Tue Sep 28 07:07:23 2004
New Revision: 47396

Added:
   cocoon/branches/BRANCH_2_1_X/legal/ehcache-1.0.jar.license.txt
      - copied unchanged from rev 47395, cocoon/branches/BRANCH_2_1_X/legal/ehcache-0.9.jar.license.txt
   cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/lib/ehcache-1.0.jar   (contents, props changed)
Removed:
   cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/lib/ehcache-0.9.jar
Modified:
   cocoon/branches/BRANCH_2_1_X/lib/jars.xml
   cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/conf/ehstore.xconf
   cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/ehcache-defaults.xml
Log:
update ehcache to version 1.0

Modified: cocoon/branches/BRANCH_2_1_X/lib/jars.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/lib/jars.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/lib/jars.xml	Tue Sep 28 07:07:23 2004
@@ -568,7 +568,7 @@
     <title>EHCache</title>
     <description>Easy Hibernate Cache</description>
     <used-by>EHCache Store</used-by>
-    <lib>scratchpad/lib/ehcache-0.9.jar</lib>
+    <lib>scratchpad/lib/ehcache-1.0.jar</lib>
     <homepage>http://ehcache.sourceforge.net/</homepage>
   </file>
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/conf/ehstore.xconf
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/conf/ehstore.xconf	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/conf/ehstore.xconf	Tue Sep 28 07:07:23 2004
@@ -15,21 +15,14 @@
   limitations under the License.
 -->
 
-<xconf xpath="/cocoon" unless="comment()[contains(.,'Experimental EHCache Store implementation')]">
+<xconf xpath="/cocoon" unless="comment()[contains(.,'EHCache Store implementation')]">
 
-  <!-- Experimental EHCache Store implementation -->
+  <!-- EHCache Store implementation -->
   <!--
   <store class="org.apache.cocoon.components.store.EHStore" 
          logger="core.store">
     <parameter name="maxobjects" value="10000"/>
   </store>
-  
-  <transient-store class="org.apache.cocoon.components.store.EHStore" 
-                   logger="core.store.transient">
-    <parameter name="maxobjects" value="1000"/>
-    <parameter name="cache-name" value="transient"/>
-    <parameter name="overflow-to-disk" value="false"/>
-  </transient-store>
   -->
-  
+
 </xconf>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java	Tue Sep 28 07:07:23 2004
@@ -20,6 +20,7 @@
 import java.net.URL;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.List;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheException;
@@ -47,20 +48,29 @@
 /**
  * Store implementation based on EHCache.
  * (http://ehcache.sourceforge.net/)
- * 
- * <p>
- *  IMPORTANT:<br>
- *  (from http://ehcache.sourceforge.net/documentation/) 
- *  Persistence:
- *  The Disk Cache used by EHCache is not meant to be persistence mechanism. 
- *  The data file for each cache is deleted, if it exists, on startup.
- *  No data from a previous instance of an application is persisted through the disk cache. 
- *  The data file for each cache is also deleted on shutdown.
- * </p>
  */
 public class EHStore extends AbstractLogEnabled 
-implements Store, Parameterizable, Initializable, Disposable, ThreadSafe, Serviceable, Contextualizable {
-    
+implements Store, Contextualizable, Serviceable, Parameterizable, Initializable, Disposable, ThreadSafe {
+
+	// ---------------------------------------------------- Constants
+
+	private static final String CACHE_NAME_PARAM = "cache-name";
+	private static final String MAXOBJECTS_PARAM = "maxobjects";
+	private static final String OVERFLOW_TO_DISK_PARAM = "overflow-to-disk";
+	private static final String ETERNAL_PARAM = "eternal";
+	private static final String TIME_TO_IDLE_PARAM = "time-to-idle-seconds";
+    private static final String TIME_TO_LIVE_PARAM = "time-to-live-seconds";
+	private static final String THREAD_INTERVAL_PARAM = "thread-interval";
+    private static final String CONFIG_FILE_PARAM = "config-file";
+
+	private static final String DEFAULT_CACHE_NAME = "main";
+	private static final long DEFAULT_TIME_TO_IDLE = 120;
+	private static final long DEFAULT_TIME_TO_LIVE = 120;
+	private static final long DEFAULT_THREAD_INTERVAL = 120;
+	private static final String DEFAULT_CONFIG_FILE = "org/apache/cocoon/components/store/ehcache-defaults.xml";
+
+	// ---------------------------------------------------- Instance variables
+
     private Cache cache;
     private CacheManager cacheManager;
     
@@ -68,8 +78,11 @@
     private String cacheName;
     private int maximumSize;
     private boolean overflowToDisk;
+	private boolean eternal;
+    private long timeToIdle;
+	private long timeToLive;
     private String configFile;
-    
+
     /** The service manager */
     private ServiceManager manager;
     
@@ -78,7 +91,13 @@
 
     /** The context containing the work and the cache directory */
     private Context context;
-    
+	private long threadInterval;
+
+	// ---------------------------------------------------- Lifecycle
+
+    public EHStore() {
+    }
+
     /* (non-Javadoc)
      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
      */
@@ -91,7 +110,7 @@
      */
     public void service(ServiceManager aManager) throws ServiceException {
         this.manager = aManager;
-        this.storeJanitor = (StoreJanitor)this.manager.lookup(StoreJanitor.ROLE);
+        this.storeJanitor = (StoreJanitor) this.manager.lookup(StoreJanitor.ROLE);
     }
     
     /**
@@ -101,22 +120,33 @@
      *  EHStore intances you must specify a different name for each.</li>
      *  <li><code>maxobjects</code> (10000) - The maximum number of in-memory objects.</li>
      *  <li><code>overflow-to-disk</disk> (true) - Whether to spool elements to disk after
-     *   maxobjects has been exceeded.
+     *   maxobjects has been exceeded.</li>
+     *  <li><code>eternal</code> (true) - If eternal, 
+     *   timeouts are ignored and the elements are never expired.
+     *  <li><code>time-to-idle-seconds</code> (120) - Idle time before an element expires. Only
+     *   relevant if the cache is not eternal.
+     *  <li><code>time-to-live-seconds</code> (120) - Time to live before an element expires. Only
+     *   relevant if the cache is not eternal.
+     *  <li><code>thread-interval</code> (120) - The number of seconds between runs of the disk 
+     *   expiry thread.
      *  <li><code>config-file</code> (org/apache/cocoon/components/store/ehcache-defaults.xml) -
      *   The default configuration file to use. This file is the only way to specify the path where
      *   the disk store puts its .cache files. The current default value is <code>java.io.tmp</code>.
      *   (On a standard Linux system this will be /tmp). Note that since the EHCache manager is
      *   a singleton object the value of this parameter will only have effect when this store is the
      *   first to create it. Configuring different stores with different values for this parameter
-     *   will have no effect.
+     *   will have no effect.</li>
      * </ul>
      */
     public void parameterize(Parameters parameters) throws ParameterException {
-        this.cacheName = parameters.getParameter("cache-name", "main");
-        this.maximumSize = parameters.getParameterAsInteger("maxobjects", 10000);
-        this.overflowToDisk = parameters.getParameterAsBoolean("overflow-to-disk", true);
-        this.configFile = parameters.getParameter("config-file", 
-            "org/apache/cocoon/components/store/ehcache-defaults.xml");
+        this.cacheName = parameters.getParameter(CACHE_NAME_PARAM, DEFAULT_CACHE_NAME);
+        this.maximumSize = parameters.getParameterAsInteger(MAXOBJECTS_PARAM, 10000);
+        this.overflowToDisk = parameters.getParameterAsBoolean(OVERFLOW_TO_DISK_PARAM, true);
+        this.eternal = parameters.getParameterAsBoolean(ETERNAL_PARAM, true);
+        this.timeToIdle = parameters.getParameterAsLong(TIME_TO_IDLE_PARAM, DEFAULT_TIME_TO_IDLE);
+        this.timeToLive = parameters.getParameterAsLong(TIME_TO_LIVE_PARAM, DEFAULT_TIME_TO_LIVE);
+        this.threadInterval = parameters.getParameterAsLong(THREAD_INTERVAL_PARAM, DEFAULT_THREAD_INTERVAL);
+        this.configFile = parameters.getParameter(CONFIG_FILE_PARAM, DEFAULT_CONFIG_FILE);
     }
     
     /**
@@ -129,7 +159,14 @@
         if (cacheDir != null) System.setProperty("java.io.tmpdir", cacheDir.toString());
         this.cacheManager = CacheManager.create(configFileURL);
         if (tempDir != null) System.setProperty("java.io.tmpdir", tempDir);
-        this.cache = new Cache(this.cacheName, this.maximumSize, this.overflowToDisk, true, 0, 0);
+        this.cache = new Cache(this.cacheName,
+        		               this.maximumSize,
+							   this.overflowToDisk,
+							   this.eternal,
+							   this.timeToLive,
+							   this.timeToIdle,
+							   true,
+							   this.threadInterval);
         this.cacheManager.addCache(this.cache);
         this.storeJanitor.register(this);
     }
@@ -236,14 +273,32 @@
      * @see org.apache.excalibur.store.Store#keys()
      */
     public Enumeration keys() {
-        return Collections.enumeration(this.cache.getKeys());
+    	List keys = null;
+		try {
+			keys = this.cache.getKeys();
+		}
+		catch (CacheException e) {
+			if (getLogger().isWarnEnabled()) {
+				getLogger().warn("Error while getting cache keys", e);
+			}
+			keys = Collections.EMPTY_LIST;
+		}
+        return Collections.enumeration(keys);
     }
 
     /* (non-Javadoc)
      * @see org.apache.excalibur.store.Store#size()
      */
     public int size() {
-        return this.cache.getSize();
+        try {
+			return this.cache.getSize();
+		}
+        catch (CacheException e) {
+			if (getLogger().isWarnEnabled()) {
+				getLogger().warn("Error while getting cache size", e);
+			}
+			return 0;
+		}
     }
 
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/ehcache-defaults.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/ehcache-defaults.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/store/ehcache-defaults.xml	Tue Sep 28 07:07:23 2004
@@ -27,28 +27,42 @@
          java.io.tmpdir - Default temp file path -->
     <diskStore path="java.io.tmpdir"/>
 
-
-    <!--Default Cache configuration. These will applied to caches programmatically created through
+    <!--Default Cache configuration. These will be applied to caches programmatically created through
         the CacheManager.
 
-        The following attributes are required for defaultCache:
+        The following attributes are required:
 
-        maxInMemory       - Sets the maximum number of objects that will be created in memory
-        eternal           - Sets whether elements are eternal. If eternal,  timeouts are ignored and the element
-                            is never expired.
-        timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used
-                            if the element is not eternal.
-        timeToLiveSeconds - Sets the time to idle for an element before it expires. Is only used
-                            if the element is not eternal.
-        overflowToDisk    - Sets whether elements can overflow to disk when the in-memory cache
-                            has reached the maxInMemory limit.
+        maxElementsInMemory            - Sets the maximum number of objects that will be created in memory
+        eternal                        - Sets whether elements are eternal. If eternal,  timeouts are ignored and the
+                                         element is never expired.
+        overflowToDisk                 - Sets whether elements can overflow to disk when the in-memory cache
+                                         has reached the maxInMemory limit.
 
+        The following attributes are optional:
+        timeToIdleSeconds              - Sets the time to idle for an element before it expires.
+                                         i.e. The maximum amount of time between accesses before an element expires
+                                         Is only used if the element is not eternal.
+                                         Optional attribute. A value of 0 means that an Element can idle for infinity.
+                                         The default value is 0.
+        timeToLiveSeconds              - Sets the time to live for an element before it expires.
+                                         i.e. The maximum time between creation time and when an element expires.
+                                         Is only used if the element is not eternal.
+                                         Optional attribute. A value of 0 means that and Element can live for infinity.
+                                         The default value is 0.
+        diskPersistent                 - Whether the disk store persists between restarts of the Virtual Machine.
+                                         The default value is false.
+        diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
+                                         is 120 seconds.
         -->
+
     <defaultCache
         maxElementsInMemory="10000"
         eternal="true"
-        timeToIdleSeconds="120"
-        timeToLiveSeconds="120"
+        timeToIdleSeconds="0"
+        timeToLiveSeconds="0"
         overflowToDisk="true"
+        diskPersistent="true"
+        diskExpiryThreadIntervalSeconds="120"
         />
+
 </ehcache>

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/lib/ehcache-1.0.jar
==============================================================================
Binary file. No diff available.

Re: svn commit: rev 47396 - in cocoon/branches/BRANCH_2_1_X: legal lib src/blocks/scratchpad/conf src/blocks/scratchpad/java/org/apache/cocoon/components/store src/blocks/scratchpad/lib

Posted by Vadim Gritsenko <va...@reverycodes.com>.
unico@apache.org wrote:

> -  <!-- Experimental EHCache Store implementation -->
> +  <!-- EHCache Store implementation -->

Does it implement free() now?

     /* (non-Javadoc)
      * @see org.apache.excalibur.store.Store#free()
      */
     public void free() {
         // FIXME - we have to implement this!
     }

Or, does EH cache uses alternative algorithm for freeing up memory? 
Going through documentation did not gave much.

Vadim


Re: svn commit: rev 47396 - in cocoon/branches/BRANCH_2_1_X: legal lib src/blocks/scratchpad/conf src/blocks/scratchpad/java/org/apache/cocoon/components/store src/blocks/scratchpad/lib

Posted by Pier Fumagalli <pi...@betaversion.org>.
On 28 Sep 2004, at 15:07, unico@apache.org wrote:

> Log:
> update ehcache to version 1.0
>

Woohooo! :-P

	Pier