[jbosscache-commits] JBoss Cache SVN: r4682 - in core/trunk/src: main/java/org/jboss/cache/config and 7 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Oct 24 17:58:49 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-10-24 17:58:48 -0400 (Wed, 24 Oct 2007)
New Revision: 4682

Added:
   core/trunk/src/main/resources/META-INF/clonable-config-service.xml
   core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java
   core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
   core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
   core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
   core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
   core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
   core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java
   core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
   core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java
   core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
   core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
   core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java
   core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java
   core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java
   core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java
Log:
[JBCACHE-1206] Improve cloning of configuration elements

Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/NextMemberBuddyLocatorConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -84,6 +84,7 @@
       }
    }
 
+   @Override
    public boolean equals(Object obj)
    {
       if (this == obj)
@@ -98,6 +99,7 @@
       return false;
    }
 
+   @Override
    public int hashCode()
    {
       int result = 13;
@@ -106,5 +108,13 @@
       return result;
    }
 
+   @Override
+   public NextMemberBuddyLocatorConfig clone() throws CloneNotSupportedException
+   {
+      return (NextMemberBuddyLocatorConfig) super.clone();
+   }
+   
+   
 
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -162,6 +162,15 @@
       return result;
    }
 
+   @Override
+   public BuddyReplicationConfig clone() throws CloneNotSupportedException
+   {
+      BuddyReplicationConfig clone = (BuddyReplicationConfig) super.clone();
+      if (buddyLocatorConfig != null) 
+         clone.setBuddyLocatorConfig(buddyLocatorConfig.clone());
+      return clone;
+   }
+
    public static class BuddyLocatorConfig extends ConfigurationComponent
    {
       private static final long serialVersionUID = -8003634097931826091L;
@@ -226,5 +235,16 @@
                  " properties=" + buddyLocatorProperties;
       }
 
+      @Override
+      public BuddyLocatorConfig clone() throws CloneNotSupportedException
+      {
+         BuddyLocatorConfig clone = (BuddyLocatorConfig) super.clone();
+         if (buddyLocatorProperties != null)
+            clone.buddyLocatorProperties = (Properties) buddyLocatorProperties.clone();
+         return clone;
+      }
+      
+      
+
    }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -107,6 +107,7 @@
       return shared;
    }
 
+   @Override
    public boolean equals(Object obj)
    {
       if (this == obj)
@@ -123,6 +124,7 @@
       return false;
    }
 
+   @Override
    public int hashCode()
    {
       int result = 19;
@@ -132,8 +134,29 @@
       result = 51 * result + (cacheLoaderConfigs == null ? 0 : cacheLoaderConfigs.hashCode());
       return result;
    }
+   
+   
 
 
+   @Override
+   public CacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      CacheLoaderConfig clone =  (CacheLoaderConfig) super.clone();
+      if (cacheLoaderConfigs != null)
+      {
+         List<IndividualCacheLoaderConfig> clcs = new ArrayList<IndividualCacheLoaderConfig>(cacheLoaderConfigs.size());
+         for (IndividualCacheLoaderConfig clc : cacheLoaderConfigs)
+         {
+            clcs.add(clc.clone());
+         }
+         clone.setIndividualCacheLoaderConfigs(clcs);
+      }
+      return clone;
+   }
+
+
+
+
    /**
     * Configuration object that holds the confguration of an individual cache loader.
     *
@@ -259,10 +282,12 @@
 
       public void setSingletonStoreConfig(SingletonStoreConfig singletonStoreConfig)
       {
-         testImmutability("singletonStoreConfig");         
+         testImmutability("singletonStoreConfig");      
+         replaceChildConfig(this.singletonStoreConfig, singletonStoreConfig);
          this.singletonStoreConfig = singletonStoreConfig;
       }
 
+      @Override
       public boolean equals(Object obj)
       {
          if (!(obj instanceof IndividualCacheLoaderConfig))
@@ -286,6 +311,7 @@
 
       }
 
+      @Override
       public int hashCode()
       {
          return 31 * hashCodeExcludingProperties() + (properties == null ? 0 : properties.hashCode());
@@ -303,6 +329,7 @@
          return result;
       }
 
+      @Override
       public String toString()
       {
          return new StringBuffer().append("IndividualCacheLoaderConfig{").append("className='").append(className).append('\'')
@@ -314,7 +341,22 @@
                  .append("SingletonStoreConfig{").append(singletonStoreConfig).append('}')
                  .toString();
       }
+      
+      
 
+      @Override
+      public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
+      {
+         IndividualCacheLoaderConfig clone = (IndividualCacheLoaderConfig) super.clone();
+         if (properties != null)
+            clone.properties = (Properties) properties.clone();
+         if (singletonStoreConfig != null)
+            clone.setSingletonStoreConfig(singletonStoreConfig.clone());
+         return clone;
+      }
+
+
+
       /**
        * Configuration for a SingletonStoreCacheLoader
        */
