[jboss-cvs] JBossCache/src/org/jboss/cache/factories ...

Manik Surtani msurtani at jboss.com
Fri Jan 5 06:42:53 EST 2007


  User: msurtani
  Date: 07/01/05 06:42:53

  Modified:    src/org/jboss/cache/factories   DefaultCacheFactory.java
                        CacheFactory.java
  Log:
  - Configurations are now cloned before being used by the factory to guarantee ownership
  - Cloning configurations also resets RuntimeConfiguration of the clone
  - RemoteCacheListenerTest updated for completeness and thoroughness
  
  Revision  Changes    Path
  1.14      +53 -4     JBossCache/src/org/jboss/cache/factories/DefaultCacheFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DefaultCacheFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/DefaultCacheFactory.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- DefaultCacheFactory.java	2 Jan 2007 18:26:05 -0000	1.13
  +++ DefaultCacheFactory.java	5 Jan 2007 11:42:53 -0000	1.14
  @@ -6,6 +6,8 @@
    */
   package org.jboss.cache.factories;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheImpl;
   import org.jboss.cache.config.Configuration;
  @@ -19,6 +21,7 @@
   public class DefaultCacheFactory implements CacheFactory
   {
      private static CacheFactory singleton = null;
  +   private Log log = LogFactory.getLog(DefaultCacheFactory.class);
   
      /**
       * Protected constructor to prevent instantiation by user code
  @@ -45,7 +48,8 @@
   
      public Cache createCache() throws ConfigurationException
      {
  -      return createCache(new Configuration());
  +      // don't bother cloning the cfg since we're creating it here.
  +      return createCache(new Configuration(), true, false);
      }
   
      public Cache createCache(String configFileName) throws ConfigurationException
  @@ -57,20 +61,65 @@
      {
         XmlConfigurationParser parser = new XmlConfigurationParser();
         Configuration c = parser.parseFile(configFileName);
  -      return createCache(c, start);
  +      // don't bother cloning the cfg since we're creating it here.
  +      return createCache(c, start, false);
      }
   
  +   /**
  +    * This implementation clones the configuration passed in before using it.
  +    *
  +    * @param configuration to use
  +    * @return a cache
  +    * @throws ConfigurationException if there are problems with the cfg
  +    */
      public Cache createCache(Configuration configuration) throws ConfigurationException
      {
  -      return createCache(configuration, true);
  +      // make sure we clone any configs passed in from the outside world.
  +      return createCache(configuration, true, true);
      }
   
  +   /**
  +    * This implementation clones the configuration passed in before using it.
  +    *
  +    * @param configuration to use
  +    * @param start         whether to start the cache
  +    * @return a cache
  +    * @throws ConfigurationException if there are problems with the cfg
  +    */
      public Cache createCache(Configuration configuration, boolean start) throws ConfigurationException
      {
  +      // make sure we clone any configs passed in from the outside world, in case it is reused by several caches.
  +      // We don't want updates to one cache instance be reflected in others.
  +      return createCache(configuration, start, true);
  +   }
  +
  +   /**
  +    * Creates a cache with the option of starting the cache and cloning the configuration.
  +    *
  +    * @param configuration      with which to create a cache
  +    * @param start              whether we start the cache or not
  +    * @param cloneConfiguration whether we clone the cfg or not
  +    * @return a cache
  +    * @throws ConfigurationException if there are problems with the cfg
  +    */
  +   private Cache createCache(Configuration configuration, boolean start, boolean cloneConfiguration) throws ConfigurationException
  +   {
  +      Configuration toUse = configuration;
  +      if (cloneConfiguration)
  +      {
  +         try
  +         {
  +            toUse = configuration.clone();
  +         }
  +         catch (CloneNotSupportedException e)
  +         {
  +            log.error("Unable to clone configuration?", e);
  +         }
  +      }
         try
         {
            CacheImpl cache = new CacheImpl();
  -         cache.setConfiguration(configuration);
  +         cache.setConfiguration(toUse);
            if (start) cache.start();
            return cache;
         }
  
  
  
  1.6       +16 -3     JBossCache/src/org/jboss/cache/factories/CacheFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/CacheFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- CacheFactory.java	5 Jan 2007 09:04:58 -0000	1.5
  +++ CacheFactory.java	5 Jan 2007 11:42:53 -0000	1.6
  @@ -35,7 +35,8 @@
      /**
       * Creates and starts a {@link Cache} instance using default configuration settings.  See {@link Configuration} for default values.
       *
  -    * @throws ConfigurationException
  +    * @return a cache
  +    * @throws ConfigurationException if there are problems with the default configuration
       */
      Cache createCache() throws ConfigurationException;
   
  @@ -44,6 +45,8 @@
       *
       * @param configFileName the named XML file should exist in the classpath.
       * @return a running {@link org.jboss.cache.Cache} instance
  +    * @throws org.jboss.cache.config.ConfigurationException
  +    *          if there are problems with the configuration
       */
      Cache createCache(String configFileName) throws ConfigurationException;
   
  @@ -53,23 +56,33 @@
       * @param configFileName the named XML file should exist in the classpath.
       * @param start          if true, the cache is started before returning.
       * @return an optionally running {@link Cache} instance
  +    * @throws org.jboss.cache.config.ConfigurationException
  +    *          if there are problems with the configuration
       */
      Cache createCache(String configFileName, boolean start) throws ConfigurationException;
   
      /**
  -    * Creates a {@link Cache} instance
  +    * Creates a {@link Cache} instance based on a {@link org.jboss.cache.config.Configuration} passed in.
  +    * Implementations should clone the configuration passed in before using it, to ensure the reference is not
  +    * shared and cannot be affected by the configuration changing unexpectedly.
       *
       * @param configuration the {@link Configuration} object that is passed in to configure the {@link Cache}.
       * @return a running {@link Cache} instance
  +    * @throws org.jboss.cache.config.ConfigurationException
  +    *          if there are problems with the configuration
       */
      Cache createCache(Configuration configuration) throws ConfigurationException;
   
      /**
  -    * Creates {@link Cache} instance, and optionally starts it.
  +    * Creates {@link Cache} instance, and optionally starts it, based on a {@link org.jboss.cache.config.Configuration} passed in.
  +    * Implementations should clone the configuration passed in before using it, to ensure the reference is not
  +    * shared and cannot be affected by the configuration changing unexpectedly.
       *
       * @param configuration the {@link Configuration} object that is passed in to configure the {@link Cache}.
       * @param start         if true, the cache is started before returning.
       * @return an optionally running {@link Cache} instance
  +    * @throws org.jboss.cache.config.ConfigurationException
  +    *          if there are problems with the configuration
       */
      Cache createCache(Configuration configuration, boolean start) throws ConfigurationException;
   }
  
  
  



More information about the jboss-cvs-commits mailing list