cziegeler    2004/05/20 03:48:16

  Modified:    src/java/org/apache/cocoon/components/store/impl
                        JCSDefaultStore.java
               src/java/org/apache/cocoon/generation StatusGenerator.java
  Log:
  Integrate JCSStore into StoreJanitor; fix size(), keys() and free()
  
  Revision  Changes    Path
  1.3       +52 -5     
cocoon-2.1/src/java/org/apache/cocoon/components/store/impl/JCSDefaultStore.java
  
  Index: JCSDefaultStore.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/store/impl/JCSDefaultStore.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JCSDefaultStore.java      19 May 2004 08:43:05 -0000      1.2
  +++ JCSDefaultStore.java      20 May 2004 10:48:16 -0000      1.3
  @@ -17,6 +17,8 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.io.Serializable;
  +import java.util.Arrays;
   import java.util.Enumeration;
   import java.util.Properties;
   
  @@ -29,15 +31,20 @@
   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.Constants;
   import org.apache.cocoon.util.IOUtils;
   import org.apache.commons.collections.iterators.IteratorEnumeration;
   import org.apache.excalibur.store.Store;
  +import org.apache.excalibur.store.StoreJanitor;
   import org.apache.jcs.access.GroupCacheAccess;
   import org.apache.jcs.access.exception.CacheException;
   import org.apache.jcs.engine.control.CompositeCache;
   import org.apache.jcs.engine.control.CompositeCacheManager;
  +import org.apache.jcs.engine.memory.MemoryCache;
   
   
   /**
  @@ -53,7 +60,8 @@
                  Parameterizable,
                  Initializable,
                  Disposable, 
  -               ThreadSafe {
  +               ThreadSafe,
  +               Serviceable {
   
       /** The JCS configuration properties */
       protected Properties properties;
  @@ -73,6 +81,12 @@
       /** The context containing the work and the cache directory */
       private Context context;
   
  +    /** Service Manager */
  +    private ServiceManager manager;
  +    
  +    /** Store janitor */
  +    private StoreJanitor janitor;
  +    
       /* (non-Javadoc)
        * @see 
org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
        */
  @@ -81,6 +95,14 @@
       }
       
       /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
  +     */
  +    public void service(ServiceManager aManager) throws ServiceException {
  +        this.manager = aManager;
  +        this.janitor = (StoreJanitor)this.manager.lookup(StoreJanitor.ROLE);
  +    }
  +    
  +    /* (non-Javadoc)
        * @see 
org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
        */
       public void parameterize(Parameters parameters) 
  @@ -155,12 +177,16 @@
           this.cacheManager = CompositeCacheManager.getUnconfiguredInstance();
           this.cacheManager.configure(this.properties);
           this.jcs = new JCSCacheAccess(cacheManager.getCache(region));
  +        this.janitor.register(this);
       }
       
       /* (non-Javadoc)
        * @see org.apache.avalon.framework.activity.Disposable#dispose()
        */
       public void dispose() {
  +        if( this.janitor != null ) {
  +            this.janitor.unregister( this );
  +        }
           if ( this.jcs != null ) {
               this.jcs.dispose();
               this.jcs = null;
  @@ -170,6 +196,11 @@
               this.cacheManager = null;            
           }
           this.properties = null;
  +        if ( this.manager != null ) {
  +            this.manager.release( this.janitor );
  +            this.janitor = null;
  +            this.manager = null;
  +        }
       }
       
       protected String getDefaultPropertiesFile() {
  @@ -246,7 +277,16 @@
        * @see org.apache.excalibur.store.Store#free()
        */
       public void free() {
  -        // TODO
  +        // TODO Find a better way
  +        MemoryCache memoryCache = 
this.cacheManager.getCache(region).getMemoryCache();
  +        Object[] keys = memoryCache.getKeyArray();
  +        if ( keys != null && keys.length > 0 ) {
  +            final Object key = keys[0];
  +            try {
  +                memoryCache.remove((Serializable)key);
  +            } catch (Exception ignore) {                
  +            }
  +        }
       }
       
       /* (non-Javadoc)
  @@ -291,14 +331,21 @@
        * @see org.apache.excalibur.store.Store#keys()
        */
       public Enumeration keys() {
  -      return new IteratorEnumeration(this.jcs.getGroupKeys("").iterator());
  +        // TODO Find a better way
  +        final MemoryCache memoryCache = 
this.cacheManager.getCache(region).getMemoryCache();
  +        final Object[] keys = memoryCache.getKeyArray();
  +        return new IteratorEnumeration(Arrays.asList(keys).iterator());
  +        //return new 
IteratorEnumeration(this.jcs.getGroupKeys("").iterator());
       }
       
       /* (non-Javadoc)
        * @see org.apache.excalibur.store.Store#size()
        */
       public int size() {
  -        return this.jcs.getSize();
  +        // TODO Find a better way
  +        MemoryCache memoryCache = 
this.cacheManager.getCache(region).getMemoryCache();
  +        return memoryCache.getSize();
  +        //return this.jcs.getSize();
       }
       
   
  
  
  
  1.8       +2 -3      
cocoon-2.1/src/java/org/apache/cocoon/generation/StatusGenerator.java
  
  Index: StatusGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/StatusGenerator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StatusGenerator.java      19 May 2004 11:32:02 -0000      1.7
  +++ StatusGenerator.java      20 May 2004 10:48:16 -0000      1.8
  @@ -107,8 +107,7 @@
           if ( this.manager.hasService(Store.PERSISTENT_STORE) ) {
               this.store_persistent = 
(Store)this.manager.lookup(Store.PERSISTENT_STORE);
           } else {
  -            getLogger().info("Persistent Store is not available. We will use 
the general store instead.");
  -            this.store_persistent = (Store)this.manager.lookup(Store.ROLE);
  +            getLogger().info("Persistent Store is not available. Sorry no 
cache statistics about it.");
           }
       }
       
  
  
  

Reply via email to