@@ -411,6 +453,17 @@
                     " class=" + singletonStoreClass +
                     " properties=" + singletonStoreproperties;
          }
+
+         @Override
+         public SingletonStoreConfig clone() throws CloneNotSupportedException
+         {
+            SingletonStoreConfig clone = (SingletonStoreConfig) super.clone();
+            if (singletonStoreproperties != null)
+               clone.singletonStoreproperties = (Properties) singletonStoreproperties.clone();
+            return clone;
+         }
+         
+         
       }
    }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -754,19 +754,19 @@
       Configuration c = (Configuration) super.clone();
       if (buddyReplicationConfig != null)
       {
-         c.setBuddyReplicationConfig((BuddyReplicationConfig) buddyReplicationConfig.clone());
+         c.setBuddyReplicationConfig(buddyReplicationConfig.clone());
       }
       if (evictionConfig != null)
       {
-         c.setEvictionConfig((EvictionConfig) evictionConfig.clone());
+         c.setEvictionConfig(evictionConfig.clone());
       }
       if (cacheLoaderConfig != null)
       {
-         c.setCacheLoaderConfig((CacheLoaderConfig) cacheLoaderConfig.clone());
+         c.setCacheLoaderConfig(cacheLoaderConfig.clone());
       }
       if (runtimeConfig != null)
       {
-         c.setRuntimeConfig((RuntimeConfig) runtimeConfig.clone());
+         c.setRuntimeConfig(runtimeConfig.clone());
          // always make sure we reset the runtime when cloning.
          c.getRuntimeConfig().reset();
       }

Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -24,6 +24,7 @@
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.eviction.EvictionPolicy;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -141,6 +142,7 @@
       this.wakeupIntervalSeconds = wakeupIntervalSeconds;
    }
 
+   @Override
    public boolean equals(Object obj)
    {
       if (this == obj)
@@ -156,6 +158,7 @@
       return false;
    }
 
+   @Override
    public int hashCode()
    {
       int result = 17;
@@ -164,4 +167,22 @@
       result = 37 * result + (evictionRegionConfigs == null ? 0 : evictionRegionConfigs.hashCode());
       return result;
    }
+
+   @Override
+   public EvictionConfig clone() throws CloneNotSupportedException
+   {
+      EvictionConfig clone = (EvictionConfig) super.clone();
+      if (evictionRegionConfigs != null)
+      {
+         List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>(evictionRegionConfigs.size());
+         for (EvictionRegionConfig erc : evictionRegionConfigs)
+         {
+             ercs.add(erc.clone());
+         }
+         clone.setEvictionRegionConfigs(ercs);
+      }
+      return clone;
+   }
+   
+   
 }

Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -21,6 +21,8 @@
  */
 package org.jboss.cache.config;
 
+import java.lang.reflect.Method;
+
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.Fqn;
 
@@ -136,5 +138,41 @@
       return result;
    }
 
