[jbosscache-commits] JBoss Cache SVN: r5898 - core/trunk/src/main/java/org/jboss/cache/config.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed May 28 11:14:41 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-05-28 11:14:41 -0400 (Wed, 28 May 2008)
New Revision: 5898

Added:
   core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java
Modified:
   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/ConfigurationComponent.java
Log:
JBCACHE-1138: User extensible configuration should be centralised - configuration settings allowing <class> and <properties> defintions

Modified: core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java	2008-05-28 14:54:46 UTC (rev 5897)
+++ core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java	2008-05-28 15:14:41 UTC (rev 5898)
@@ -170,77 +170,39 @@
       return clone;
    }
 
-   public static class BuddyLocatorConfig extends ConfigurationComponent
+   public static class BuddyLocatorConfig extends PluggableConfigurationComponent
    {
       private static final long serialVersionUID = -8003634097931826091L;
 
-      private String buddyLocatorClass = NextMemberBuddyLocator.class.getName();
-      private Properties buddyLocatorProperties;
+      public BuddyLocatorConfig()
+      {
+         // default
+         className = NextMemberBuddyLocator.class.getName();
+      }
 
       public String getBuddyLocatorClass()
       {
-         return buddyLocatorClass;
+         return className;
       }
 
       public void setBuddyLocatorClass(String buddyLocatorClass)
       {
-         testImmutability("buddyLocatorClass");
-         this.buddyLocatorClass = buddyLocatorClass;
-         if (buddyLocatorClass == null)
-            this.buddyLocatorClass = NextMemberBuddyLocator.class.getName();
+         setClassName(buddyLocatorClass);
       }
 
       public Properties getBuddyLocatorProperties()
       {
-         return buddyLocatorProperties;
+         return properties;
       }
 
       public void setBuddyLocatorProperties(Properties buddyLocatorProperties)
       {
-         testImmutability("buddyLocatorProperties");
-         this.buddyLocatorProperties = buddyLocatorProperties;
+         setProperties(buddyLocatorProperties);
       }
 
-      @Override
-      public boolean equals(Object obj)
-      {
-         if (this == obj)
-            return true;
-
-         if (obj instanceof BuddyLocatorConfig)
-         {
-            BuddyLocatorConfig other = (BuddyLocatorConfig) obj;
-            return (Util.safeEquals(this.buddyLocatorClass, other.buddyLocatorClass)
-                  && Util.safeEquals(this.buddyLocatorProperties, other.buddyLocatorProperties));
-         }
-         return false;
-      }
-
-      @Override
-      public int hashCode()
-      {
-         int result = 19;
-         result = 41 * result + (buddyLocatorClass == null ? 0 : buddyLocatorClass.hashCode());
-         result = 41 * result + (buddyLocatorProperties == null ? 0 : buddyLocatorProperties.hashCode());
-         return result;
-      }
-
-      @Override
-      public String toString()
-      {
-         return super.toString() + " class=" + buddyLocatorClass +
-               " properties=" + buddyLocatorProperties;
-      }
-
-      @Override
       public BuddyLocatorConfig clone() throws CloneNotSupportedException
       {
-         BuddyLocatorConfig clone = (BuddyLocatorConfig) super.clone();
-         if (buddyLocatorProperties != null)
-            clone.buddyLocatorProperties = (Properties) buddyLocatorProperties.clone();
-         return clone;
+         return (BuddyLocatorConfig) super.clone();
       }
-
-
    }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java	2008-05-28 14:54:46 UTC (rev 5897)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java	2008-05-28 15:14:41 UTC (rev 5898)
@@ -9,10 +9,7 @@
 import org.jboss.cache.loader.CacheLoader;
 import org.jboss.cache.loader.SingletonStoreCacheLoader;
 import org.jboss.cache.util.Util;
-import org.jboss.cache.xml.XmlHelper;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -170,19 +167,16 @@
     * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
     * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
     */
