You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2007/01/13 10:45:15 UTC
svn commit: r495859 - in /cocoon/trunk/core:
cocoon-core/src/main/resources/org/apache/cocoon/
cocoon-store/cocoon-store-impl/
cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/
cocoon-store/cocoon-store-impl/src/main...
Author: danielf
Date: Sat Jan 13 01:45:14 2007
New Revision: 495859
URL: http://svn.apache.org/viewvc?view=rev&rev=495859
Log:
POJOfied the cocoon-store-impl module. Needed to copy and adapt the MRUMemoryStore from Excalibur store to be able to POJOfy the DefaultStore and DefaultTransientStore. While adapting the MRUMemoryStore I commented away the instrumentation support as I don't know how it works. Should we support instrumentation and in that case should the Excalibur version be used?
Added:
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java (with props)
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml (with props)
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml (with props)
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml (with props)
Removed:
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/avalon/
Modified:
cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/cocoon.roles
cocoon/trunk/core/cocoon-store/cocoon-store-impl/pom.xml
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultStore.java
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultTransientStore.java
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/FilesystemStore.java
cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java
Modified: cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/cocoon.roles
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/cocoon.roles?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/cocoon.roles (original)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/cocoon.roles Sat Jan 13 01:45:14 2007
@@ -58,36 +58,6 @@
shorthand="xpath-processor"
default-class="org.apache.excalibur.xml.xpath.XPathProcessorImpl"/>
- <!-- Stores: -->
- <role name="org.apache.excalibur.store.Store"
- shorthand="store"
- default-class="org.apache.cocoon.components.store.impl.EHDefaultStore"/>
-
- <role name="org.apache.excalibur.store.Store/TransientStore"
- shorthand="transient-store"
- default-class="org.apache.cocoon.components.store.impl.DefaultTransientStore"/>
-
-<!--
- The persistent store is only an auxiliary store that shouldn't be
- used by Cocoon users. It should only be used - if required - by
- the Store. If we use JCS, we don't need a persistent store.
- <role name="org.apache.excalibur.store.Store/PersistentStore"
- shorthand="persistent-store"
- default-class="org.apache.cocoon.components.store.impl.DefaultPersistentStore"/>
--->
- <!-- Normally uses the org.apache.excalibur.store.impl.StoreJanitorImpl as
- the default-class but as that uses its own Thread spawning there is
- the org.apache.cocoon.components.store.impl.CocoonStoreJanitor class
- to use a daemon thread from the org.apache.cocoon.components.thread.RunnableManager
- component
- NOT: As soon as our patch has been accepted by the Excalibur community and an
- excalibur-store has been release we can switch back to the original
- org.apache.excalibur.store.impl.StoreJanitorImpl class
- -->
- <role name="org.apache.excalibur.store.StoreJanitor"
- shorthand="store-janitor"
- default-class="org.apache.cocoon.components.store.impl.CocoonStoreJanitor"/>
-
<!--=========================================================================
Sitemap engine
=========================================================================-->
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/pom.xml?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/pom.xml (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/pom.xml Sat Jan 13 01:45:14 2007
@@ -52,17 +52,6 @@
</dependency>
<!-- Excalibur -->
<dependency>
- <groupId>org.apache.avalon.framework</groupId>
- <artifactId>avalon-framework-api</artifactId>
- <version>4.3</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.avalon.logkit</groupId>
- <artifactId>avalon-logkit</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>org.apache.excalibur.components.store</groupId>
<artifactId>excalibur-store</artifactId>
<version>2.1</version>
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java Sat Jan 13 01:45:14 2007
@@ -16,13 +16,6 @@
*/
package org.apache.cocoon.components.store.impl;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-
import org.apache.cocoon.components.thread.RunnableManager;
/**
@@ -32,16 +25,14 @@
*
* @version $Id$
*/
-public class CocoonStoreJanitor extends StoreJanitorImpl
- implements Serviceable, Disposable {
+public class CocoonStoreJanitor extends StoreJanitorImpl {
+
+ private static final String THREAD_POOL = "daemon";
//~ Instance fields --------------------------------------------------------
/** Name of the thread pool to use. Defaults to 'daemon'. */
- private String threadPool;
-
- /** Our {@link ServiceManager} */
- private ServiceManager serviceManager;
+ private String threadPool = THREAD_POOL;
/** Our {@link RunnableManager} */
private RunnableManager runnableManager;
@@ -54,30 +45,23 @@
//~ Methods ----------------------------------------------------------------
- public void parameterize(Parameters params) throws ParameterException {
- super.parameterize(params);
- this.threadPool = params.getParameter("thread-pool", "daemon");
- }
-
/**
- * Get the <code>RunnableManager</code>
- *
- * @param serviceManager The <code>ServiceManager</code>
- * @throws ServiceException If RunnableManager is not available
+ * Name of the thread pool to use.
+ * If not specified, defaults to 'daemon'.
+ *
+ * @param threadPool
*/
- public void service(final ServiceManager serviceManager)
- throws ServiceException {
- this.serviceManager = serviceManager;
- this.runnableManager = (RunnableManager) serviceManager.lookup(RunnableManager.ROLE);
+ public void setThreadPool(String threadPool) {
+ this.threadPool = threadPool;
}
/**
- * Release <code>RunnableManager</code>
+ * Set the <code>RunnableManager</code>
+ *
+ * @param runnableManager
*/
- public void dispose() {
- this.serviceManager.release(this.runnableManager);
- this.runnableManager = null;
- this.serviceManager = null;
+ public void setRunnableManager(RunnableManager runnableManager) {
+ this.runnableManager = runnableManager;
}
/**
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultStore.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultStore.java?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultStore.java (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultStore.java Sat Jan 13 01:45:14 2007
@@ -16,9 +16,6 @@
*/
package org.apache.cocoon.components.store.impl;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.excalibur.store.impl.MRUMemoryStore;
/**
* Default implementation of Cocoon's store. It's a <code>MRUMemoryStore</code> whose
@@ -30,10 +27,13 @@
*/
public class DefaultStore extends MRUMemoryStore {
- public void parameterize(Parameters params) throws ParameterException {
- if (!params.isParameter("use-persistent-cache")) {
- params.setParameter("use-persistent-cache", "true");
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.store.impl.MRUMemoryStore#init()
+ */
+ public void init() throws Exception {
+ super.init();
+ if (!this.persistent) {
+ throw new Exception("A persistent store must be backed by a persistent store.");
}
- super.parameterize(params);
}
}
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultTransientStore.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultTransientStore.java?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultTransientStore.java (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/DefaultTransientStore.java Sat Jan 13 01:45:14 2007
@@ -16,9 +16,6 @@
*/
package org.apache.cocoon.components.store.impl;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.excalibur.store.impl.MRUMemoryStore;
/**
* Default implementation of Cocoon's transient store. This is a <code>MRUMemoryStore</code>
@@ -28,10 +25,13 @@
*/
public class DefaultTransientStore extends MRUMemoryStore {
- public void parameterize(Parameters params) throws ParameterException {
- if (params.getParameterAsBoolean("use-persistent-cache", false)) {
- throw new ParameterException("A transient store cannot be backed by a persistent store.");
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.store.impl.MRUMemoryStore#init()
+ */
+ public void init() throws Exception {
+ super.init();
+ if (this.persistent) {
+ throw new Exception("A transient store cannot be backed by a persistent store.");
}
- super.parameterize(params);
}
}
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java Sat Jan 13 01:45:14 2007
@@ -30,37 +30,92 @@
import net.sf.ehcache.Element;
import net.sf.ehcache.Status;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameterizable;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.configuration.Settings;
import org.apache.cocoon.util.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.excalibur.store.Store;
import org.apache.excalibur.store.StoreJanitor;
/**
* Store implementation based on EHCache.
* (http://ehcache.sourceforge.net/)
+ * Configure the store.
+ * <br/>
+ * The following options can be used:
+ * <ul>
+ * <li><code>maxobjects</code> (10000) - The maximum number of in-memory objects.</li>
+ * <li><code>overflow-to-disk</code> (true) - Whether to spool elements to disk after
+ * maxobjects has been exceeded.</li>
+ * <li><code>eternal</code> (true) - whether or not entries expire. When set to
+ * <code>false</code> the <code>timeToLiveSeconds</code> and
+ * <code>timeToIdleSeconds</code> parameters are used to determine when an
+ * item expires.</li>
+ * <li><code>timeToLiveSeconds</code> (0) - how long an entry may live in the cache
+ * before it is removed. The entry will be removed no matter how frequently it is retrieved.</li>
+ * <li><code>timeToIdleSeconds</code> (0) - the maximum time between retrievals
+ * of an entry. If the entry is not retrieved for this period, it is removed from the
+ * cache.</li>
+ * <li><code>use-cache-directory</code> (false) - If true the <i>cache-directory</i>
+ * context entry will be used as the location of the disk store.
+ * Within the servlet environment this is set in web.xml.</li>
+ * <li><code>use-work-directory</code> (false) - If true the <i>work-directory</i>
+ * context entry will be used as the location of the disk store.
+ * Within the servlet environment this is set in web.xml.</li>
+ * <li><code>directory</code> - Specify an alternative location of the disk store.
+ * </ul>
+ *
+ * <p>
+ * Setting <code>eternal</code> to <code>false</code> but not setting
+ * <code>timeToLiveSeconds</code> and/or <code>timeToIdleSeconds</code>, has the
+ * same effect as setting <code>eternal</code> to <code>true</code>.
+ * </p>
+ *
+ * <p>
+ * Here is an example to clarify the purpose of the <code>timeToLiveSeconds</code> and
+ * <code>timeToIdleSeconds</code> parameters:
+ * </p>
+ * <ul>
+ * <li>timeToLiveSeconds = 86400 (1 day)</li>
+ * <li>timeToIdleSeconds = 10800 (3 hours)</li>
+ * </ul>
+ *
+ * <p>
+ * With these settings the entry will be removed from the cache after 24 hours. If within
+ * that 24-hour period the entry is not retrieved within 3 hours after the last retrieval, it will
+ * also be removed from the cache.
+ * </p>
+ *
+ * <p>
+ * By setting <code>timeToLiveSeconds</code> to <code>0</code>, an item can stay in
+ * the cache as long as it is retrieved within <code>timeToIdleSeconds</code> after the
+ * last retrieval.
+ * </p>
+ *
+ * <p>
+ * By setting <code>timeToIdleSeconds</code> to <code>0</code>, an item will stay in
+ * the cache for exactly <code>timeToLiveSeconds</code>.
+ * </p>
+ *
+ * <p>
+ * <code>disk-persistent</code> Whether the disk store persists between restarts of
+ * the Virtual Machine. The default value is true.
+ *
* @version $Id$
*/
-public class EHDefaultStore
- extends AbstractLogEnabled
- implements Store,
- Serviceable,
- Parameterizable,
- Initializable,
- Disposable,
- ThreadSafe {
+public class EHDefaultStore implements Store {
// ---------------------------------------------------- Constants
+ private static final int MAXOBJECTS = 10000;
+ private static final boolean OVERFLOW_TO_DISK = true;
+ private static final boolean DISK_PERSISTENT = true;
+ private static final boolean ETERNAL = true;
+ private static final long TIME_TO_LIVE_SECONDS = 0L;
+ private static final long TIME_TO_IDLE_SECONDS = 0L;
+ private static final boolean USE_WORK_DIRECTORY = false;
+ private static final boolean USE_CACHE_DIRECTORY = false;
+
private static final String CONFIG_FILE = "org/apache/cocoon/components/store/impl/ehcache.xml";
private static int instanceCount = 0;
@@ -73,18 +128,25 @@
private final String cacheName;
// configuration options
- private int maxObjects;
- private boolean overflowToDisk;
- private boolean diskPersistent;
- private boolean eternal;
- private long timeToLiveSeconds;
- private long timeToIdleSeconds;
-
+ private int maxObjects = MAXOBJECTS;
+ private boolean overflowToDisk = OVERFLOW_TO_DISK;
+ private boolean diskPersistent = DISK_PERSISTENT;
+ private boolean eternal = ETERNAL;
+ private long timeToLiveSeconds = TIME_TO_LIVE_SECONDS;
+ private long timeToIdleSeconds = TIME_TO_IDLE_SECONDS;
+ private boolean useCacheDirectory = USE_CACHE_DIRECTORY;
+ private boolean useWorkDirectory = USE_WORK_DIRECTORY;
+ private String directory;
/** The service manager */
- private ServiceManager manager;
+
+ /** By default we use the logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
/** The store janitor */
private StoreJanitor storeJanitor;
+
+ /** The settings object */
+ private Settings settings;
private File workDir;
private File cacheDir;
@@ -97,118 +159,109 @@
}
/**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ * <li><code>directory</code> - Specify an alternative location of the disk store.
+ * @param directory
*/
- public void service(ServiceManager aManager) throws ServiceException {
- this.manager = aManager;
- this.storeJanitor = (StoreJanitor) this.manager.lookup(StoreJanitor.ROLE);
- final Settings settings = (Settings)this.manager.lookup(Settings.ROLE);
- this.workDir = new File(settings.getWorkDirectory());
- this.cacheDir = new File(settings.getCacheDirectory());
- this.manager.release(settings);
+ public void setDirectory(String directory) {
+ this.directory = directory;
+ }
+
+ /**
+ * <code>disk-persistent</code> Whether the disk store persists between restarts of
+ * the Virtual Machine. The default value is true.
+ * @param diskPersistent
+ */
+ public void setDiskPersistent(boolean diskPersistent) {
+ this.diskPersistent = diskPersistent;
}
/**
- * Configure the store. The following options can be used:
- * <ul>
- * <li><code>maxobjects</code> (10000) - The maximum number of in-memory objects.</li>
- * <li><code>overflow-to-disk</code> (true) - Whether to spool elements to disk after
- * maxobjects has been exceeded.</li>
* <li><code>eternal</code> (true) - whether or not entries expire. When set to
* <code>false</code> the <code>timeToLiveSeconds</code> and
* <code>timeToIdleSeconds</code> parameters are used to determine when an
* item expires.</li>
- * <li><code>timeToLiveSeconds</code> (0) - how long an entry may live in the cache
- * before it is removed. The entry will be removed no matter how frequently it is retrieved.</li>
+ * @param eternal
+ */
+ public void setEternal(boolean eternal) {
+ this.eternal = eternal;
+ }
+
+ /**
+ * <code>maxobjects</code> (10000) - The maximum number of in-memory objects.
+ * @param maxObjects
+ */
+ public void setMaxObjects(int maxObjects) {
+ this.maxObjects = maxObjects;
+ }
+
+ /**
+ * <li><code>overflow-to-disk</code> (true) - Whether to spool elements to disk after
+ * maxobjects has been exceeded.</li>
+ * @param overflowToDisk
+ */
+ public void setOverflowToDisk(boolean overflowToDisk) {
+ this.overflowToDisk = overflowToDisk;
+ }
+
+ /**
* <li><code>timeToIdleSeconds</code> (0) - the maximum time between retrievals
* of an entry. If the entry is not retrieved for this period, it is removed from the
* cache.</li>
+ * @param timeToIdleSeconds
+ */
+ public void setTimeToIdleSeconds(long timeToIdleSeconds) {
+ this.timeToIdleSeconds = timeToIdleSeconds;
+ }
+
+ /**
+ * <li><code>timeToLiveSeconds</code> (0) - how long an entry may live in the cache
+ * before it is removed. The entry will be removed no matter how frequently it is retrieved.</li>
+ * @param timeToLiveSeconds
+ */
+ public void setTimeToLiveSeconds(long timeToLiveSeconds) {
+ this.timeToLiveSeconds = timeToLiveSeconds;
+ }
+
+ /**
* <li><code>use-cache-directory</code> (false) - If true the <i>cache-directory</i>
* context entry will be used as the location of the disk store.
* Within the servlet environment this is set in web.xml.</li>
+ * @param useCacheDirectory
+ */
+ public void setUseCacheDirectory(boolean useCacheDirectory) {
+ this.useCacheDirectory = useCacheDirectory;
+ }
+
+ /**
* <li><code>use-work-directory</code> (false) - If true the <i>work-directory</i>
* context entry will be used as the location of the disk store.
* Within the servlet environment this is set in web.xml.</li>
- * <li><code>directory</code> - Specify an alternative location of the disk store.
- * </ul>
- *
- * <p>
- * Setting <code>eternal</code> to <code>false</code> but not setting
- * <code>timeToLiveSeconds</code> and/or <code>timeToIdleSeconds</code>, has the
- * same effect as setting <code>eternal</code> to <code>true</code>.
- * </p>
- *
- * <p>
- * Here is an example to clarify the purpose of the <code>timeToLiveSeconds</code> and
- * <code>timeToIdleSeconds</code> parameters:
- * </p>
- * <ul>
- * <li>timeToLiveSeconds = 86400 (1 day)</li>
- * <li>timeToIdleSeconds = 10800 (3 hours)</li>
- * </ul>
- *
- * <p>
- * With these settings the entry will be removed from the cache after 24 hours. If within
- * that 24-hour period the entry is not retrieved within 3 hours after the last retrieval, it will
- * also be removed from the cache.
- * </p>
- *
- * <p>
- * By setting <code>timeToLiveSeconds</code> to <code>0</code>, an item can stay in
- * the cache as long as it is retrieved within <code>timeToIdleSeconds</code> after the
- * last retrieval.
- * </p>
- *
- * <p>
- * By setting <code>timeToIdleSeconds</code> to <code>0</code>, an item will stay in
- * the cache for exactly <code>timeToLiveSeconds</code>.
- * </p>
- *
- * <p>
- * <code>disk-persistent</code> Whether the disk store persists between restarts of
- * the Virtual Machine. The default value is true.
- *
+ * @param useWorkDirectory
*/
- public void parameterize(Parameters parameters) throws ParameterException {
- this.maxObjects = parameters.getParameterAsInteger("maxobjects", 10000);
- this.overflowToDisk = parameters.getParameterAsBoolean("overflow-to-disk", true);
- this.diskPersistent = parameters.getParameterAsBoolean("disk-persistent", true);
-
- this.eternal = parameters.getParameterAsBoolean("eternal", true);
- if (!this.eternal) {
- this.timeToLiveSeconds = parameters.getParameterAsLong("timeToLiveSeconds", 0L);
- this.timeToIdleSeconds = parameters.getParameterAsLong("timeToIdleSeconds", 0L);
- }
+ public void setUseWorkDirectory(boolean useWorkDirectory) {
+ this.useWorkDirectory = useWorkDirectory;
+ }
- try {
- if (parameters.getParameterAsBoolean("use-cache-directory", false)) {
- if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("Using cache directory: " + cacheDir);
- }
- setDirectory(cacheDir);
- } else if (parameters.getParameterAsBoolean("use-work-directory", false)) {
- if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("Using work directory: " + workDir);
- }
- setDirectory(workDir);
- } else if (parameters.getParameter("directory", null) != null) {
- String dir = parameters.getParameter("directory");
- dir = IOUtils.getContextFilePath(workDir.getPath(), dir);
- if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("Using directory: " + dir);
- }
- setDirectory(new File(dir));
- } else {
- try {
- // Legacy: use working directory by default
- setDirectory(workDir);
- } catch (IOException e) {
- // EMPTY
- }
- }
- } catch (IOException e) {
- throw new ParameterException("Unable to set directory", e);
- }
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ public void setLogger(Log l) {
+ this.logger = l;
+ }
+
+ /**
+ * @param settings the settings to set
+ */
+ public void setSettings(Settings settings) {
+ this.settings = settings;
+ }
+
+ /**
+ * @param storeJanitor the storeJanitor to set
+ */
+ public void setStoreJanitor(StoreJanitor storeJanitor) {
+ this.storeJanitor = storeJanitor;
}
/**
@@ -260,7 +313,39 @@
/**
* Initialize the CacheManager and created the Cache.
*/
- public void initialize() throws Exception {
+ public void init() throws Exception {
+ this.workDir = new File(settings.getWorkDirectory());
+ this.cacheDir = new File(settings.getCacheDirectory());
+
+ try {
+ if (this.useCacheDirectory) {
+ if (this.getLogger().isDebugEnabled()) {
+ getLogger().debug("Using cache directory: " + cacheDir);
+ }
+ setDirectory(cacheDir);
+ } else if (this.useWorkDirectory) {
+ if (this.getLogger().isDebugEnabled()) {
+ getLogger().debug("Using work directory: " + workDir);
+ }
+ setDirectory(workDir);
+ } else if (this.directory != null) {
+ this.directory = IOUtils.getContextFilePath(workDir.getPath(), this.directory);
+ if (this.getLogger().isDebugEnabled()) {
+ getLogger().debug("Using directory: " + this.directory);
+ }
+ setDirectory(new File(this.directory));
+ } else {
+ try {
+ // Legacy: use working directory by default
+ setDirectory(this.workDir);
+ } catch (IOException e) {
+ // EMPTY
+ }
+ }
+ } catch (IOException e) {
+ throw new Exception("Unable to set directory", e);
+ }
+
URL configFileURL = Thread.currentThread().getContextClassLoader().getResource(CONFIG_FILE);
this.cacheManager = CacheManager.create(configFileURL);
this.cache = new Cache(this.cacheName, this.maxObjects, this.overflowToDisk, this.eternal,
@@ -273,13 +358,10 @@
/**
* Shutdown the CacheManager.
*/
- public void dispose() {
- if (this.storeJanitor != null) {
+ public void destroy() {
+ if (this.storeJanitor != null)
this.storeJanitor.unregister(this);
- this.manager.release(this.storeJanitor);
- this.storeJanitor = null;
- }
- this.manager = 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
@@ -303,8 +385,6 @@
getLogger().info("EHCache cache \"" + this.cacheName + "\" already disposed.");
}
}
- this.cacheManager = null;
- this.cache = null;
}
// ---------------------------------------------------- Store implementation
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/FilesystemStore.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/FilesystemStore.java?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/FilesystemStore.java (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/FilesystemStore.java Sat Jan 13 01:45:14 2007
@@ -19,14 +19,11 @@
import java.io.File;
import java.io.IOException;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameterizable;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.configuration.Settings;
import org.apache.cocoon.util.IOUtils;
+import org.apache.cocoon.util.avalon.CLLoggerWrapper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.excalibur.store.impl.AbstractFilesystemStore;
/**
@@ -36,42 +33,63 @@
* @version $Id$
*/
public final class FilesystemStore
- extends AbstractFilesystemStore
- implements Serviceable, Parameterizable {
+ extends AbstractFilesystemStore {
+
+ private static final boolean USE_CACHE_DIRECTORY = false;
+ private static final boolean USE_WORK_DIRECTORY = false;
+
+ private boolean useCacheDirectory = USE_CACHE_DIRECTORY;
+ private boolean useWorkDirectory = USE_WORK_DIRECTORY;
+ private String directory;
protected File workDir;
protected File cacheDir;
+
+ /** The default logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
+
+ private Settings settings;
/**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ * @param settings
*/
- public void service(ServiceManager manager) throws ServiceException {
- final Settings settings = (Settings)manager.lookup(Settings.ROLE);
- this.workDir = new File(settings.getWorkDirectory());
- this.cacheDir = new File(settings.getCacheDirectory());
- manager.release(settings);
+ public void setSettings(Settings settings) {
+ this.settings = settings;
+ }
+
+ /**
+ * @param useCacheDirectory
+ */
+ public void setUseCacheDirectory(boolean useCacheDirectory) {
+ this.useCacheDirectory = useCacheDirectory;
}
/**
- * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+ * @param useWorkDirectory
*/
- public void parameterize(Parameters params)
- throws ParameterException {
+ public void setUseWorkDirectory(boolean useWorkDirectory) {
+ this.useWorkDirectory = useWorkDirectory;
+ }
+
+ public void init() throws Exception {
+ this.enableLogging(new CLLoggerWrapper(this.logger));
+ this.workDir = new File(settings.getWorkDirectory());
+ this.cacheDir = new File(settings.getCacheDirectory());
+
try {
- if (params.getParameterAsBoolean("use-cache-directory", false)) {
+ if (this.useCacheDirectory) {
if (this.getLogger().isDebugEnabled())
getLogger().debug("Using cache directory: " + cacheDir);
setDirectory(cacheDir);
- } else if (params.getParameterAsBoolean("use-work-directory", false)) {
+ } else if (this.useWorkDirectory) {
if (this.getLogger().isDebugEnabled())
getLogger().debug("Using work directory: " + workDir);
setDirectory(workDir);
- } else if (params.getParameter("directory", null) != null) {
- String dir = params.getParameter("directory");
- dir = IOUtils.getContextFilePath(workDir.getPath(), dir);
+ } else if (this.directory != null) {
+ this.directory = IOUtils.getContextFilePath(workDir.getPath(), this.directory);
if (this.getLogger().isDebugEnabled())
- getLogger().debug("Using directory: " + dir);
- setDirectory(new File(dir));
+ getLogger().debug("Using directory: " + this.directory);
+ setDirectory(new File(this.directory));
} else {
try {
// Legacy: use working directory by default
@@ -81,7 +99,7 @@
}
}
} catch (IOException e) {
- throw new ParameterException("Unable to set directory", e);
+ throw new Exception("Unable to set directory", e);
}
}
}
Added: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java?view=auto&rev=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java (added)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java Sat Jan 13 01:45:14 2007
@@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.store.impl;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.excalibur.store.Store;
+import org.apache.excalibur.store.StoreJanitor;
+
+// import org.apache.excalibur.instrument.CounterInstrument;
+// import org.apache.excalibur.instrument.Instrument;
+// import org.apache.excalibur.instrument.Instrumentable;
+// import org.apache.excalibur.instrument.ValueInstrument;
+
+/**
+ * This class provides a cache algorithm for the requested documents. It
+ * combines a HashMap and a LinkedList to create a so called MRU (Most Recently
+ * Used) cache.
+ *
+ * Adapted from org.apache.excalibur.store.impl.MRUMemoryStore
+ *
+ * @version $Id$
+ */
+public class MRUMemoryStore implements Store {
+ private static final int MAX_OBJECTS = 100;
+
+ /** By default we use the logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
+
+ // private String instrumentableName;
+ private int maxObjects = MAX_OBJECTS;
+
+ protected boolean persistent = false;
+
+ private Store persistentStore;
+
+ private StoreJanitor storeJanitor;
+
+ private Hashtable cache;
+
+ private LinkedList mrulist;
+
+ // private ValueInstrument sizeInstrument = new ValueInstrument("size");
+ // private CounterInstrument hitsInstrument = new CounterInstrument("hits");
+ // private CounterInstrument missesInstrument = new
+ // CounterInstrument("misses");
+
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ public void setLogger(Log l) {
+ this.logger = l;
+ }
+
+ /**
+ * Indicates how many objects will be held in the cache. When the number of
+ * maxobjects has been reached. The last object in the cache will be thrown
+ * out. (Default: 100 objects)
+ *
+ * @param maxobjects
+ */
+ public void setMaxObjects(int maxobjects) {
+ this.maxObjects = maxobjects;
+ }
+
+ /**
+ * @param persistent
+ */
+ public void setUsePersistentStore(boolean persistent) {
+ this.persistent = persistent;
+ }
+
+ /**
+ * Set to keep objects persisted after container shutdown
+ *
+ * @param persistentStore
+ */
+ public void setPersistentStore(Store persistentStore) {
+ this.persistentStore = persistentStore;
+ }
+
+ /**
+ * @param storeJanitor
+ */
+ public void setStoreJanitor(StoreJanitor storeJanitor) {
+ this.storeJanitor = storeJanitor;
+ }
+
+ /**
+ * Initialize the MRUMemoryStore.
+ *
+ * @throws Exception
+ * @exception ParameterException
+ */
+ public void init() throws Exception {
+ if ((this.maxObjects < 1))
+ throw new Exception("MRUMemoryStore maxobjects must be at least 1!");
+
+ if (this.persistent == true && this.persistentStore == null)
+ throw new Exception(
+ "The persistent store must be set if usePersistentStore is required");
+
+ this.persistent = this.persistentStore != null;
+
+ this.cache = new Hashtable((int) (this.maxObjects * 1.2));
+ this.mrulist = new LinkedList();
+ this.storeJanitor.register(this);
+ }
+
+ /**
+ * Dispose the component
+ */
+ public void destroy() {
+ getLogger().debug("Destroying component!");
+
+ if (this.storeJanitor != null) {
+ this.storeJanitor.unregister(this);
+ }
+
+ // save all cache entries to filesystem
+ if (this.persistent) {
+ getLogger().debug("Final cache size: " + this.cache.size());
+ Enumeration enumer = this.cache.keys();
+ while (enumer.hasMoreElements()) {
+ Object key = enumer.nextElement();
+ if (key == null) {
+ continue;
+ }
+ try {
+ Object value = this.cache.remove(key);
+ if (checkSerializable(value)) {
+ this.persistentStore.store(key, value);
+ }
+ } catch (IOException ioe) {
+ getLogger().error("Error in dispose()", ioe);
+ }
+ }
+ }
+ }
+
+ /**
+ * Store the given object in a persistent state. It is up to the caller to
+ * ensure that the key has a persistent state across different JVM
+ * executions.
+ *
+ * @param key
+ * The key for the object to store
+ * @param value
+ * The object to store
+ */
+ public synchronized void store(Object key, Object value) {
+ hold(key, value);
+ }
+
+ /**
+ * This method holds the requested object in a HashMap combined with a
+ * LinkedList to create the MRU. It also stores objects onto the filesystem
+ * if configured.
+ *
+ * @param key
+ * The key of the object to be stored
+ * @param value
+ * The object to be stored
+ */
+ public synchronized void hold(Object key, Object value) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Holding object in memory:");
+ getLogger().debug(" key: " + key);
+ getLogger().debug(" value: " + value);
+ }
+ /** ...first test if the max. objects in cache is reached... */
+ while (this.mrulist.size() >= this.maxObjects) {
+ /** ...ok, heapsize is reached, remove the last element... */
+ free();
+ }
+ /** ..put the new object in the cache, on the top of course ... */
+ this.cache.put(key, value);
+ this.mrulist.remove(key);
+ this.mrulist.addFirst(key);
+ // this.sizeInstrument.setValue( this.mrulist.size() );
+ }
+
+ /**
+ * Get the object associated to the given unique key.
+ *
+ * @param key
+ * The key of the requested object
+ * @return the requested object
+ */
+ public synchronized Object get(Object key) {
+ Object value = this.cache.get(key);
+ if (value != null) {
+ /** put the accessed key on top of the linked list */
+ this.mrulist.remove(key);
+ this.mrulist.addFirst(key);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Found key: " + key.toString());
+ }
+ // this.hitsInstrument.increment();
+ return value;
+ }
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("NOT Found key: " + key.toString());
+ }
+
+ /** try to fetch from filesystem */
+ if (this.persistent) {
+ value = this.persistentStore.get(key);
+ if (value != null) {
+ try {
+ if (!this.cache.containsKey(key)) {
+ hold(key, value);
+ }
+ // this.hitsInstrument.increment();
+ return value;
+ } catch (Exception e) {
+ getLogger().error("Error in get()!", e);
+ }
+ }
+ }
+ // this.missesInstrument.increment();
+ return null;
+ }
+
+ /**
+ * Remove the object associated to the given key.
+ *
+ * @param key
+ * The key of to be removed object
+ */
+ public synchronized void remove(Object key) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Removing object from store");
+ getLogger().debug(" key: " + key);
+ }
+ this.cache.remove(key);
+ this.mrulist.remove(key);
+ // this.sizeInstrument.setValue( this.mrulist.size() );
+
+ if (this.persistent && key != null) {
+ this.persistentStore.remove(key);
+ }
+ }
+
+ /**
+ * Clear the Store of all elements
+ */
+ public synchronized void clear() {
+ Enumeration enumer = this.cache.keys();
+ while (enumer.hasMoreElements()) {
+ Object key = enumer.nextElement();
+ if (key == null) {
+ continue;
+ }
+ remove(key);
+ }
+ // this.sizeInstrument.setValue( 0 );
+ }
+
+ /**
+ * Indicates if the given key is associated to a contained object.
+ *
+ * @param key
+ * The key of the object
+ * @return true if the key exists
+ */
+ public synchronized boolean containsKey(Object key) {
+ if (this.persistent) {
+ return (this.cache.containsKey(key) || this.persistentStore
+ .containsKey(key));
+ } else {
+ return this.cache.containsKey(key);
+ }
+ }
+
+ /**
+ * Returns the list of used keys as an Enumeration.
+ *
+ * @return the enumeration of the cache
+ */
+ public synchronized Enumeration keys() {
+ return this.cache.keys();
+ }
+
+ /**
+ * Returns count of the objects in the store, or -1 if could not be
+ * obtained.
+ */
+ public synchronized int size() {
+ return this.cache.size();
+ }
+
+ /**
+ * Frees some of the fast memory used by this store. It removes the last
+ * element in the store.
+ */
+ public synchronized void free() {
+ try {
+ if (this.cache.size() > 0) {
+ // This can throw NoSuchElementException
+ Object key = this.mrulist.removeLast();
+ Object value = this.cache.remove(key);
+ if (value == null) {
+ getLogger().warn("Concurrency condition in free()");
+ }
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Freeing cache.");
+ getLogger().debug(" key: " + key);
+ getLogger().debug(" value: " + value);
+ }
+
+ if (this.persistent) {
+ // Swap object on fs.
+ if (checkSerializable(value)) {
+ try {
+ this.persistentStore.store(key, value);
+ } catch (Exception e) {
+ getLogger().error("Error storing object on fs", e);
+ }
+ }
+ }
+
+ // this.sizeInstrument.setValue( this.mrulist.size() );
+ }
+ } catch (NoSuchElementException e) {
+ getLogger().warn("Concurrency error in free()", e);
+ } catch (Exception e) {
+ getLogger().error("Error in free()", e);
+ }
+ }
+
+ /**
+ * This method checks if an object is seriazable.
+ *
+ * @param object
+ * The object to be checked
+ * @return true if the object is storeable
+ */
+ private boolean checkSerializable(Object object) {
+
+ if (object == null)
+ return false;
+
+ return (object instanceof java.io.Serializable);
+ }
+
+ /*
+ * public void setInstrumentableName(String name) { this.instrumentableName =
+ * name; }
+ *
+ * public String getInstrumentableName() { return this.instrumentableName; }
+ *
+ * public Instrument[] getInstruments() { return new Instrument[] {
+ * this.sizeInstrument, this.hitsInstrument, this.missesInstrument }; }
+ *
+ * public Instrumentable[] getChildInstrumentables() { return
+ * Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY; }
+ */
+}
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/MRUMemoryStore.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java?view=diff&rev=495859&r1=495858&r2=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java (original)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java Sat Jan 13 01:45:14 2007
@@ -21,13 +21,8 @@
import java.util.ArrayList;
import java.util.Iterator;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.parameters.ParameterException;
-import org.apache.avalon.framework.parameters.Parameterizable;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.excalibur.store.Store;
import org.apache.excalibur.store.StoreJanitor;
@@ -52,29 +47,35 @@
*
* @version $Id$
*/
-public class StoreJanitorImpl extends AbstractLogEnabled
- implements StoreJanitor, Parameterizable, ThreadSafe,
- Initializable, Disposable,
- Runnable {
+public class StoreJanitorImpl implements StoreJanitor, Runnable {
// Note: this class doesn't need to be Startable. This allows the janitor thread to be
// lazily created the first time a store registers itsefl
+ private static final int FREE_MEMORY = 1024 * 1024;
+ private static final int HEAP_SIZE = 66600000;
+ private static final int CLEAN_UP_THREAD_INTERVAL = 10 * 1000;
+ private static final boolean ADAPTIVE_THREAD_INTERVAL = false;
+ private static final int PERCENT_TO_FREE = 10;
+
+ /** By default we use the logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
+
// Configuration parameters
- private int minFreeMemory = -1;
- private int maxHeapSize = -1;
- private int threadInterval = -1;
+ private int minFreeMemory = FREE_MEMORY;
+ private int maxHeapSize = HEAP_SIZE;
+ private int threadInterval = CLEAN_UP_THREAD_INTERVAL;
private int minThreadInterval = 500;
- private boolean adaptiveThreadInterval;
+ private boolean adaptiveThreadInterval = ADAPTIVE_THREAD_INTERVAL;
private int priority = -1;
- private double fraction;
+ private double fraction = PERCENT_TO_FREE / 100.0D;
private Runtime jvm;
private ArrayList storelist;
private int index = -1;
/** Should the gc be called on low memory? */
- protected boolean invokeGC;
+ protected boolean invokeGC = false;
private boolean doRun;
@@ -94,36 +95,111 @@
/**
- * Parameterize the StoreJanitorImpl.
+ * How much free memory shall be available in the jvm?
+ * If not specified, defaults to 1Mb.
+ *
+ * @param freeMemory
+ */
+ public void setFreeMemory(int freeMemory) {
+ this.minFreeMemory = freeMemory;
+ }
+
+ /**
+ * How much memory at max jvm can consume?
+ * The default max heapsize for Sun's JVM is (almost) 64Mb,
+ * can be increased by specifying -Xmx command line parameter.
+ * If not specified, defaults to 66600000 bytes.
+ *
+ * @param heapSize
+ */
+ public void setHeapSize(int heapSize) {
+ this.maxHeapSize = heapSize;
+ }
+
+ /**
+ * How often shall the cleanup thread check memory?
+ * If not specified, defaults to 10 seconds.
+ *
+ * @param cleanupThreadInterval
+ */
+ public void setCleanupThreadInterval(int cleanupThreadInterval) {
+ this.threadInterval = cleanupThreadInterval * 1000;
+ }
+
+ /**
+ * Experimental adaptive algorithm for cleanup interval
+ *
+ * @param adaptiveThreadInterval
+ */
+ public void setAdaptiveThreadInterval(boolean adaptiveThreadInterval) {
+ this.adaptiveThreadInterval = adaptiveThreadInterval;
+ }
+
+ /**
+ * What percent of the store elements shall be dropped on low memory?
+ * If not specified, defaults to 10%
+ *
+ * @param percentToFree
+ */
+ public void setPercentToFree(double percentToFree) {
+ this.fraction = percentToFree / 100.0D;
+ }
+
+ /**
+ * Shall garbage collector be invoked on low memory?
+ * If not specified, defaults to false.
+ *
+ * @param invokeGC
+ */
+ public void setInvokeGC(boolean invokeGC) {
+ this.invokeGC = invokeGC;
+ }
+
+ /**
+ * What should be the priority of the cleanup thread?
+ * This property is used only by older implementation of the janitor.
+ * New implementation uses centrally configured thread pool (see
+ * thread-pools element below).
+ *
+ * @param threadPriority
+ */
+ public void setThreadPriority(int threadPriority) {
+ this.priority = threadPriority;
+ }
+
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ public void setLogger(Log l) {
+ this.logger = l;
+ }
+
+ /**
+ * Initialize the StoreJanitorImpl.
+ * @throws Exception
*/
- public void parameterize(Parameters params) throws ParameterException {
+ public void init() throws Exception {
this.jvm = Runtime.getRuntime();
- this.minFreeMemory = params.getParameterAsInteger("freememory", 1024 * 1024);
- this.maxHeapSize = params.getParameterAsInteger("heapsize", 66600000);
- // Parameter value is in seconds, converted to millis
- this.threadInterval = params.getParameterAsInteger("cleanupthreadinterval", 10) * 1000;
- this.adaptiveThreadInterval = params.getParameterAsBoolean("adaptivethreadinterval", false);
- this.priority = params.getParameterAsInteger("threadpriority", Thread.currentThread().getPriority());
- int percent = params.getParameterAsInteger("percent_to_free", 10);
- this.invokeGC = params.getParameterAsBoolean("invokegc", this.invokeGC);
+ if (this.priority == -1)
+ this.priority = Thread.currentThread().getPriority();
if (getMinFreeMemory() < 1) {
- throw new ParameterException("StoreJanitorImpl freememory parameter has to be greater then 1");
+ throw new Exception("StoreJanitorImpl freememory parameter has to be greater then 1");
}
if (getMaxHeapSize() < 1) {
- throw new ParameterException("StoreJanitorImpl heapsize parameter has to be greater then 1");
+ throw new Exception("StoreJanitorImpl heapsize parameter has to be greater then 1");
}
if (getThreadInterval() < 1) {
- throw new ParameterException("StoreJanitorImpl cleanupthreadinterval parameter has to be greater then 1");
+ throw new Exception("StoreJanitorImpl cleanupthreadinterval parameter has to be greater then 1");
}
if (getPriority() < 1 || getPriority() > 10) {
- throw new ParameterException("StoreJanitorImpl threadpriority has to be between 1 and 10");
+ throw new Exception("StoreJanitorImpl threadpriority has to be between 1 and 10");
}
- if (percent > 100 && percent < 1) {
- throw new ParameterException("StoreJanitorImpl percent_to_free, has to be between 1 and 100");
+ if (fraction > 1 && fraction < 0.01) {
+ throw new Exception("StoreJanitorImpl percentToFree, has to be between 1 and 100");
}
- this.fraction = percent / 100.0D;
this.storelist = new ArrayList();
if (getLogger().isDebugEnabled()) {
@@ -132,12 +208,9 @@
getLogger().debug("thread interval=" + getThreadInterval());
getLogger().debug("adaptivethreadinterval=" + getAdaptiveThreadInterval());
getLogger().debug("priority=" + getPriority());
- getLogger().debug("percent=" + percent);
+ getLogger().debug("percent=" + fraction * 100);
getLogger().debug("invoke gc=" + this.invokeGC);
}
- }
-
- public void initialize() throws Exception {
doStart();
}
@@ -157,7 +230,7 @@
this.doRun = false;
}
- public void dispose() {
+ public void destroy() {
doStop();
}
Added: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml?view=auto&rev=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml (added)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml Sat Jan 13 01:45:14 2007
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- SVN $Id$ -->
+ <!-- Normally uses the org.apache.excalibur.store.impl.StoreJanitorImpl as
+ the default-class but as that uses its own Thread spawning there is
+ the org.apache.cocoon.components.store.impl.CocoonStoreJanitor class
+ to use a daemon thread from the org.apache.cocoon.components.thread.RunnableManager
+ component
+ NOT: As soon as our patch has been accepted by the Excalibur community and an
+ excalibur-store has been release we can switch back to the original
+ org.apache.excalibur.store.impl.StoreJanitorImpl class
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <!--+
+ | Store Janitor: the store garbage collector and memory usage controller.
+ |
+ | WARNING: Be careful with the heapsize and freememory parameters.
+ | Wrong values can cause high cpu usage.
+ |
+ | Example configuration:
+ | Jvm settings:
+ | -Xmx200000000
+ | store-janitor settings:
+ | <parameter name="freememory" value="5000000"/>
+ | <parameter name="heapsize" value="196000000"/>
+ |
+ | It is recommended to have heapsize equal to -Xmx, especially on Sun's
+ | JVM which are unable to shrink its heap once it grows above minimum.
+ | Freememory should be greater than amount of memory necessary for normal
+ | application operation.
+ | BUT: The heap size of the memory of the JVM is a little bit less than
+ | the value you specify for -Xmx, so you have to set the heapsize
+ | for the store janitor to a value which is lower (2% less seems
+ | to be a working value).
+ +-->
+
+ <bean name="org.apache.excalibur.store.StoreJanitor" class="org.apache.cocoon.components.store.impl.CocoonStoreJanitor"
+ init-method="init" destroy-method="destroy">
+ <!--+
+ | How much free memory shall be available in the jvm?
+ | If not specified, defaults to 1Mb.
+ +-->
+ <property name="freeMemory" value="2048000"/>
+ <!--+
+ | How much memory at max jvm can consume?
+ | The default max heapsize for Sun's JVM is (almost) 64Mb,
+ | can be increased by specifying -Xmx command line parameter.
+ | If not specified, defaults to 66600000 bytes.
+ +-->
+ <property name="heapSize" value="66600000"/>
+ <!--+
+ | How often shall the cleanup thread check memory?
+ | If not specified, defaults to 10 seconds.
+ +-->
+ <property name="cleanupThreadInterval" value="10"/>
+ <!--+
+ | Experimental adaptive algorithm for cleanup interval
+ <property name="adaptiveThreadInterval" value="true"/>
+ +-->
+ <!--+
+ | What percent of the store elements shall be dropped on low memory?
+ | If not specified, defaults to 10%
+ +-->
+ <property name="percentToFree" value="10"/>
+ <!--+
+ | Shall garbage collector be invoked on low memory?
+ | If not specified, defaults to false.
+ +-->
+ <property name="invokeGC" value="false"/>
+ <!--+
+ | Name of the thread pool to use.
+ | If not specified, defaults to 'daemon'.
+ +-->
+ <property name="threadPool" value="daemon"/>
+
+ <!--+
+ | What should be the priority of the cleanup thread?
+ | This property is used only by older implementation of the janitor.
+ | New implementation uses centrally configured thread pool (see
+ | thread-pools element below).
+ <property name="threadPriority" value="5"/>
+ +-->
+
+ <property name="runnableManager" ref="org.apache.cocoon.components.thread.RunnableManager"/>
+ </bean>
+</beans>
\ No newline at end of file
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-janitor.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml?view=auto&rev=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml (added)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml Sat Jan 13 01:45:14 2007
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- SVN $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <!--+
+ | Transient Store: holds objects that don't have to survive shutdown
+ |
+ | Common configuration parameters:
+ | maxobjects: Indicates how many objects will be held in the cache.
+ | When the number of maxobjects has been reached. The last object
+ | in the cache will be thrown out.
+ +-->
+ <bean name="org.apache.excalibur.store.Store/TransientStore" class="org.apache.cocoon.components.store.impl.DefaultTransientStore"
+ init-method="init" destroy-method="destroy">
+ <property name="maxObjects" value="${org.apache.cocoon.store.transient.maxobjects}"/>
+ <property name="storeJanitor" ref="org.apache.excalibur.store.StoreJanitor"/>
+ </bean>
+</beans>
\ No newline at end of file
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store-transient.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml?view=auto&rev=495859
==============================================================================
--- cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml (added)
+++ cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml Sat Jan 13 01:45:14 2007
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- SVN $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <!--+
+ | Store: generic store. The default implementation is an in-memory store
+ | backed by a disk store (based on EHCache). This forms a two-stage
+ | cache composed of a fast in-memory MRU front-end and a persistent
+ | back-end which stores the less-used objects.
+ |
+ | Common configuration parameters:
+ | maxobjects: Indicates how many objects will be held in the cache.
+ | When the number of maxobjects has been reached. The last object
+ | in the cache will be thrown out.
+ +-->
+ <bean name="org.apache.excalibur.store.Store" class="org.apache.cocoon.components.store.impl.EHDefaultStore"
+ init-method="init" destroy-method="destroy">
+ <property name="maxObjects" value="${org.apache.cocoon.store.maxobjects}"/>
+ <property name="useCacheDirectory" value="${org.apache.cocoon.store.use-cache-directory}"/>
+ <property name="storeJanitor" ref="org.apache.excalibur.store.StoreJanitor"/>
+ <property name="settings" ref="org.apache.cocoon.configuration.Settings"/>
+ </bean>
+
+ <!--
+ The persistent store is only an auxiliary store that shouldn't be
+ used by Cocoon users. It should only be used - if required - by
+ the Store. If we use JCS, we don't need a persistent store.
+ <bean name="org.apache.excalibur.store.Store/PersistentStore" class="org.apache.cocoon.components.store.impl.DefaultStore">
+ <property name="maxobjects" value="${org.apache.cocoon.store.maxobjects}"/>
+ </bean>
+ -->
+
+</beans>
\ No newline at end of file
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-store/cocoon-store-impl/src/main/resources/META-INF/cocoon/spring/cocoon-core-store.xml
------------------------------------------------------------------------------
svn:keywords = Id
Re: svn commit: r495859 - in /cocoon/trunk/core: cocoon-core/src/main/resources/org/apache/cocoon/
cocoon-store/cocoon-store-impl/ cocoon-store/cocoon-store-impl/src/main/java/org/apache/cocoon/components/store/impl/
cocoon-store/cocoon-store-impl/src/main...
Posted by Vadim Gritsenko <va...@reverycodes.com>.
danielf@apache.org wrote:
> POJOfied the cocoon-store-impl module. Needed to copy and adapt the
> MRUMemoryStore from Excalibur store to be able to POJOfy the
> DefaultStore and DefaultTransientStore. While adapting the
> MRUMemoryStore I commented away the instrumentation support as
> I don't know how it works. Should we support instrumentation
> and in that case should the Excalibur version be used?
Excalibur instrumentation support was removed long time ago from the trunk. So
no support for it is necessary.
Vadim