+   @Override
+   public EvictionRegionConfig clone() throws CloneNotSupportedException
+   {
+      EvictionRegionConfig clone = (EvictionRegionConfig) super.clone();
+      if (evictionPolicyConfig != null)
+      {
+         if (!(evictionPolicyConfig instanceof Cloneable))
+         {
+            throw new CloneNotSupportedException(evictionPolicyConfig + " is not Cloneable");
+         }
+           
+         if (evictionPolicyConfig instanceof ConfigurationComponent)
+         {
+            clone.setEvictionPolicyConfig((EvictionPolicyConfig) ((ConfigurationComponent) evictionPolicyConfig).clone());
+         }
+         else {
+            try
+            {
+               Method cloneMethod = evictionPolicyConfig.getClass().getDeclaredMethod("clone", new Class[]{});
+               EvictionPolicyConfig epc = (EvictionPolicyConfig) cloneMethod.invoke(evictionPolicyConfig, new Object[]{});
+               clone.setEvictionPolicyConfig(epc);
+            }
+            catch (Exception e)
+            {
+               CloneNotSupportedException cnse = new CloneNotSupportedException("Cannot invoke clone() on " + evictionPolicyConfig);
+               cnse.initCause(e);
+               throw cnse;
+            }
+         }
+      }
+      
+      return clone;
+   }
+   
+   
 
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -193,4 +193,12 @@
    {
       return rpcManager;
    }
+
+   @Override
+   public RuntimeConfig clone() throws CloneNotSupportedException
+   {
+      return (RuntimeConfig) super.clone();
+   }
+   
+   
 }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -108,4 +108,12 @@
       super.reset();
       setMaxElementsPerNode(-1);
    }
+
+   @Override
+   public ElementSizeConfiguration clone() throws CloneNotSupportedException
+   {
+      return (ElementSizeConfiguration) super.clone();
+   }
+   
+   
 }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -79,6 +79,14 @@
    public void setTimeToLiveSeconds(int timeToLiveSeconds)
    {
       this.timeToLiveSeconds = timeToLiveSeconds;
+   }
+
+   @Override
+   public ExpirationConfiguration clone() throws CloneNotSupportedException
+   {
+      return (ExpirationConfiguration) super.clone();
    }   
+   
+   
 
 }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -74,4 +74,12 @@
    {
       setMaxNodes(-1);
    }
+
+   @Override
+   public FIFOConfiguration clone() throws CloneNotSupportedException
+   {
+      return (FIFOConfiguration) super.clone();
+   }
+   
+   
 }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -78,4 +78,10 @@
       return result;
    }
 
+   @Override
+   public LFUConfiguration clone() throws CloneNotSupportedException
+   {
+      return (LFUConfiguration) super.clone();
+   }
+
 }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -120,5 +120,11 @@
       super.reset();
       setTimeToLiveSeconds(-1);
    }
+
+   @Override
+   public LRUConfiguration clone() throws CloneNotSupportedException
+   {
+      return (LRUConfiguration) super.clone();
+   }
    
 }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -73,5 +73,11 @@
    {
       setMaxNodes(-1);
    }
+
+   @Override
+   public MRUConfiguration clone() throws CloneNotSupportedException
+   {
+      return (MRUConfiguration) super.clone();
+   }
    
 }

Modified: core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -393,4 +393,10 @@
         return result;
     }
 
+   @Override
+   public AdjListJDBCCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (AdjListJDBCCacheLoaderConfig) super.clone();
+   }
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -136,5 +136,11 @@
       return result;
    }
 
+   @Override
+   public AsyncCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (AsyncCacheLoaderConfig) super.clone();
+   }
 
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -70,4 +70,10 @@
       return 31 * hashCodeExcludingProperties() + (int) timeout;
    }
 
+   @Override
+   public ClusteredCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (ClusteredCacheLoaderConfig) super.clone();
+   }
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -77,4 +77,10 @@
       return 31 * hashCodeExcludingProperties() + (location == null ? 0 : location.hashCode());
    }
 
+   @Override
+   public FileCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (FileCacheLoaderConfig) super.clone();
+   }
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -101,5 +101,11 @@
       return result;
    }
 
+   @Override
+   public TcpDelegatingCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (TcpDelegatingCacheLoaderConfig) super.clone();
+   }
 
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -37,12 +37,14 @@
       this.location = location;
    }
 
+   @Override
    public void setProperties(Properties props)
    {
       super.setProperties(props);
       setLocation(props != null ? props.getProperty("location") : null);
    }
 
+   @Override
    public boolean equals(Object obj)
    {
       if (obj instanceof BdbjeCacheLoaderConfig && equalsExcludingProperties(obj))
@@ -52,9 +54,18 @@
       return false;
    }
 
+   @Override
    public int hashCode()
    {
       return 31 * hashCodeExcludingProperties() + (location == null ? 0 : location.hashCode());
    }
 
+   @Override
+   public BdbjeCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (BdbjeCacheLoaderConfig) super.clone();
+   }
+   
+   
+
 }