-   public static class IndividualCacheLoaderConfig extends ConfigurationComponent
+   public static class IndividualCacheLoaderConfig extends PluggableConfigurationComponent
    {
       private static final long serialVersionUID = -2282396799100828593L;
 
-      private String className;
       private boolean async;
       private boolean ignoreModifications;
       private boolean fetchPersistentState;
 
       private boolean purgeOnStartup;
 
-      private Properties properties;
-
       private SingletonStoreConfig singletonStoreConfig;
       private transient CacheLoader cacheLoader;
 
@@ -215,17 +209,6 @@
          this.fetchPersistentState = fetchPersistentState;
       }
 
-      public void setClassName(String className)
-      {
-         testImmutability("className");
-         this.className = className;
-      }
-
-      public String getClassName()
-      {
-         return className;
-      }
-
       public void setAsync(boolean async)
       {
          testImmutability("async");
@@ -248,31 +231,6 @@
          return ignoreModifications;
       }
 
-      public void setProperties(String properties) throws IOException
-      {
-         if (properties == null) return;
-
-         testImmutability("properties");
-         // JBCACHE-531: escape all backslash characters
-         // replace any "\" that is not preceded by a backslash with "\\"
-         properties = XmlHelper.escapeBackslashes(properties);
-         ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
-         this.properties = new Properties();
-         this.properties.load(is);
-         is.close();
-      }
-
-      public void setProperties(Properties properties)
-      {
-         testImmutability("properties");
-         this.properties = properties;
-      }
-
-      public Properties getProperties()
-      {
-         return properties;
-      }
-
       public void setPurgeOnStartup(boolean purgeOnStartup)
       {
          testImmutability("purgeOnStartup");
@@ -318,11 +276,12 @@
       @Override
       public boolean equals(Object obj)
       {
-         if (!(obj instanceof IndividualCacheLoaderConfig))
-            return false;
-         IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig) obj;
-         return equalsExcludingProperties(i)
-               && Util.safeEquals(this.properties, i.properties);
+         if (super.equals(obj))
+         {
+            IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig) obj;
+            return equalsExcludingProperties(i);
+         }
+         return false;
       }
 
       protected boolean equalsExcludingProperties(Object obj)
@@ -374,8 +333,6 @@
       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());
          clone.cacheLoader = cacheLoader;
@@ -385,7 +342,7 @@
       /**
        * Configuration for a SingletonStoreCacheLoader
        */
-      public static class SingletonStoreConfig extends ConfigurationComponent
+      public static class SingletonStoreConfig extends PluggableConfigurationComponent
       {
          private static final long serialVersionUID = 824251894176131850L;
 
@@ -394,19 +351,10 @@
           */
          private boolean singletonStoreEnabled;
 
-         /**
-          * Class implementing the singleton store functionality.
-          */
-         private String singletonStoreClass;
-
-         /**
-          * Properties of the singleton store.
-          */
-         private Properties singletonStoreproperties;
-
          public SingletonStoreConfig()
          {
-            singletonStoreClass = SingletonStoreCacheLoader.class.getName();
+            // default value
+            className = SingletonStoreCacheLoader.class.getName();
          }
 
          public boolean isSingletonStoreEnabled()
@@ -422,27 +370,22 @@
 
          public String getSingletonStoreClass()
          {
-            return singletonStoreClass;
+            return className;
          }
 
-         public void setSingletonStoreClass(String singletonStoreClass)
+         public void setSingletonStoreClass(String className)
          {
-            testImmutability("singletonStoreClass");
-            if (!singletonStoreClass.equals(""))
-            {
-               this.singletonStoreClass = singletonStoreClass;
-            }
+            setClassName(className);
          }
 
          public Properties getSingletonStoreproperties()
          {
-            return singletonStoreproperties;
+            return properties;
          }
 
-         public void setSingletonStoreproperties(Properties singletonStoreproperties)
+         public void setSingletonStoreproperties(Properties properties)
          {
-            testImmutability("singletonStoreproperties");
-            this.singletonStoreproperties = singletonStoreproperties;
+            setProperties(properties);
          }
 
          @Override
@@ -451,12 +394,10 @@
             if (this == obj)
                return true;
 
-            if (obj instanceof SingletonStoreConfig)
+            if (super.equals(obj))
             {
                SingletonStoreConfig other = (SingletonStoreConfig) obj;
-               return ((this.singletonStoreEnabled == other.singletonStoreEnabled)
-                     && Util.safeEquals(this.singletonStoreClass, other.singletonStoreClass)
-                     && Util.safeEquals(this.singletonStoreproperties, other.singletonStoreproperties));
+               return this.singletonStoreEnabled == other.singletonStoreEnabled;
             }
             return false;
          }
