cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store EHStore.java
Date Mon, 08 Mar 2004 22:44:51 GMT
unico       2004/03/08 14:44:51

  Modified:    src/blocks/scratchpad/java/org/apache/cocoon/components/store
                        EHStore.java
  Log:
  - implement more lifecycle stages
  - add debug logging
  - addTODO message
  
  Revision  Changes    Path
  1.2       +41 -5     cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java
  
  Index: EHStore.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/EHStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EHStore.java	8 Mar 2004 21:36:26 -0000	1.1
  +++ EHStore.java	8 Mar 2004 22:44:51 -0000	1.2
  @@ -25,55 +25,85 @@
   import net.sf.ehcache.CacheManager;
   import net.sf.ehcache.Element;
   
  +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.excalibur.store.Store;
   
   /**
    * Store implementation based on EHCache.
    * (http://ehcache.sourceforge.net/)
  + * 
  + * TODO: CacheManager expects to be a singleton. So configuring
  + * multiple EHStore intances could lead to errors.
    */
  -public class EHStore extends AbstractLogEnabled implements Store, Parameterizable {
  +public class EHStore extends AbstractLogEnabled 
  +implements Store, Parameterizable, Initializable, Disposable, ThreadSafe {
       
       private Cache m_cache;
       private CacheManager m_cacheManager;
       
       private String m_cacheName;
       private int m_maximumSize;
  +    private boolean m_overflowToDisk;
       
       public EHStore() {
       }
       
       public void parameterize(Parameters parameters) throws ParameterException {
           m_cacheName = parameters.getParameter("cache-name","main");
  -        m_maximumSize = parameters.getParameterAsInteger("max-objects",100);
  +        m_maximumSize = parameters.getParameterAsInteger("maxobjects",100);
  +        m_overflowToDisk = parameters.getParameterAsBoolean("overflow-to-disk",true);
       }
       
       public void initialize() throws Exception {
           m_cacheManager = CacheManager.create();
  -        m_cache = new Cache(m_cacheName,m_maximumSize,true,false,0,0);
  +        m_cache = new Cache(m_cacheName,m_maximumSize,m_overflowToDisk,true,0,0);
           m_cacheManager.addCache(m_cache);
       }
       
  +    public void dispose() {
  +        m_cacheManager.shutdown();
  +        m_cacheManager = null;
  +        m_cache = null;
  +    }
  +    
       /* (non-Javadoc)
        * @see org.apache.excalibur.store.Store#free()
        */
       public Object get(Object key) {
  +        Object value = null;
           try {
  -            return m_cache.get((Serializable) key);
  +            final Element element = m_cache.get((Serializable) key);
  +            if (element != null) {
  +                value = element.getValue();
  +            }
           }
           catch (CacheException e) {
               getLogger().error("Failure retrieving object from store", e);
           }
  -        return null;
  +        if (getLogger().isDebugEnabled()) {
  +            if (value != null) {
  +                getLogger().debug("Found key: " + key);
  +            } 
  +            else {
  +                getLogger().debug("NOT Found key: " + key);
  +            }
  +        }
  +        return value;
       }
   
       /* (non-Javadoc)
        * @see org.apache.excalibur.store.Store#free()
        */
       public void store(Object key, Object value) throws IOException {
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Store object " + value + " with key "+ key);
  +        }
           final Element element = new Element((Serializable) key, (Serializable) value);
           m_cache.put(element);
       }
  @@ -88,6 +118,9 @@
        * @see org.apache.excalibur.store.Store#remove(java.lang.Object)
        */
       public void remove(Object key) {
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Removing item " + key);
  +        }
           m_cache.remove((Serializable) key);
       }
   
  @@ -95,6 +128,9 @@
        * @see org.apache.excalibur.store.Store#clear()
        */
       public void clear() {
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Clearing the store");
  +        }
           try {
               m_cache.removeAll();
           }
  
  
  

Mime
View raw message