\ No newline at end of file

Modified: core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoaderConfig.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -37,12 +37,14 @@
       this.location = location;
    }
 
+   @Override
    public void setProperties(Properties props)
    {
       super.setProperties(props);
       setLocation(props != null ? props.getProperty("location") : null);
    }
 
+   @Override
    public boolean equals(Object obj)
    {
       if (obj instanceof JdbmCacheLoaderConfig && equalsExcludingProperties(obj))
@@ -52,9 +54,16 @@
       return false;
    }
 
+   @Override
    public int hashCode()
    {
       return 31 * hashCodeExcludingProperties() + (location == null ? 0 : location.hashCode());
    }
 
+   @Override
+   public JdbmCacheLoaderConfig clone() throws CloneNotSupportedException
+   {
+      return (JdbmCacheLoaderConfig) super.clone();
+   }
+
 }
\ No newline at end of file

Added: core/trunk/src/main/resources/META-INF/clonable-config-service.xml
===================================================================
--- core/trunk/src/main/resources/META-INF/clonable-config-service.xml	                        (rev 0)
+++ core/trunk/src/main/resources/META-INF/clonable-config-service.xml	2007-10-24 21:58:48 UTC (rev 4682)
@@ -0,0 +1,262 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- 
+      Cache configuration file that attempts to utilize all known elements.
+      Intent here is not to create such a cache; rather it is to create
+      a Configuration and then see if that Configuration can be cloned.
+      Basically just for testing the clone() method of the various
+      configuration elements.
+-->
+
+<server>
+
+   <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
+          name="jboss.cache:service=testTreeCache">
+
+      <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
+      </attribute>
+
+      <attribute name="NodeLockingScheme">OPTIMISTIC</attribute>
+      <attribute name="IsolationLevel">SERIALIZABLE</attribute>
+      <attribute name="CacheMode">INVALIDATION_SYNC</attribute>
+      
+      <attribute name="ClusterName">CloneCluster</attribute>
+      
+      <!-- Use both a stack name and a ClusterConfig so we can test both -->
+      <attribute name="MultiplexerStack">udp</attribute>      
+      <attribute name="ClusterConfig">
+         <config>
+            <UDP mcast_addr="228.10.10.10"
+                 mcast_port="45588"
+                 tos="8"
+                 ucast_recv_buf_size="20000000"
+                 ucast_send_buf_size="640000"
+                 mcast_recv_buf_size="25000000"
+                 mcast_send_buf_size="640000"
+                 loopback="false"
+                 discard_incompatible_packets="true"
+                 max_bundle_size="64000"
+                 max_bundle_timeout="30"
+                 use_incoming_packet_handler="true"
+                 ip_ttl="2"
+                 enable_bundling="false"
+                 enable_diagnostics="true"
+
+                 use_concurrent_stack="true"
+
+                 thread_naming_pattern="pl"
+
+                 thread_pool.enabled="true"
+                 thread_pool.min_threads="1"
+                 thread_pool.max_threads="25"
+                 thread_pool.keep_alive_time="30000"
+                 thread_pool.queue_enabled="true"
+                 thread_pool.queue_max_size="10"
+                 thread_pool.rejection_policy="Run"
+
+                 oob_thread_pool.enabled="true"
+                 oob_thread_pool.min_threads="1"
+                 oob_thread_pool.max_threads="4"
+                 oob_thread_pool.keep_alive_time="10000"
+                 oob_thread_pool.queue_enabled="true"
+                 oob_thread_pool.queue_max_size="10"
+                 oob_thread_pool.rejection_policy="Run"/>
+
+            <PING timeout="2000" num_initial_members="3"/>
+            <MERGE2 max_interval="30000" min_interval="10000"/>
+            <FD_SOCK/>
+            <FD timeout="10000" max_tries="5" shun="true"/>
+            <VERIFY_SUSPECT timeout="1500"/>
+            <pbcast.NAKACK
+                    use_mcast_xmit="false" gc_lag="0"
+                    retransmit_timeout="300,600,1200,2400,4800"
+                    discard_delivered_msgs="true"/>
+            <UNICAST timeout="300,600,1200,2400,3600"/>
+            <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+                           max_bytes="400000"/>
+            <pbcast.GMS print_local_addr="true" join_timeout="5000"
+                        join_retry_timeout="2000" shun="false"
+                        view_bundling="true" view_ack_collection_timeout="5000"/>
+            <FRAG2 frag_size="60000"/>
+            <pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
+            <!-- <pbcast.STATE_TRANSFER/> -->
+            <pbcast.FLUSH timeout="0"/>
+         </config>
+      </attribute>
+
+      <attribute name="FetchInMemoryState">false</attribute>
+      <attribute name="StateRetrievalTimeout">3</attribute>
+      <attribute name="SyncReplTimeout">2</attribute>
+      <attribute name="LockAcquisitionTimeout">1</attribute>
+
+
+      <attribute name="BuddyReplicationConfig">
+         <config>
+            <buddyReplicationEnabled>true</buddyReplicationEnabled>
+            <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>
+            <buddyLocatorProperties>
+               numBuddies = 11
+               ignoreColocatedBuddies = true
+            </buddyLocatorProperties>
+
+            <buddyPoolName>cloneGroup</buddyPoolName>
+            <buddyCommunicationTimeout>7</buddyCommunicationTimeout>
+
+            <autoDataGravitation>false</autoDataGravitation>
+            <dataGravitationRemoveOnFind>true</dataGravitationRemoveOnFind>
+            <dataGravitationSearchBackupTrees>true</dataGravitationSearchBackupTrees>
+
+         </config>
+      </attribute>
+      
+      <attribute name="EvictionPolicyConfig">
+         <config>
+            <attribute name="wakeUpIntervalSeconds">45</attribute>
+            <attribute name="eventQueueSize">4</attribute>
+            <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
+
+            <!-- Cache wide default -->
+            <region name="/_default_">
+               <attribute name="maxNodes">5000</attribute>
+               <attribute name="timeToLiveSeconds">1000</attribute>
+               <attribute name="maxAge">15000</attribute>
+            </region>
+            <region name="/fifo" policyClass="org.jboss.cache.eviction.FIFOPolicy">
+               <attribute name="maxNodes">5000</attribute>
+            </region>
+            <region name="/mru" policyClass="org.jboss.cache.eviction.MRUPolicy">
+               <attribute name="maxNodes">10000</attribute>
+            </region>
+            <region name="/lfu" policyClass="org.jboss.cache.eviction.LFUPolicy">
+               <attribute name="maxNodes">5000</attribute>
+               <attribute name="minNodes">4000</attribute>
+            </region>
+         </config>
+      </attribute>
+      
+      <attribute name="CacheLoaderConfig">
+         <config>
+            <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
+            <passivation>false</passivation>
+            <preload>/</preload>
+            <shared>true</shared>
+
+            <!-- we can now have multiple cache loaders, which get chained -->
+            <cacheloader>
+               <class>org.jboss.cache.loader.FileCacheLoader</class>
+               <properties>
+                  location=/tmp/FileCacheLoader
+               </properties>
+               <async>false</async>
+               <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+               <fetchPersistentState>true</fetchPersistentState>
+               <ignoreModifications>false</ignoreModifications>
+               <singletonStore>
+                  <enabled>false</enabled>
+                  <properties>
+                     pushStateWhenCoordinator=true
+                     pushStateWhenCoordinatorTimeout=5000
+                  </properties>
+               </singletonStore>
+            </cacheloader>
+            
+            <cacheloader>
+               <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>
+               <properties>
+                  location=/tmp/BdbjeCacheLoader
+               </properties>
+               <async>false</async>
+               <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+               <fetchPersistentState>false</fetchPersistentState>
+               <ignoreModifications>false</ignoreModifications>
+               <singletonStore>
+                  <enabled>false</enabled>
+                  <properties>
+                     pushStateWhenCoordinator=true
+                     pushStateWhenCoordinatorTimeout=5000
+                  </properties>
+               </singletonStore>
+            </cacheloader>
+            
+            <cacheloader>
+               <class>org.jboss.cache.loader.jdbm.JdbmCacheLoader</class>
+               <properties>
+                  location=/tmp/JdbmCacheLoader
+               </properties>
+               <async>false</async>
+               <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+               <fetchPersistentState>false</fetchPersistentState>
+               <ignoreModifications>false</ignoreModifications>
+               <singletonStore>
+                  <enabled>false</enabled>
+                  <properties>
+                     pushStateWhenCoordinator=true
+                     pushStateWhenCoordinatorTimeout=5000
+                  </properties>
+               </singletonStore>
+            </cacheloader>
+            
+            <cacheloader>
+               <class>org.jboss.cache.loader.JDBCCacheLoader</class>
+               <properties>
+                  cache.jdbc.driver=com.foo.jdbc.Driver
+                  cache.jdbc.url=foo://driver
+                  cache.jdbc.user=sa
+                  cache.jdbc.password=secret
+               </properties>
+               <async>false</async>
+               <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+               <fetchPersistentState>false</fetchPersistentState>
+               <ignoreModifications>false</ignoreModifications>
+               <singletonStore>
+                  <enabled>false</enabled>
+                  <properties>
+                     pushStateWhenCoordinator=true
+                     pushStateWhenCoordinatorTimeout=5000
+                  </properties>
+               </singletonStore>
+            </cacheloader>
+            
+            <cacheloader>
+               <class>org.jboss.cache.loader.TcpDelegatingCacheLoader</class>
+               <properties>
+                  host=127.0.0.1\nport=12121
+               </properties>
+               <async>false</async>
+               <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+               <fetchPersistentState>false</fetchPersistentState>
+               <ignoreModifications>false</ignoreModifications>
+               <singletonStore>
+                  <enabled>false</enabled>
+                  <properties>
+                     pushStateWhenCoordinator=true
+                     pushStateWhenCoordinatorTimeout=5000
+                  </properties>
+               </singletonStore>
+            </cacheloader>
+            
+            <cacheloader>
+               <class>org.jboss.cache.loader.ClusteredCacheLoader</class>
+               <properties>
+                  timeout=500
+               </properties>
+               <async>false</async>
+               <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+               <fetchPersistentState>false</fetchPersistentState>
+               <ignoreModifications>false</ignoreModifications>
+               <singletonStore>
+                  <enabled>false</enabled>
+                  <properties>
+                     pushStateWhenCoordinator=true
+                     pushStateWhenCoordinatorTimeout=5000
+                  </properties>
+               </singletonStore>
+            </cacheloader>
+
+         </config>
+      </attribute>
+      
+   </mbean>
+
+
+</server>

