unico 2004/03/17 07:00:41
Modified: src/blocks/scratchpad/java/org/apache/cocoon/components/store
EHStore.java
src/blocks/scratchpad/conf ehstore.xconf
Added: src/blocks/scratchpad/java/org/apache/cocoon/components/store
ehcache-defaults.xml
Log:
default configuration and documentation
Revision Changes Path
1.3 +47 -7
cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java
Index: EHStore.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EHStore.java 8 Mar 2004 22:44:51 -0000 1.2
+++ EHStore.java 17 Mar 2004 15:00:41 -0000 1.3
@@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.Serializable;
+import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
@@ -38,8 +39,15 @@
* Store implementation based on EHCache.
* (http://ehcache.sourceforge.net/)
*
- * TODO: CacheManager expects to be a singleton. So configuring
- * multiple EHStore intances could lead to errors.
+ * <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 {
@@ -47,30 +55,62 @@
private Cache m_cache;
private CacheManager m_cacheManager;
+ // configuration options
private String m_cacheName;
private int m_maximumSize;
private boolean m_overflowToDisk;
+ private String m_configFile;
+
+ // ---------------------------------------------------- lifecycle
public EHStore() {
}
+ /**
+ * Configure the store. The following options can be used:
+ * <ul>
+ * <li><code>cache-name</code> (main) - When configuring multiple
+ * 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.
+ * <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.
+ * </ul>
+ */
public void parameterize(Parameters parameters) throws
ParameterException {
- m_cacheName = parameters.getParameter("cache-name","main");
- m_maximumSize = parameters.getParameterAsInteger("maxobjects",100);
- m_overflowToDisk =
parameters.getParameterAsBoolean("overflow-to-disk",true);
+ m_cacheName = parameters.getParameter("cache-name", "main");
+ m_maximumSize = parameters.getParameterAsInteger("maxobjects",
10000);
+ m_overflowToDisk =
parameters.getParameterAsBoolean("overflow-to-disk", true);
+ m_configFile = parameters.getParameter("config-file",
+ "org/apache/cocoon/components/store/ehcache-defaults.xml");
}
+ /**
+ * Initialize the CacheManager and created the Cache.
+ */
public void initialize() throws Exception {
- m_cacheManager = CacheManager.create();
- m_cache = new
Cache(m_cacheName,m_maximumSize,m_overflowToDisk,true,0,0);
+ URL configFile =
Thread.currentThread().getContextClassLoader().getResource(m_configFile);
+ m_cacheManager = CacheManager.create(configFile);
+ m_cache = new Cache(m_cacheName, m_maximumSize, m_overflowToDisk,
true, 0, 0);
m_cacheManager.addCache(m_cache);
}
+ /**
+ * Shutdown the CacheManager.
+ */
public void dispose() {
m_cacheManager.shutdown();
m_cacheManager = null;
m_cache = null;
}
+
+ // ---------------------------------------------------- Store
implementation
/* (non-Javadoc)
* @see org.apache.excalibur.store.Store#free()
1.1
cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/ehcache-defaults.xml
Index: ehcache-defaults.xml
===================================================================
<ehcache>
<!-- Sets the path to the directory where cache .data files are created.
If the path is a Java System Property it is replaced by
its value in the running VM.
The following properties are translated:
user.home - User's home directory
user.dir - User's current working directory
java.io.tmpdir - Default temp file path -->
<diskStore path="java.io.tmpdir"/>
<!--Default Cache configuration. These will applied to caches
programmatically created through
the CacheManager.
The following attributes are required for defaultCache:
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.
-->
<defaultCache
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
</ehcache>
1.2 +5 -4 cocoon-2.1/src/blocks/scratchpad/conf/ehstore.xconf
Index: ehstore.xconf
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/conf/ehstore.xconf,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ehstore.xconf 8 Mar 2004 22:43:32 -0000 1.1
+++ ehstore.xconf 17 Mar 2004 15:00:41 -0000 1.2
@@ -20,13 +20,14 @@
<!-- Experimental EHCache Store implementation -->
<!--
<store class="org.apache.cocoon.components.store.EHStore"
- logger="core.store">
- <parameter name="maxobjects" value="100"/>
+ 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="100"/>
+ logger="core.store.transient">
+ <parameter name="maxobjects" value="1000"/>
+ <parameter name="cache-name" value="transient"/>
<parameter name="overflow-to-disk" value="false"/>
</transient-store>
-->