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/WEB-INF cache.ccf
Date Sat, 06 Mar 2004 15:18:46 GMT
unico       2004/03/06 07:18:46

  Modified:    src/blocks/scratchpad/conf jcs-store.xconf
  Added:       src/blocks/scratchpad/java/org/apache/cocoon/components/store
                        AbstractJCSStore.java default.ccf transient.ccf
                        JCSTransientStore.java JCSDefaultStore.java
  Removed:     src/blocks/scratchpad/java/org/apache/cocoon/components/store
                        JCSStore.java
               src/blocks/scratchpad/WEB-INF cache.ccf
  Log:
  - configuration from parameters
  - two flavors: transient and default
  
  Revision  Changes    Path
  1.5       +11 -7     cocoon-2.1/src/blocks/scratchpad/conf/jcs-store.xconf
  
  Index: jcs-store.xconf
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/conf/jcs-store.xconf,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jcs-store.xconf	6 Mar 2004 02:25:52 -0000	1.4
  +++ jcs-store.xconf	6 Mar 2004 15:18:46 -0000	1.5
  @@ -15,14 +15,18 @@
     limitations under the License.
   -->
   
  -<xconf xpath="/cocoon" unless="persistent-store[@class='org.apache.cocoon.components.store.JCSStore']">
  +<xconf xpath="/cocoon" unless="store[@class='org.apache.cocoon.components.store.JCSDefaultStore']">
   
     <!-- Experimental JCS Store implementation -->
  -  <persistent-store class="org.apache.cocoon.components.store.JCSStore" 
  -                    logger="core.store.persistent">
  -    <parameter name="region-name" value="indexedRegion4"/>
  -    <parameter name="group-name" value="indexedDiskCache2"/>
  -    <parameter name="config-file" value="context://WEB-INF/cache.ccf"/>
  -  </persistent-store>
  +  <store class="org.apache.cocoon.components.store.JCSDefaultStore" 
  +                    logger="core.store">
  +    <parameter name="maxobjects" value="100"/>
  +    <parameter name="use-cache-directory" value="true"/>
  +  </store>
     
  +  <transient-store class="org.apache.cocoon.components.store.JCSTransientStore" 
  +                    logger="core.store.transient">
  +    <parameter name="maxobjects" value="100"/>
  +  </transient-store>
  +
   </xconf>
  
  
  
  1.6       +129 -158  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/AbstractJCSStore.java
  
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/default.ccf
  
  Index: default.ccf
  ===================================================================
  # Cache configuration defaults.
  
  jcs.default=DC
  jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.default.cacheattributes.MaxObjects=100
  jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  # SYSTEM GROUP ID CACHE
  jcs.system.groupIdCache=DC
  jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.system.groupIdCache.cacheattributes.MaxObjects=1000
  jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  ##### AUXILIARY CACHES
  
  # Indexed Disk Cache
  jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
  jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
  #jcs.auxiliary.DC.attributes.DiskPath=
  
  # PRE-DEFINED CACHE REGIONS   
  
  jcs.region.main=DC
  jcs.region.main.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.region.main.cacheattributes.MaxObjects=100
  jcs.region.main.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  jcs.region.main.cacheattributes.UseMemoryShrinker=true
  jcs.region.main.cacheattributes.MaxMemoryIdleTimeSeconds=3600
  jcs.region.main.cacheattributes.ShrinkerIntervalSeconds=60
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/transient.ccf
  
  Index: transient.ccf
  ===================================================================
  # Cache configuration defaults.
  
  jcs.default=
  jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.default.cacheattributes.MaxObjects=100
  jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  # SYSTEM GROUP ID CACHE
  jcs.system.groupIdCache=
  jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.system.groupIdCache.cacheattributes.MaxObjects=1000
  jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  
  jcs.region.main=
  jcs.region.main.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  jcs.region.main.cacheattributes.MaxObjects=100
  jcs.region.main.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  jcs.region.main.cacheattributes.UseMemoryShrinker=true
  jcs.region.main.cacheattributes.MaxMemoryIdleTimeSeconds=3600
  jcs.region.main.cacheattributes.ShrinkerIntervalSeconds=60
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/JCSTransientStore.java
  
  Index: JCSTransientStore.java
  ===================================================================
  /*
   * Copyright 2004,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 org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  
  public class JCSTransientStore extends AbstractJCSStore {
  
      /** The location of the JCS default properties file */
      private static final String DEFAULT_PROPERTIES = "org/apache/cocoon/components/store/transient.ccf";
      
      public JCSTransientStore() {
      }
  
      public void parameterize(Parameters parameters) throws ParameterException {
          super.parameterize(parameters);
          int maxobjects = parameters.getParameterAsInteger("maxobjects",-1);
          if (maxobjects != -1) {
              String key = "jcs.region." + m_region + ".cacheattributes.MaxObjects";
              m_properties.setProperty(key,String.valueOf(maxobjects));
          }
      }
      
      protected String getDefaultPropertiesFile() {
          return DEFAULT_PROPERTIES;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/store/JCSDefaultStore.java
  
  Index: JCSDefaultStore.java
  ===================================================================
  /*
   * Copyright 2004,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 org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.Constants;
  import org.apache.cocoon.util.IOUtils;
  
  
  public class JCSDefaultStore extends JCSTransientStore implements Contextualizable, Parameterizable
{
  
      /** The location of the JCS default properties file */
      private static final String DEFAULT_PROPERTIES = "org/apache/cocoon/components/store/default.ccf";
  
      /** The context containing the work and the cache directory */
      private Context m_context;
  
      // ---------------------------------------------------- Lifecycle
      
      public JCSDefaultStore() {
      }
  
      /**
       * Contextualize the Component
       *
       * @param  context the Context of the Application
       * @exception  ContextException
       */
      public void contextualize(Context context) throws ContextException {
          m_context = context;
      }
      
      /**
       *  Configure the Component.<br>
       *  A few options can be used
       * 
       *  TODO: describe options
       * 
       * @param params the configuration paramters
       * @exception  ParameterException
       */
      public void parameterize(Parameters parameters) throws ParameterException {
          
          super.parameterize(parameters);
          
          int maxobjects = parameters.getParameterAsInteger("maxobjects",-1);
          if (maxobjects != -1) {
              m_properties.setProperty("jcs.default.cacheattributes.MaxObjects",String.valueOf(maxobjects));
          }
          
          // get the directory to use
          try {
              File workDir = (File) m_context.get(Constants.CONTEXT_WORK_DIR);
              if (parameters.getParameterAsBoolean("use-cache-directory", false)) {
                  final File cacheDir = (File) m_context.get(Constants.CONTEXT_CACHE_DIR);
                  if (getLogger().isDebugEnabled()) {
                      getLogger().debug("Using cache directory: " + cacheDir);
                  }
                  setDirectory(cacheDir);
              } else if (parameters.getParameterAsBoolean("use-work-directory", false)) {
                  if (getLogger().isDebugEnabled()) {
                      getLogger().debug("Using work directory: " + workDir);
                  }
                  setDirectory(workDir);
              } else if (parameters.getParameter("directory", null) != null) {
                  String dir = parameters.getParameter("directory");
                  dir = IOUtils.getContextFilePath(workDir.getPath(), dir);
                  if (getLogger().isDebugEnabled()) {
                      getLogger().debug("Using directory: " + dir);
                  }
                  setDirectory(new File(dir));
              } else {
                  if (getLogger().isDebugEnabled()) {
                      getLogger().debug("Using default directory: " + workDir);
                  }
                  setDirectory(workDir);
              }
          } catch (ContextException ce) {
              throw new ParameterException("Unable to get directory information from context.",
ce);
          } catch (IOException e) {
              throw new ParameterException("Unable to set directory", e);
          }
      }
      
      protected String getDefaultPropertiesFile() {
          return DEFAULT_PROPERTIES;
      }
      
      /**
       * Sets the disk cache location.
       */
      private void setDirectory(final File directory)
      throws IOException 
      {
  
          /* Does directory exist? */
          if (!directory.exists()) 
          {
              /* Create it anew */
              if (!directory.mkdirs()) 
              {
                  throw new IOException(
                  "Error creating store directory '" + directory.getAbsolutePath() + "'. ");
              }
          }
  
          /* Is given file actually a directory? */
          if (!directory.isDirectory()) 
          {
              throw new IOException("'" + directory.getAbsolutePath() + "' is not a directory");
          }
  
          /* Is directory readable and writable? */
          if (!(directory.canRead() && directory.canWrite())) 
          {
              throw new IOException(
                  "Directory '" + directory.getAbsolutePath() + "' is not readable/writable"
              );
          }
          
          m_properties.setProperty("jcs.auxiliary.DC.attributes.DiskPath",directory.getAbsolutePath());
      }
  
  }
  
  
  

Mime
View raw message