Added: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.config;
+
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.factories.XmlConfigurationParser;
+import org.testng.annotations.Test;
+
+/**
+ * Tests the ability to clone Configuration elements and end up with
+ * independently modifiable configurations.
+ * 
+ * @author Brian Stansberry
+ */
+ at Test(groups = {"functional"})
+public class ConfigurationCloningTest
+{
+   /** A file that includes every configuration element I could think of */
+   public static final String DEFAULT_CONFIGURATION_FILE = "META-INF/clonable-config-service.xml";
+   
+   private static final Log log = LogFactory.getLog(ConfigurationCloningTest.class);
+   
+   public void testClone() throws Exception
+   {
+      XmlConfigurationParser parser = new XmlConfigurationParser();
+      Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE);
+      
+      try {
+         Configuration clone = c.clone();   
+         
+         // Test a few simple properties 
+         assertEquals(NodeLockingScheme.OPTIMISTIC, clone.getNodeLockingScheme());   
+         assertEquals(CacheMode.INVALIDATION_SYNC, clone.getCacheMode());   
+         assertEquals("CloneCluster", clone.getClusterName());   
+         assertEquals(c.getClusterConfig(), clone.getClusterConfig());   
+         assertEquals(3, clone.getStateRetrievalTimeout());   
+         
+         // Buddy replication config
+         BuddyReplicationConfig brc1 = c.getBuddyReplicationConfig();
+         BuddyReplicationConfig brc2 = clone.getBuddyReplicationConfig();
+         
+         assertFalse(brc1 == brc2);
+         
+         assertEquals(7, brc2.getBuddyCommunicationTimeout());
+         assertEquals("cloneGroup", brc2.getBuddyPoolName());
+         
+         BuddyLocatorConfig blc1 = brc1.getBuddyLocatorConfig();
+         BuddyLocatorConfig blc2 = brc2.getBuddyLocatorConfig();
+         assertFalse(blc1 == blc2);
+         Properties p1 = blc1.getBuddyLocatorProperties();
+         Properties p2 = blc2.getBuddyLocatorProperties();
+         assertFalse(p1 == p2);
+         assertEquals(p1, p2);
+         
+         // Eviction
+         EvictionConfig ec1 = c.getEvictionConfig();
+         EvictionConfig ec2 = clone.getEvictionConfig();
+         
+         assertFalse(ec1 == ec2);
+         
+         assertEquals(4, ec2.getDefaultEventQueueSize());
+         assertEquals(45, ec2.getWakeupIntervalSeconds());
+         assertEquals(LRUPolicy.class.getName(), ec2.getDefaultEvictionPolicyClass());
+         
+         List<EvictionRegionConfig> ercs1 = ec1.getEvictionRegionConfigs();
+         List<EvictionRegionConfig> ercs2 = ec2.getEvictionRegionConfigs();
+         assertEquals(ercs1.size(), ercs2.size());
+         for (int i = 0; i < ercs1.size(); i++)
+         {
+            compareEvictionRegionConfigs(ercs1.get(i), ercs2.get(i));
+         }
+         
+         // Cache loading
+         CacheLoaderConfig clc1 = c.getCacheLoaderConfig();
+         CacheLoaderConfig clc2 = clone.getCacheLoaderConfig();
+         
+         assertFalse(clc1 == clc2);
+         
+         assertFalse(clc2.isPassivation());
+         assertTrue(clc2.isShared());
+         
+         List<IndividualCacheLoaderConfig> clcs1 = clc1.getIndividualCacheLoaderConfigs();
+         List<IndividualCacheLoaderConfig> clcs2 = clc2.getIndividualCacheLoaderConfigs();
+         assertEquals(clcs1.size(), clcs2.size());
+         for (int i = 0; i < clcs1.size(); i++)
+         {
+            compareCacheLoaderConfigs(clcs1.get(i), clcs2.get(i));
+         }
+         
+         RuntimeConfig rc1 = c.getRuntimeConfig();
+         RuntimeConfig rc2 = clone.getRuntimeConfig();
+         assertFalse(rc1 == rc2);
+         assertEquals(rc1, rc2);
+         
+      }
+      catch (CloneNotSupportedException e)
+      {
+         log.error(e.getMessage(), e);
+         fail("Cloning failed -- " + e.getMessage());
+      }
+   }
+
+   private void compareEvictionRegionConfigs(EvictionRegionConfig erc1,
+         EvictionRegionConfig erc2)
+   {
+      assertEquals(erc1.getRegionName(), erc2.getRegionName());
+      assertEquals(erc1.getRegionFqn(), erc2.getRegionFqn());
+      assertEquals(erc1.getEventQueueSize(), erc2.getEventQueueSize());
+      
+      EvictionPolicyConfig epc1 = erc1.getEvictionPolicyConfig();
+      EvictionPolicyConfig epc2 = erc2.getEvictionPolicyConfig();
+      
+      assertFalse(epc1 == epc2);
+      assertEquals(epc1, epc2);
+   }
+
+   private void compareCacheLoaderConfigs(IndividualCacheLoaderConfig clc1,
+         IndividualCacheLoaderConfig clc2)
+   {
+      assertFalse(clc1 == clc2);
+      assertEquals(clc1, clc2);
+      
+      Properties p1 = clc1.getProperties();      
+      Properties p2 = clc2.getProperties();
+      assertFalse(p1 == p2);
+      assertEquals(p1, p2);
+      
+      SingletonStoreConfig ssc1 = clc1.getSingletonStoreConfig();      
+      SingletonStoreConfig ssc2 = clc2.getSingletonStoreConfig();
+      assertFalse(ssc1 == ssc2);
+      assertEquals(ssc1, ssc2);
+   }
+
+}

Modified: core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java	2007-10-24 16:09:31 UTC (rev 4681)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java	2007-10-24 21:58:48 UTC (rev 4682)
@@ -29,5 +29,13 @@
    public void reset()
    {
       // no-op
+   }
+
+   @Override
+   public DummyEvictionConfiguration clone() throws CloneNotSupportedException
+   {
+      return (DummyEvictionConfiguration) super.clone();
    }   
+   
+   
 }




More information about the jbosscache-commits mailing list