@@ -465,9 +406,8 @@
          public int hashCode()
          {
             int result = 19;
+            result = 41 * result + super.hashCode();
             result = 41 * result + (singletonStoreEnabled ? 0 : 1);
-            result = 41 * result + (singletonStoreClass == null ? 0 : singletonStoreClass.hashCode());
-            result = 41 * result + (singletonStoreproperties == null ? 0 : singletonStoreproperties.hashCode());
             return result;
          }
 
@@ -475,17 +415,14 @@
          public String toString()
          {
             return super.toString() + " enabled=" + singletonStoreEnabled +
-                  " class=" + singletonStoreClass +
-                  " properties=" + singletonStoreproperties;
+                  " class=" + className +
+                  " properties=" + properties;
          }
 
          @Override
          public SingletonStoreConfig clone() throws CloneNotSupportedException
          {
-            SingletonStoreConfig clone = (SingletonStoreConfig) super.clone();
-            if (singletonStoreproperties != null)
-               clone.singletonStoreproperties = (Properties) singletonStoreproperties.clone();
-            return clone;
+            return (SingletonStoreConfig) super.clone();
          }
       }
    }

Modified: core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java	2008-05-28 14:54:46 UTC (rev 5897)
+++ core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java	2008-05-28 15:14:41 UTC (rev 5898)
@@ -28,7 +28,7 @@
  * @version $Revision$
  * @see #testImmutability(String)
  */
-public class ConfigurationComponent implements Serializable, Cloneable
+public abstract class ConfigurationComponent implements Serializable, Cloneable
 {
    private static final long serialVersionUID = 4879873994727821938L;
 

Added: core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java	                        (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java	2008-05-28 15:14:41 UTC (rev 5898)
@@ -0,0 +1,91 @@
+package org.jboss.cache.config;
+
+import org.jboss.cache.xml.XmlHelper;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * A configuration component where the implementation class can be specified, and comes with its own set of properties.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.2.0
+ */
+public abstract class PluggableConfigurationComponent extends ConfigurationComponent
+{
+   protected String className;
+   protected Properties properties;
+
+   public String getClassName()
+   {
+      return className;
+   }
+
+   public void setClassName(String className)
+   {
+      testImmutability("className");
+      this.className = className;
+   }
+
+   public Properties getProperties()
+   {
+      return properties;
+   }
+
+   public void setProperties(Properties properties)
+   {
+      testImmutability("properties");
+      this.properties = properties;
+   }
+
+   public void setProperties(String properties) throws IOException
+   {
+      if (properties == null) return;
+
+      testImmutability("properties");
+      // JBCACHE-531: escape all backslash characters
+      // replace any "\" that is not preceded by a backslash with "\\"
+      properties = XmlHelper.escapeBackslashes(properties);
+      ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
+      this.properties = new Properties();
+      this.properties.load(is);
+      is.close();
+   }
+
+   public boolean equals(Object o)
+   {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      PluggableConfigurationComponent that = (PluggableConfigurationComponent) o;
+
+      if (className != null ? !className.equals(that.className) : that.className != null) return false;
+      if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false;
+
+      return true;
+   }
+
+   public int hashCode()
+   {
+      int result;
+      result = (className != null ? className.hashCode() : 0);
+      result = 31 * result + (properties != null ? properties.hashCode() : 0);
+      return result;
+   }
+
+   @Override
+   public String toString()
+   {
+      return getClass().getSimpleName() + " {className = " + className +
+            ", properties=" + properties + "}";
+   }
+
+   @Override
+   public PluggableConfigurationComponent clone() throws CloneNotSupportedException
+   {
+      PluggableConfigurationComponent clone = (PluggableConfigurationComponent) super.clone();
+      if (properties != null) clone.properties = (Properties) properties.clone();
+      return clone;
+   }
+}




More information about the jbosscache-commits mailing list