cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/lib jars.xml
Date Wed, 03 Mar 2004 22:28:08 GMT
cziegeler    2004/03/03 14:28:08

  Modified:    lib      jars.xml
  Added:       src/blocks/scratchpad/java/org/apache/cocoon/components/store
                        AbstractJCSStore.java JCSPersistentStore.java
               src/blocks/scratchpad/lib jcs-1.0-dev.20040303.jar.license
                        jcs-1.0-dev-20040303.jar
               src/blocks/scratchpad/WEB-INF TestDiskCache.ccf
  Log:
  Add slightly improved JCS store from Corin Moss to scratchpad
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/AbstractJCSStore.java
  
  Index: AbstractJCSStore.java
  ===================================================================
  /* 
   * Copyright 2002-2004 The Apache Software Foundation
   * Licensed  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;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.Serializable;
  import java.util.Enumeration;
  
  import org.apache.jcs.JCS;
  import org.apache.jcs.access.exception.CacheException;
  
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.excalibur.store.Store;
  import org.apache.excalibur.store.impl.AbstractReadWriteStore;
  
  /**
   * TODO - This store implementation should be moved to excalibur store
   * 
   * @author <a href="mailto:cmoss@tvnz.co.nz">Corin Moss</a>
   */
  public abstract class AbstractJCSStore
      extends AbstractReadWriteStore
      implements Store, ThreadSafe {
      
      /**The JCS Configuration file - for details see: 
      *http://jakarta.apache.org/turbine/jcs/BasicJCSConfiguration.html
      */
      protected File m_JCSConfigFile;
      
      /** The Java Cache System object */
      protected JCS m_JCS;
      
      /**The Region as used by JCS*/
      protected String m_region;
  
      /**The group name as used by JCS getGroupKeys*/
      protected String m_group;
      
  
       
      public void setup(final File configFile, final String regionName, final String groupName)

        throws IOException, CacheException {
     
          this.m_JCSConfigFile = configFile;
          this.m_region = regionName;
          this.m_group = groupName;
          
          getLogger().debug("CEM Loading config: '" + this.m_JCSConfigFile.getAbsolutePath()
+ "'");
          getLogger().debug("CEM Loading region: '" + this.m_region + "'");
          getLogger().debug("CEM Loading group: '" + this.m_group + "'");
  
          /* Does config exist? */
         // if (this.m_JCSConfigFile.exists()) 
         // {
              getLogger().debug("CEM Setting full path: " + this.m_JCSConfigFile.getAbsolutePath());
              
              JCS.setConfigFilename( this.m_JCSConfigFile.getAbsolutePath() );
         // } else {         
          //    throw new IOException( "Error reading JCS Config '" + this.m_JCSConfigFile.getAbsolutePath()
+ "'. File not found." );
         // }
  
  
          try {
             m_JCS = JCS.getInstance( m_region );
          } catch (CacheException ce) { 
              throw new CacheException( "Error initialising JCS with region: " + this.m_region
);
          }
           
  
      } 
      
       /**
       * Returns a Object from the store associated with the Key Object
       *
       * @param key the Key object
       * @return the Object associated with Key Object
       */
      
      protected Object doGet(Object key) 
      {
          Object value = null;
          
          value = m_JCS.get(key);
          if (getLogger().isDebugEnabled()) 
          {
              if (value != null) 
              {
                  getLogger().debug("Found key: " + key);
              } 
              else 
              {
                  getLogger().debug("NOT Found key: " + key);
              }
          }
          
          return value;
      }
      
      /**
       *  Store the given object in the indexed data file.
       *
       * @param key the key object
       * @param value the value object
       * @exception  IOException
       */
      protected void doStore(Object key, Object value)
          throws IOException 
      {
          
          if (getLogger().isDebugEnabled()) 
          {
              getLogger().debug("store(): Store file with key: "
                  + key.toString());
              getLogger().debug("store(): Store file with value: "
                  + value.toString());
          }
          
          //This test is not really pertinent here - we
          //won't always be storing serializable objects (I don't think)
          if (value instanceof Serializable) 
          {
              try 
              {
                  m_JCS.put(key, value);
              } 
              catch (CacheException ce) 
              {
                  getLogger().error("store(..): Exception", ce);
              }
          } 
          else 
          {
              throw new IOException("Object not Serializable");
          }
      }
      
      /**
       * Frees some values of the data file.<br>
       * TODO: implementation
       */
      public void free() 
      {
          // if we ever implement this, we should implement doFree()
      }
      
      /* (non-Javadoc)
       * @see org.apache.excalibur.store.impl.AbstractReadWriteStore#doFree()
       */
      protected void doFree() {
      }
      
      /**
       * Clear the Store of all elements
       */
      protected void doClear() 
      {
          
          if (getLogger().isDebugEnabled()) 
          {
              getLogger().debug("clear(): Clearing the database ");
          }
          
          try 
          {
              //No args - should remove all
              //This is not well documented, although the source
              //suggests that this will work
              m_JCS.remove();               
          } 
          catch (CacheException ce) 
          {
              getLogger().error("store(..): Exception", ce);
          }
      }
      
      /**
       * Removes a value from the data file with the given key.
       *
       * @param key the key object
       */
      protected void doRemove(Object key)
      {
          if (getLogger().isDebugEnabled()) 
          {
              getLogger().debug("remove(..) Remove item");
          }
          
          try 
          {
             m_JCS.remove(key); 
          } 
           //Need to revisit this exception - what happens
           //if no match found for key  - is an exception thrown?
          catch (CacheException ce) 
          {
              getLogger().error("remove(..): Exception", ce);
          }
      }
      
      /**
       *  Test if the the index file contains the given key
       *
       * @param key the key object
       * @return true if Key exists and false if not
       */
      protected boolean doContainsKey(Object key) 
      {
           
          //All we have available is a null check
          if (m_JCS.get(key) != null) {
              return true;
          } 
          else {
              return false;
          }
      }
      
      
       /**
       * Returns an Enumeration of all Keys in the cache.<br>
       * this is a bit of a hack - I don't believe that the group
       * needs to be passed in as a string in this way - we should
       * be able to retreive it.
       * FIX ME!!
       *
       * @return  Enumeration Object with all existing keys
       */
      protected Enumeration doGetKeys() 
      {
        return new org.apache.commons.collections.iterators.IteratorEnumeration(
           this.m_JCS.getGroupKeys(this.m_group).iterator()
        );
      }
      
      protected int doGetSize() 
      {
          //The following is protected - I shall try and 
          //find a way to get to it, but I'm not sure yet
          //return this.m_JCS.cacheControl.getSize();
          
          //Nothing seems to rely on this out side of the instrumentation
          //so, I'll be bad
          return 0;
      }
      
      
      
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/JCSPersistentStore.java
  
  Index: JCSPersistentStore.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.store;
  
  import java.io.File;
  import java.io.IOException;
  
  import org.apache.jcs.access.exception.CacheException;
  
  import org.apache.avalon.framework.activity.Disposable;
  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.excalibur.source.Source;
  import org.apache.excalibur.source.SourceResolver;
  import org.apache.excalibur.source.SourceUtil;
  import org.apache.excalibur.store.Store;
  
  /**
   * This store is based on the JCS Caching library
   * (http://jakarta.apache.org/turbine/jcs/). This store can be configured
   * to use any of the caching types available through the JCS.
   *
   * TODO - This store implementation should  perhaps be moved to excalibur store
   *
   * @author <a href="mailto:cmoss@tvnz.co.nz">Corin Moss</a>
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   */
  public class JCSPersistentStore extends AbstractJCSStore
      implements Store,
                 ThreadSafe,
                 Parameterizable,
                 Disposable,
                 Serviceable {
      
      protected ServiceManager manager;
      
      
      /* (non-Javadoc)
       * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
       */
      public void service(ServiceManager manager) throws ServiceException {
          this.manager = manager;
      }
      
      /**
       *  Configure the Component.<br>
       *  A few options can be used
       *  <UL>
       *    <LI> configFile = the name of the file which specifies the configuration

       *         parameters
       *    </LI>
       *    <LI> region = the region to be used as defined in the config file
       *    </LI>
       *  </UL>
       *
       * @param params the configuration paramters
       * @exception  ParameterException
       */
      public void parameterize(Parameters params) throws ParameterException {
          // TODO - These are only values for testing:
          final String configFileName = params.getParameter("config-file", "context://WEB-INF/TestDiskCache.ccf");
    
          final String regionName = params.getParameter("region-name", "indexedRegion1");
       
          final String groupName = params.getParameter("group-name", "indexedDiskCache");
       
          
          SourceResolver resolver = null;
          Source source = null;
          try {
              resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
              source = resolver.resolveURI(configFileName);
              
              // get the config file to use
              final File configFile = SourceUtil.getFile(source);
              
              //if(!configFile.exists()){
              //   throw new ParameterException(
              //      "JCS Config file does not exist: " + configFileName
              //   );
              //}
              try {
                 this.setup(configFile, regionName, groupName);
              } catch (CacheException ce) {
                 throw new ParameterException(
                    "JCS unable to run setup with region: " + regionName
                 );
              }
          } catch (ServiceException se) {
              throw new ParameterException("Unable to get source resolver.", se);
          } catch (IOException ioe) {
              throw new ParameterException("Unable to get handle on JCS Config file: " + configFileName
, ioe);
          } finally {
              if ( resolver != null ) {
                  resolver.release(source);
                  this.manager.release(resolver);
              }
          }
  
      }
  
      public void dispose() {
          
          try {
              getLogger().debug("Disposing");
  
              if (super.m_JCS != null) {
                  
                  super.m_JCS = null;
                  //protected - what is the best way to do this?
                  //super.m_JCS.dispose();
              }
  
          } catch (Exception e) {
              getLogger().error("dispose(..) Exception", e);
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/lib/jcs-1.0-dev.20040303.jar.license
  
  Index: jcs-1.0-dev.20040303.jar.license
  ===================================================================
  
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache JCS" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache JCS", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/lib/jcs-1.0-dev-20040303.jar
  
  	<<Binary file>>
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/WEB-INF/TestDiskCache.ccf
  
  Index: TestDiskCache.ccf
  ===================================================================
  # Cache configuration for the 'TestDiskCache' test. The memory cache has a
  # a maximum of 100 objects, so objects should get pushed into the disk cache
  
  jcs.default=indexedDiskCache
  jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.default.cacheattributes.MaxObjects=10
  jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  # SYSTEM GROUP ID CACHE
  jcs.system.groupIdCache=indexedDiskCache
  jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.system.groupIdCache.cacheattributes.MaxObjects=10
  jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  
  ##### CACHE REGIONS FOR TEST
  
  jcs.region.indexedRegion1=indexedDiskCache
  jcs.region.indexedRegion1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.region.indexedRegion1.cacheattributes.MaxObjects=1000
  jcs.region.indexedRegion1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  jcs.region.indexedRegion2=indexedDiskCache
  jcs.region.indexedRegion2.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.region.indexedRegion2.cacheattributes.MaxObjects=100
  jcs.region.indexedRegion2.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  jcs.region.indexedRegion3=indexedDiskCache
  jcs.region.indexedRegion3.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.region.indexedRegion3.cacheattributes.MaxObjects=100
  jcs.region.indexedRegion3.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  jcs.region.indexedRegion4=indexedDiskCache2
  jcs.region.indexedRegion4.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.region.indexedRegion4.cacheattributes.MaxObjects=100
  jcs.region.indexedRegion4.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  
  ##### AUXILIARY CACHES
  
  # Indexed Disk Cache
  jcs.auxiliary.indexedDiskCache=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
  jcs.auxiliary.indexedDiskCache.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
  jcs.auxiliary.indexedDiskCache.attributes.DiskPath=/www/cocoon/webapps/cocoon/indexed-disk-cache
  
  # Indexed Disk Cache
  jcs.auxiliary.indexedDiskCache2=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
  jcs.auxiliary.indexedDiskCache2.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
  jcs.auxiliary.indexedDiskCache2.attributes.DiskPath=target/test-sandbox/indexed-disk-cache2
  
  
  
  1.181     +10 -1     cocoon-2.1/lib/jars.xml
  
  Index: jars.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/lib/jars.xml,v
  retrieving revision 1.180
  retrieving revision 1.181
  diff -u -r1.180 -r1.181
  --- jars.xml	3 Mar 2004 09:42:24 -0000	1.180
  +++ jars.xml	3 Mar 2004 22:28:08 -0000	1.181
  @@ -495,12 +495,21 @@
       <homepage>http://oss.software.ibm.com/icu4j/index.html</homepage>
     </file>
   
  +
     <file>
       <title>JISP</title>
       <description>Java Indexed Serialization Package</description>
       <used-by>JISP file storage</used-by>
       <lib>core/jisp-2.5.1.jar</lib>
       <homepage>http://www.coyotegulch.com/jisp/</homepage>
  +  </file>
  +
  +  <file>
  +    <title>JCS</title>
  +    <description>Java Caching System</description>
  +    <used-by>JCS Store</used-by>
  +    <lib>scratchpad/lib/jcs-1.0-dev-20040303.jar</lib>
  +    <homepage>http://jakarta.apache.org/turbine/jcs</homepage>
     </file>
   
     <file>
  
  
  

Mime
View raw message