You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by tw...@apache.org on 2009/11/10 02:40:54 UTC
svn commit: r834295 - in /forrest/trunk/main: build.xml
java/org/apache/forrest/locationmap/LocationMapModule.java webapp/WEB-INF/
webapp/WEB-INF/cocoon.xconf webapp/WEB-INF/ehcache.xml
Author: twilliams
Date: Tue Nov 10 01:40:54 2009
New Revision: 834295
URL: http://svn.apache.org/viewvc?rev=834295&view=rev
Log:
Add cache config to get rid of failsafe warning. Finishing up FOR-1031
Added:
forrest/trunk/main/webapp/WEB-INF/ehcache.xml
Modified:
forrest/trunk/main/build.xml
forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java
forrest/trunk/main/webapp/WEB-INF/ (props changed)
forrest/trunk/main/webapp/WEB-INF/cocoon.xconf
Modified: forrest/trunk/main/build.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/main/build.xml?rev=834295&r1=834294&r2=834295&view=diff
==============================================================================
--- forrest/trunk/main/build.xml (original)
+++ forrest/trunk/main/build.xml Tue Nov 10 01:40:54 2009
@@ -456,8 +456,10 @@
<!-- Jar Cocoon classes -->
<!-- =================================================================== -->
<target name="jar" depends="init, compile">
- <jar destfile="${build.dir}/xml-forrest.jar"
- basedir="${build.classes}">
+ <jar destfile="${build.dir}/xml-forrest.jar">
+ <fileset dir="${build.classes}"/>
+ <fileset file="${forrest.core}/webapp/WEB-INF/ehcache.xml"/>
+
<manifest>
<section name="org/apache/forrest/">
<attribute name="Comment" value="Support classes for Apache Forrest"/>
Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java
URL: http://svn.apache.org/viewvc/forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java?rev=834295&r1=834294&r2=834295&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java Tue Nov 10 01:40:54 2009
@@ -18,11 +18,12 @@
import java.io.IOException;
import java.util.Collections;
-import java.util.Date;
import java.util.Iterator;
import java.util.Map;
-import java.util.HashMap;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
import org.apache.forrest.locationmap.lm.LocationMap;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
@@ -60,22 +61,19 @@
* </locationmap><br>
* <p>
* You can use the same actions and selectors like you can use
- * in any othe sitemap.
+ * in any other sitemap.
*/
public class LocationMapModule extends AbstractLogEnabled
implements InputModule, Serviceable, Configurable, Disposable, ThreadSafe {
-
- private static final Iterator ATTNAMES = Collections.EMPTY_LIST.iterator();
-
+
private ServiceManager m_manager;
private SourceResolver m_resolver;
private String m_src;
private SourceValidity m_srcVal;
private LocationMap m_lm;
- private boolean m_cacheAll;
- private int m_cacheTtl;
- private Date m_cacheLastLoaded;
- private Map m_locationsCache;
+ private boolean m_cacheAll;
+ private Cache m_cache;
+ private CacheManager m_cacheManager;
// ---------------------------------------------------- lifecycle
@@ -90,20 +88,23 @@
public void configure(Configuration configuration) throws ConfigurationException {
m_src = configuration.getChild("file").getAttribute("src");
m_cacheAll = configuration.getChild("cacheable").getValueAsBoolean(true);
- m_cacheTtl = configuration.getChild("cache-lifespan").getValueAsInteger();
+ Configuration oldCacheConf = configuration.getChild("cache-lifespan", false);
- debug("LM Configured cache? " + m_cacheAll);
- debug("LM Configured cache-lifespan: " + m_cacheTtl);
+ if(oldCacheConf != null) {
+ getLogger().warn("Locationmap cache configuration is deprecated through cocoon.xconf. "
+ + "Please use ehcache.xml instead.");
+ }
- if (m_cacheAll == true) {
- m_locationsCache = new HashMap();
- m_cacheLastLoaded = new Date();
+ if(m_cacheAll == true) {
+ m_cacheManager = new CacheManager();
+ m_cache = m_cacheManager.getCache("lm_Cache");
+ debug("LM caching enabled and configured.");
}
}
public void dispose() {
m_lm.dispose();
- m_locationsCache = null;
+ m_cacheManager.shutdown();
}
private LocationMap getLocationMap() throws Exception {
@@ -146,7 +147,6 @@
m_resolver.release(source);
}
}
- m_cacheLastLoaded = new Date();
return m_lm;
}
@@ -195,26 +195,14 @@
try {
if (this.m_cacheAll == true) {
- Date now = new Date();
- long cacheAge = now.getTime() - m_cacheLastLoaded.getTime();
- debug("LM Cache current age is: " + cacheAge + "ms");
-
- if (cacheAge > m_cacheTtl) {
- debug("LM Cache has expiring - contains " + m_locationsCache.size() + " objects.");
- synchronized (this) {
- m_locationsCache.clear();
- debug("LM Cache has expired - now contains " + m_locationsCache.size() + " objects.");
- }
- }
-
- hasBeenCached = m_locationsCache.containsKey(name);
- if (hasBeenCached == true && m_locationsCache.get(name)!=null) {
- result = m_locationsCache.get(name);
+ hasBeenCached = m_cache.isKeyInCache(name);
+ if (hasBeenCached == true && m_cache.get(name)!=null) {
+ result = m_cache.get(name).getObjectValue();
if (getLogger().isDebugEnabled()) {
getLogger().debug("Locationmap cached location returned for hint: " + name + " value: " + result);
}
- }else{
- result = getFreshResult(name, objectModel);
+ } else{
+ result = getFreshResult(name, objectModel);
}
}
@@ -254,10 +242,12 @@
result = getLocationMap().locate(name,objectModel);
if (m_cacheAll == true) {
- m_locationsCache.put(name,result);
- if (getLogger().isDebugEnabled()) {
+ Element elem = new Element(name, result);
+ m_cache.put(elem);
+
+ if (getLogger().isDebugEnabled()) {
getLogger().debug("Locationmap caching hint: " + name + " value: " + result);
- }
+ }
}
return result;
}
Propchange: forrest/trunk/main/webapp/WEB-INF/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Nov 10 01:40:54 2009
@@ -0,0 +1 @@
+.cocoon.xconf.swp
Modified: forrest/trunk/main/webapp/WEB-INF/cocoon.xconf
URL: http://svn.apache.org/viewvc/forrest/trunk/main/webapp/WEB-INF/cocoon.xconf?rev=834295&r1=834294&r2=834295&view=diff
==============================================================================
--- forrest/trunk/main/webapp/WEB-INF/cocoon.xconf (original)
+++ forrest/trunk/main/webapp/WEB-INF/cocoon.xconf Tue Nov 10 01:40:54 2009
@@ -264,7 +264,6 @@
logger="core.modules.mapper.lm" name="lm">
<file src="cocoon://locationmap.xml"/>
<cacheable>true</cacheable>
- <cache-lifespan>100000</cache-lifespan>
</component-instance>
</input-modules>
Added: forrest/trunk/main/webapp/WEB-INF/ehcache.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/main/webapp/WEB-INF/ehcache.xml?rev=834295&view=auto
==============================================================================
--- forrest/trunk/main/webapp/WEB-INF/ehcache.xml (added)
+++ forrest/trunk/main/webapp/WEB-INF/ehcache.xml Tue Nov 10 01:40:54 2009
@@ -0,0 +1,79 @@
+<?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.
+-->
+<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="${diskstorepath}"/>
+
+ <!--Default Cache configuration. These will be applied to caches programmatically created through
+ the CacheManager.
+
+ The following attributes are required:
+
+ 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="0"
+ timeToLiveSeconds="0"
+ overflowToDisk="true"
+ diskPersistent="true"
+ diskExpiryThreadIntervalSeconds="120"
+ />
+
+ <cache name="lm_Cache"
+ maxElementsInMemory="10000"
+ eternal="false"
+ overflowToDisk="false"
+ timeToIdleSeconds="0"
+ timeToLiveSeconds="0"
+ diskPersistent="false"
+ diskExpiryThreadIntervalSeconds="120"
+ memoryStoreEvictionPolicy="LFU"
+ />
+</ehcache>
Re: svn commit: r834295 - in /forrest/trunk/main: build.xml
java/org/apache/forrest/locationmap/LocationMapModule.java webapp/WEB-INF/
webapp/WEB-INF/cocoon.xconf webapp/WEB-INF/ehcache.xml
Posted by Brian M Dube <bd...@apache.org>.
On Mon, Nov 09, 2009 at 09:22:49PM -0800, Brian M Dube wrote:
> On Mon, Nov 09, 2009 at 08:46:03PM -0800, Brian M Dube wrote:
> > On Tue, Nov 10, 2009 at 01:40:54AM -0000, twilliams@apache.org wrote:
> > > Author: twilliams
> > > Date: Tue Nov 10 01:40:54 2009
> > > New Revision: 834295
> > >
> > > URL: http://svn.apache.org/viewvc?rev=834295&view=rev
> > > Log:
> > > Add cache config to get rid of failsafe warning. Finishing up FOR-1031
> >
> > When running `forrest' in site-author to verify the patch in FOR-1182,
> > there are new exceptions due to LocationMapModule and build did not
> > succeed.
>
> I updated my local copy to the revision before this change to get
> FOR-1181 and FOR-1182 done. I have not reverted your commit, but given
> that I could not build the site, I suspect we'll be hearing Forrestbot
> complain this evening.
Please excuse my noise. I forgot to rebuild after a change that
affects core Java code.
Brian
Re: svn commit: r834295 - in /forrest/trunk/main: build.xml
java/org/apache/forrest/locationmap/LocationMapModule.java webapp/WEB-INF/
webapp/WEB-INF/cocoon.xconf webapp/WEB-INF/ehcache.xml
Posted by Brian M Dube <bd...@apache.org>.
On Mon, Nov 09, 2009 at 08:46:03PM -0800, Brian M Dube wrote:
> On Tue, Nov 10, 2009 at 01:40:54AM -0000, twilliams@apache.org wrote:
> > Author: twilliams
> > Date: Tue Nov 10 01:40:54 2009
> > New Revision: 834295
> >
> > URL: http://svn.apache.org/viewvc?rev=834295&view=rev
> > Log:
> > Add cache config to get rid of failsafe warning. Finishing up FOR-1031
>
> When running `forrest' in site-author to verify the patch in FOR-1182,
> there are new exceptions due to LocationMapModule and build did not
> succeed.
I updated my local copy to the revision before this change to get
FOR-1181 and FOR-1182 done. I have not reverted your commit, but given
that I could not build the site, I suspect we'll be hearing Forrestbot
complain this evening.
Brian
Re: svn commit: r834295 - in /forrest/trunk/main: build.xml
java/org/apache/forrest/locationmap/LocationMapModule.java webapp/WEB-INF/
webapp/WEB-INF/cocoon.xconf webapp/WEB-INF/ehcache.xml
Posted by Brian M Dube <bd...@apache.org>.
On Tue, Nov 10, 2009 at 01:40:54AM -0000, twilliams@apache.org wrote:
> Author: twilliams
> Date: Tue Nov 10 01:40:54 2009
> New Revision: 834295
>
> URL: http://svn.apache.org/viewvc?rev=834295&view=rev
> Log:
> Add cache config to get rid of failsafe warning. Finishing up FOR-1031
When running `forrest' in site-author to verify the patch in FOR-1182,
there are new exceptions due to LocationMapModule and build did not
succeed.
Brian