You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by wo...@apache.org on 2008/10/16 17:45:27 UTC
svn commit: r705265 - in
/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade:
components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/
components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/
components/jetspee...
Author: woonsan
Date: Thu Oct 16 08:45:26 2008
New Revision: 705265
URL: http://svn.apache.org/viewvc?rev=705265&view=rev
Log:
[JS2-761] ConcurrentModificationException in FileCache after jetspeed 2.1.2 installation
Modified FileCache to use an injected JetspeedCache instance. It doesn't need to synchronize any object any more.
Modified:
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCache.java
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCacheEntryImpl.java
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/test/java/org/apache/jetspeed/cache/file/TestFileCache.java
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/cache.xml
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/importer-page-manager.xml
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-base.xml
portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/ehcache.xml
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java Thu Oct 16 08:45:26 2008
@@ -17,9 +17,11 @@
package org.apache.jetspeed.cache.impl;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import net.sf.ehcache.CacheException;
@@ -31,11 +33,14 @@
import org.apache.jetspeed.cache.CacheElement;
import org.apache.jetspeed.cache.DistributedCacheObject;
import org.apache.jetspeed.cache.JetspeedCache;
+import org.apache.jetspeed.cache.JetspeedCacheEventListener;
import org.apache.jetspeed.request.RequestContext;
public class EhCacheDistributedImpl extends EhCacheImpl implements JetspeedCache, CacheEventListener
{
+ protected List localListeners = new ArrayList();
+ protected List remoteListeners = new ArrayList();
private Map refList = Collections.synchronizedMap(new HashMap());
@@ -121,7 +126,29 @@
return ehcache.removeQuiet(key);
}
+
+ public void clear()
+ {
+ super.clear();
+ notifyListeners(true, CacheElement.ActionRemoved,null,null);
+ }
+ public void addEventListener(JetspeedCacheEventListener listener, boolean local)
+ {
+ if (local)
+ localListeners.add(listener);
+ else
+ remoteListeners.add(listener);
+ }
+
+ public void removeEventListener(JetspeedCacheEventListener listener, boolean local)
+ {
+ if (local)
+ localListeners.remove(listener);
+ else
+ remoteListeners.remove(listener);
+ }
+
public void evictContentForUser(RequestContext context)
{
return;
@@ -153,6 +180,40 @@
}
}
+ protected void notifyListeners(boolean local, int action, Object key, Object value)
+ {
+ List listeners = (local?localListeners:remoteListeners);
+ for (int ix = 0; ix < listeners.size(); ix++)
+ {
+ try
+ {
+ JetspeedCacheEventListener listener = (JetspeedCacheEventListener)listeners.get(ix);
+ switch (action)
+ {
+ case CacheElement.ActionAdded:
+ listener.notifyElementAdded(this,local, key,value);
+ break;
+ case CacheElement.ActionChanged:
+ listener.notifyElementChanged(this,local, key,value);
+ break;
+ case CacheElement.ActionRemoved:
+ listener.notifyElementRemoved(this,local, key,value);
+ break;
+ case CacheElement.ActionEvicted:
+ listener.notifyElementEvicted(this,local, key,value);
+ break;
+ case CacheElement.ActionExpired:
+ listener.notifyElementExpired(this,local, key,value);
+ break;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
public void notifyElement( Ehcache cache, boolean local,Element arg1, int action)
{
if (cache != this.ehcache)
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java Thu Oct 16 08:45:26 2008
@@ -17,11 +17,13 @@
package org.apache.jetspeed.cache.impl;
import java.io.Serializable;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import net.sf.ehcache.event.CacheEventListener;
import org.apache.jetspeed.cache.CacheElement;
import org.apache.jetspeed.cache.ContentCacheKey;
@@ -32,12 +34,12 @@
public class EhCacheImpl implements JetspeedCache
{
protected Ehcache ehcache;
- protected List localListeners = new ArrayList();
- protected List remoteListeners = new ArrayList();
+ protected Map<JetspeedCacheEventListener, CacheEventListener> cacheEventListenersMap;
public EhCacheImpl(Ehcache ehcache)
{
this.ehcache = ehcache;
+ this.cacheEventListenersMap = new HashMap<JetspeedCacheEventListener, CacheEventListener>();
}
public CacheElement get(Object key)
@@ -68,7 +70,6 @@
{
EhCacheElementImpl impl = (EhCacheElementImpl)element;
ehcache.put(impl.getImplElement());
- notifyListeners(true, CacheElement.ActionAdded,impl.getKey(),impl.getContent());
}
public CacheElement createElement(Object key, Object content)
@@ -84,8 +85,6 @@
if (element == null)
return false;
boolean isRemoved = ehcache.remove(key);
- if (isRemoved)
- notifyListeners(true, CacheElement.ActionRemoved,key,null);
return isRemoved;
}
@@ -100,7 +99,6 @@
public void clear()
{
ehcache.removeAll();
- notifyListeners(true, CacheElement.ActionRemoved,null,null);
}
public void evictContentForUser(String username)
@@ -113,22 +111,69 @@
return;
}
- public void addEventListener(JetspeedCacheEventListener listener, boolean local)
+ public void addEventListener(final JetspeedCacheEventListener listener, final boolean local)
{
- if (local)
- localListeners.add(listener);
- else
- remoteListeners.add(listener);
-
+ CacheEventListener cacheEventListener = new CacheEventListener()
+ {
+ public void notifyElementEvicted(Ehcache cache, Element element)
+ {
+ listener.notifyElementEvicted(EhCacheImpl.this, local, element.getKey(), element.getValue());
+ }
+
+ public void notifyElementExpired(Ehcache cache, Element element)
+ {
+ listener.notifyElementExpired(EhCacheImpl.this, local, element.getKey(), element.getValue());
+ }
+
+ public void notifyElementPut(Ehcache cache, Element element)
+ {
+ listener.notifyElementAdded(EhCacheImpl.this, local, element.getKey(), element.getValue());
+ }
+
+ public void notifyElementUpdated(Ehcache cache, Element element)
+ {
+ listener.notifyElementChanged(EhCacheImpl.this, local, element.getKey(), element.getValue());
+ }
+
+ public void notifyElementRemoved(Ehcache cache, Element element)
+ {
+ listener.notifyElementRemoved(EhCacheImpl.this, local, element.getKey(), null);
+ }
+
+ public void notifyRemoveAll(Ehcache cache)
+ {
+ listener.notifyElementRemoved(EhCacheImpl.this, local, null, null);
+ }
+
+ public void dispose()
+ {
+ }
+
+ public Object clone()
+ {
+ return this;
+ }
+ };
+
+ ehcache.getCacheEventNotificationService().registerListener(cacheEventListener);
}
public void removeEventListener(JetspeedCacheEventListener listener, boolean local)
{
- if (local)
- localListeners.remove(listener);
- else
- remoteListeners.remove(listener);
-
+ CacheEventListener cacheEventListener = this.cacheEventListenersMap.get(listener);
+
+ if (cacheEventListener != null)
+ ehcache.getCacheEventNotificationService().unregisterListener(cacheEventListener);
+ }
+
+ public int getSize()
+ {
+ return ehcache.getSize();
+ }
+
+ public List getKeys()
+ {
+ return ehcache.getKeys();
}
// ------------------------------------------------------
@@ -142,41 +187,6 @@
{
}
- protected void notifyListeners(boolean local, int action, Object key, Object value)
- {
- List listeners = (local?localListeners:remoteListeners);
- for (int ix = 0; ix < listeners.size(); ix++)
- {
- try
- {
- JetspeedCacheEventListener listener = (JetspeedCacheEventListener)listeners.get(ix);
- switch (action)
- {
- case CacheElement.ActionAdded:
- listener.notifyElementAdded(this,local, key,value);
- break;
- case CacheElement.ActionChanged:
- listener.notifyElementChanged(this,local, key,value);
- break;
- case CacheElement.ActionRemoved:
- listener.notifyElementRemoved(this,local, key,value);
- break;
- case CacheElement.ActionEvicted:
- listener.notifyElementEvicted(this,local, key,value);
- break;
- case CacheElement.ActionExpired:
- listener.notifyElementExpired(this,local, key,value);
- break;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
-
- }
- }
- }
-
public ContentCacheKey createCacheKey(RequestContext rc, String windowId)
{
return null; // not implemented here
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCache.java?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCache.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCache.java Thu Oct 16 08:45:26 2008
@@ -17,19 +17,16 @@
package org.apache.jetspeed.cache.file;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.Map;
-import java.util.HashMap;
import java.util.List;
-import java.util.LinkedList;
-import java.util.Iterator;
import java.io.File;
import java.io.FileNotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.JetspeedCache;
+import org.apache.jetspeed.cache.JetspeedCacheEventListener;
/**
* FileCache keeps a cache of files up-to-date with a most simple eviction policy.
@@ -41,65 +38,38 @@
* @version $Id$
*/
-public class FileCache implements java.util.Comparator
+public class FileCache
{
protected long scanRate = 300; // every 5 minutes
- protected int maxSize = 100; // maximum of 100 items
- protected List listeners = new LinkedList();
private FileCacheScanner scanner = null;
- private Map cache = null;
+ private JetspeedCache cache = null;
private final static Log log = LogFactory.getLog(FileCache.class);
/**
- * Default constructor. Use default values for scanReate and maxSize
+ * Set cache
*
+ * @param cache the physical cache implementation
*/
- public FileCache()
+ public FileCache(JetspeedCache cache)
{
- cache = Collections.synchronizedMap(new HashMap());
+ this.cache = cache;
this.scanner = new FileCacheScanner();
this.scanner.setDaemon(true);
}
/**
- * Set scanRate and maxSize
+ * Set cache, scanRate and maxSize
*
+ * @param cache the physical cache implementation
* @param scanRate how often in seconds to refresh and evict from the cache
* @param maxSize the maximum allowed size of the cache before eviction starts
*/
- public FileCache(long scanRate,
- int maxSize)
+ public FileCache(JetspeedCache cache, long scanRate)
{
-
- cache = Collections.synchronizedMap(new HashMap());
-
- this.scanRate = scanRate;
- this.maxSize = maxSize;
- this.scanner = new FileCacheScanner();
- this.scanner.setDaemon(true);
- }
-
- /**
- * Set all parameters on the cache
- *
- * @param initialCapacity the initial size of the cache as passed to HashMap
- * @param loadFactor how full the hash table is allowed to get before increasing
- * @param scanRate how often in seconds to refresh and evict from the cache
- * @param maxSize the maximum allowed size of the cache before eviction starts
- */
- public FileCache(int initialCapacity,
- int loadFactor,
- long scanRate,
- int maxSize)
- {
- cache = Collections.synchronizedMap(new HashMap(initialCapacity, loadFactor));
-
+ this(cache);
this.scanRate = scanRate;
- this.maxSize = maxSize;
- this.scanner = new FileCacheScanner();
- this.scanner.setDaemon(true);
}
/**
@@ -123,26 +93,6 @@
}
/**
- * Set the new maximum size of the cache
- *
- * @param maxSize the maximum size of the cache
- */
- public void setMaxSize(int maxSize)
- {
- this.maxSize = maxSize;
- }
-
- /**
- * Get the maximum size of the cache
- *
- * @return the current maximum size of the cache
- */
- public int getMaxSize()
- {
- return maxSize;
- }
-
- /**
* Gets an entry from the cache given a key
*
* @param key the key to look up the entry by
@@ -150,7 +100,15 @@
*/
public FileCacheEntry get(String key)
{
- return (FileCacheEntry) cache.get(key);
+ FileCacheEntry entry = null;
+ CacheElement element = this.cache.get(key);
+
+ if (element != null)
+ {
+ entry = (FileCacheEntry) element.getContent();
+ }
+
+ return entry;
}
/**
@@ -161,11 +119,13 @@
*/
public Object getDocument(String key)
{
- FileCacheEntry entry = (FileCacheEntry) cache.get(key);
+ FileCacheEntry entry = get(key);
+
if (entry != null)
{
return entry.getDocument();
}
+
return null;
}
@@ -176,14 +136,16 @@
* @param document the cached document
*/
public void put(File file, Object document)
- throws java.io.IOException
+ throws java.io.IOException
{
if(!file.exists())
{
throw new FileNotFoundException("File to cache: "+file.getAbsolutePath()+" does not exist.");
}
+
FileCacheEntry entry = new FileCacheEntryImpl(file, document);
- cache.put(file.getCanonicalPath(), entry);
+ CacheElement element = this.cache.createElement(file.getCanonicalPath(), entry);
+ cache.put(element);
}
/**
@@ -193,15 +155,18 @@
* @param document the cached document
*/
public void put(String key, Object document, File rootFile)
- throws java.io.IOException
+ throws java.io.IOException
{
File file = new File(rootFile, key);
+
if(!file.exists())
{
throw new FileNotFoundException("File to cache: "+file.getAbsolutePath()+" does not exist.");
}
+
FileCacheEntry entry = new FileCacheEntryImpl(file, document);
- cache.put(key, entry);
+ CacheElement element = this.cache.createElement(key, entry);
+ this.cache.put(element);
}
/**
@@ -212,7 +177,8 @@
*/
public Object remove(String key)
{
- return cache.remove(key);
+ boolean removed = this.cache.remove(key);
+ return null;
}
@@ -221,9 +187,47 @@
*
* @param listener the event listener
*/
- public void addListener(FileCacheEventListener listener)
+ public void addListener(final FileCacheEventListener listener)
{
- listeners.add(listener);
+ JetspeedCacheEventListener cacheEventListener = new JetspeedCacheEventListener()
+ {
+ public void notifyElementRemoved(JetspeedCache cache, boolean local, Object key, Object element)
+ {
+ }
+
+ public void notifyElementAdded(JetspeedCache cache, boolean local, Object key, Object element)
+ {
+ }
+
+ public void notifyElementChanged(JetspeedCache cache, boolean local, Object key, Object element)
+ {
+ try
+ {
+ listener.refresh((FileCacheEntry) element);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void notifyElementEvicted(JetspeedCache cache, boolean local, Object key, Object element)
+ {
+ try
+ {
+ listener.evict((FileCacheEntry) element);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ public void notifyElementExpired(JetspeedCache cache, boolean local, Object key, Object element)
+ {
+ }
+ };
+
+ this.cache.addEventListener(cacheEventListener, true);
}
/**
@@ -234,7 +238,6 @@
{
try
{
-
this.scanner.start();
}
catch (java.lang.IllegalThreadStateException e)
@@ -253,122 +256,12 @@
}
/**
- * Evicts entries based on last accessed time stamp
- *
- */
- protected void evict()
- {
- synchronized (cache)
- {
- if (this.getMaxSize() >= cache.size())
- {
- return;
- }
-
- List list = new LinkedList(cache.values());
- Collections.sort(list, this);
-
- int count = 0;
- int limit = cache.size() - this.getMaxSize();
-
- for (Iterator it = list.iterator(); it.hasNext(); )
- {
- if (count >= limit)
- {
- break;
- }
-
- FileCacheEntry entry = (FileCacheEntry) it.next();
- String key = null;
- try
- {
- key = entry.getFile().getCanonicalPath();
- }
- catch (java.io.IOException e)
- {
- log.error("Exception getting file path: ", e);
- }
- // notify that eviction will soon take place
- for (Iterator lit = this.listeners.iterator(); lit.hasNext(); )
- {
- FileCacheEventListener listener =
- (FileCacheEventListener) lit.next();
- try
- {
- listener.evict(entry);
- }
- catch (Exception e1)
- {
- log.warn("Unable to evict cache entry. "+e1.toString(), e1);
- }
- }
- cache.remove(key);
-
- count++;
- }
- }
- }
-
- /**
* Evicts all entries
*
*/
- public void evictAll()
+ public void evictAll()
{
- synchronized (cache)
- {
- // evict all cache entries
- List list = new LinkedList(cache.values());
- for (Iterator it = list.iterator(); it.hasNext(); )
- {
- // evict cache entry
- FileCacheEntry entry = (FileCacheEntry) it.next();
- // notify that eviction will soon take place
- for (Iterator lit = this.listeners.iterator(); lit.hasNext(); )
- {
- FileCacheEventListener listener =
- (FileCacheEventListener) lit.next();
- try
- {
- listener.evict(entry);
- }
- catch (Exception e1)
- {
- log.warn("Unable to evict cache entry. "+e1.toString(), e1);
- }
- }
- // remove from cache by key
- String key = null;
- try
- {
- key = entry.getFile().getCanonicalPath();
- }
- catch (java.io.IOException e)
- {
- log.error("Exception getting file path: ", e);
- }
- cache.remove(key);
- }
- }
- }
-
- /**
- * Comparator function for sorting by last accessed during eviction
- *
- */
- public int compare(Object o1, Object o2)
- {
- FileCacheEntry e1 = (FileCacheEntry)o1;
- FileCacheEntry e2 = (FileCacheEntry)o2;
- if (e1.getLastAccessed() < e2.getLastAccessed())
- {
- return -1;
- }
- else if (e1.getLastAccessed() == e2.getLastAccessed())
- {
- return 0;
- }
- return 1;
+ this.cache.clear();
}
/**
@@ -391,52 +284,42 @@
public void run()
{
boolean done = false;
-
+
try
{
while(!done)
{
try
{
- int count = 0;
- Collection values = Collections.synchronizedCollection(FileCache.this.cache.values());
- synchronized (values)
+ for (Object key : getKeys())
{
- for (Iterator it = values.iterator(); it.hasNext(); )
+ CacheElement element = cache.get(key);
+
+ if (element != null)
{
- FileCacheEntry entry = (FileCacheEntry) it.next();
- Date modified = new Date(entry.getFile().lastModified());
-
+ FileCacheEntry entry = (FileCacheEntry) element.getContent();
+ File file = entry.getFile();
+ Date modified = new Date(file.lastModified());
+
if (modified.after(entry.getLastModified()))
- {
- for (Iterator lit = FileCache.this.listeners.iterator(); lit.hasNext(); )
+ {
+ FileCacheEntry updatedEntry = new FileCacheEntryImpl(file, entry.getDocument());
+ CacheElement updatedElement = cache.createElement(key, updatedEntry);
+ cache.put(updatedElement);
+
+ if (log.isDebugEnabled())
{
- FileCacheEventListener listener =
- (FileCacheEventListener) lit.next();
- try
- {
- listener.refresh(entry);
- }
- catch (Exception e1)
- {
- log.warn("Unable to refresh cached document: "+e1.toString(), e1);
- }
- entry.setLastModified(modified);
+ log.debug("page file has been updated: " + key);
}
}
- count++;
}
}
- if (count > FileCache.this.getMaxSize())
- {
- FileCache.this.evict();
- }
}
catch (Exception e)
{
log.error("FileCache Scanner: Error in iteration...", e);
}
-
+
sleep(FileCache.this.getScanRate() * 1000);
if (this.stopping)
@@ -459,19 +342,18 @@
*
* @return iterator over the cache values
*/
- public Iterator getIterator()
+ public List getKeys()
{
- return cache.values().iterator();
+ return cache.getKeys();
}
/**
- * get the size of the cache
- *
- * @return the size of the cache
- */
+ * get the size of the cache
+ *
+ * @return the size of the cache
+ */
public int getSize()
{
- return cache.size();
+ return cache.getSize();
}
}
-
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCacheEntryImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCacheEntryImpl.java?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCacheEntryImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/main/java/org/apache/jetspeed/cache/file/FileCacheEntryImpl.java Thu Oct 16 08:45:26 2008
@@ -18,6 +18,7 @@
package org.apache.jetspeed.cache.file;
import java.io.File;
+import java.io.Serializable;
import java.util.Date;
/**
@@ -27,7 +28,7 @@
* @version $Id$
*/
-public class FileCacheEntryImpl implements FileCacheEntry
+public class FileCacheEntryImpl implements FileCacheEntry, Serializable
{
protected File file;
protected Object document;
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/test/java/org/apache/jetspeed/cache/file/TestFileCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/test/java/org/apache/jetspeed/cache/file/TestFileCache.java?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/test/java/org/apache/jetspeed/cache/file/TestFileCache.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-file-cache/src/test/java/org/apache/jetspeed/cache/file/TestFileCache.java Thu Oct 16 08:45:26 2008
@@ -22,12 +22,18 @@
import java.io.FileInputStream;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.impl.EhCacheImpl;
import org.apache.jetspeed.test.JetspeedTestCase;
@@ -66,7 +72,13 @@
{
super.setUp();
- cache = new FileCache(SCAN_RATE, CACHE_SIZE);
+ // initialize ehCache
+ CacheManager cacheManager = new CacheManager();
+ Cache ehPageFileCache = new Cache("ehPageFileCache", CACHE_SIZE, false, false, 0, 0);
+ cacheManager.addCache(ehPageFileCache);
+ ehPageFileCache.setCacheManager(cacheManager);
+
+ cache = new FileCache(new EhCacheImpl(ehPageFileCache), SCAN_RATE);
}
/**
@@ -99,6 +111,7 @@
// load the Cache
File directory = new File(getBaseDir() + TEST_DIRECTORY);
File[] files = directory.listFiles();
+ int fileCount = 0;
for (int ix=0; ix < files.length; ix++)
{
if (files[ix].isDirectory() || files[ix].getName().equals(".cvsignore"))
@@ -107,11 +120,12 @@
}
String testData = readFile(files[ix]);
cache.put(files[ix], testData);
+ ++fileCount;
}
- assertTrue(cache.getSize() == 32);
+ assertTrue(cache.getSize() == Math.min(CACHE_SIZE, fileCount));
- dumpCache(cache.getIterator());
+ dumpCache(cache.getKeys());
cache.addListener(this);
@@ -120,9 +134,9 @@
Thread.sleep(2000);
- assertTrue(cache.getSize() == 20);
+ assertTrue(cache.getSize() == Math.min(CACHE_SIZE, fileCount));
- dumpCache(cache.getIterator());
+ dumpCache(cache.getKeys());
// Reload files array to get the files back in the correct order
// because the cache CAN have reordered them while evicting.
@@ -133,11 +147,11 @@
// Note: this is only an issue for the test itself and not for the
// cache as such.
- Iterator it = cache.getIterator();
- for ( int ix = 0; it.hasNext(); ix++ )
+ int ix = 0;
+ for (Object key : cache.getKeys())
{
- FileCacheEntry entry = (FileCacheEntry) it.next();
- files[ix] = entry.getFile();
+ FileCacheEntry entry = (FileCacheEntry) cache.get((String) key);
+ files[ix++] = entry.getFile();
}
String stuff = (String) cache.getDocument(files[18].getCanonicalPath());
@@ -220,11 +234,11 @@
System.out.println("entry is evicting: " + entry.getFile().getName());
}
- private void dumpCache(Iterator it)
+ private void dumpCache(List keys)
{
- for ( ; it.hasNext(); )
+ for (Object key : keys)
{
- FileCacheEntry entry = (FileCacheEntry) it.next();
+ FileCacheEntry entry = (FileCacheEntry) cache.get((String) key);
System.out.println(entry.getFile().getName());
}
}
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCache.java Thu Oct 16 08:45:26 2008
@@ -16,6 +16,8 @@
*/
package org.apache.jetspeed.cache;
+import java.util.List;
+
import org.apache.jetspeed.request.RequestContext;
/**
@@ -120,4 +122,18 @@
void addEventListener(JetspeedCacheEventListener listener, boolean local);
void removeEventListener(JetspeedCacheEventListener listener, boolean local);
-}
\ No newline at end of file
+
+ /**
+ * Returns a list of all elements in the cache, whether or not they are expired.
+ * The returned keys are unique and can be considered a set.
+ * @return the list of keys
+ */
+ List getKeys();
+
+ /**
+ * get the size of the cache
+ *
+ * @return the size of the cache
+ */
+ int getSize();
+}
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/cache.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/cache.xml?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/cache.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/cache.xml Thu Oct 16 08:45:26 2008
@@ -228,5 +228,35 @@
<ref bean="ehPortletWindowCache" />
</constructor-arg>
</bean>
+
+ <bean id="ehInternalPageFileCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+ <meta key="j2:cat" value="default,cache" />
+ <property name="cacheManager">
+ <ref local="cacheManager" />
+ </property>
+ <property name="cacheName" value="pageFileCache" />
+ </bean>
+
+ <bean id="internalPageFileCache" class="org.apache.jetspeed.cache.impl.EhCacheImpl">
+ <meta key="j2:cat" value="default,cache" />
+ <constructor-arg>
+ <ref bean="ehInternalPageFileCache" />
+ </constructor-arg>
+ </bean>
+
+ <bean id="ehInternalImportPageFileCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+ <meta key="j2:cat" value="default,cache" />
+ <property name="cacheManager">
+ <ref local="cacheManager" />
+ </property>
+ <property name="cacheName" value="importPageFileCache" />
+ </bean>
+
+ <bean id="internalImportPageFileCache" class="org.apache.jetspeed.cache.impl.EhCacheImpl">
+ <meta key="j2:cat" value="default,cache" />
+ <constructor-arg>
+ <ref bean="ehInternalImportPageFileCache" />
+ </constructor-arg>
+ </bean>
</beans>
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/importer-page-manager.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/importer-page-manager.xml?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/importer-page-manager.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/importer-page-manager.xml Thu Oct 16 08:45:26 2008
@@ -159,13 +159,13 @@
<bean id="ImportPageFileCache" class="org.apache.jetspeed.cache.file.FileCache" init-method="startFileScanner"
destroy-method="stopFileScanner">
<meta key="j2:cat" value="default" />
- <!-- Scan rate for changes in cached files on the file system -->
+ <!-- Internal cache -->
<constructor-arg index="0">
- <value>${page.file.cache.scanRate}</value>
+ <ref bean="internalImportPageFileCache" />
</constructor-arg>
- <!-- Cache size -->
+ <!-- Scan rate for changes in cached files on the file system -->
<constructor-arg index="1">
- <value>${page.file.cache.size}</value>
+ <value>${page.file.cache.scanRate}</value>
</constructor-arg>
</bean>
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-base.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-base.xml?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-base.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-base.xml Thu Oct 16 08:45:26 2008
@@ -40,13 +40,13 @@
<bean id="PageFileCache" class="org.apache.jetspeed.cache.file.FileCache" init-method="startFileScanner"
destroy-method="stopFileScanner">
<meta key="j2:cat" value="default,base" />
- <!-- Scan rate for changes in cached files on the file system -->
+ <!-- Internal cache -->
<constructor-arg index="0">
- <value>${page.file.cache.scanRate}</value>
+ <ref bean="internalPageFileCache" />
</constructor-arg>
- <!-- Cache size -->
+ <!-- Scan rate for changes in cached files on the file system -->
<constructor-arg index="1">
- <value>${page.file.cache.size}</value>
+ <value>${page.file.cache.scanRate}</value>
</constructor-arg>
</bean>
Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/ehcache.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/ehcache.xml?rev=705265&r1=705264&r2=705265&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/ehcache.xml (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/jetspeed-portal-resources/src/main/resources/db-ojb/ehcache.xml Thu Oct 16 08:45:26 2008
@@ -521,4 +521,24 @@
memoryStoreEvictionPolicy="LFU"
/>
+ <cache name="pageFileCache"
+ maxElementsInMemory="1000"
+ maxElementsOnDisk="1000"
+ eternal="false"
+ overflowToDisk="false"
+ timeToIdleSeconds="0"
+ timeToLiveSeconds="0"
+ memoryStoreEvictionPolicy="LFU"
+ />
+
+ <cache name="importPageFileCache"
+ maxElementsInMemory="1000"
+ maxElementsOnDisk="1000"
+ eternal="false"
+ overflowToDisk="false"
+ timeToIdleSeconds="0"
+ timeToLiveSeconds="0"
+ memoryStoreEvictionPolicy="LFU"
+ />
+
</ehcache>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org