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

Manik Surtani msurtani at jboss.com
Wed Sep 13 11:53:04 EDT 2006


  User: msurtani
  Date: 06/09/13 11:53:04

  Modified:    src/org/jboss/cache/config   Configuration.java
  Added:       src/org/jboss/cache/config   Dynamic.java
  Log:
  - Added unit test for cache API
  - Added facility for making certain config elements immutable
  
  Revision  Changes    Path
  1.18      +305 -254  JBossCache/src/org/jboss/cache/config/Configuration.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Configuration.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/config/Configuration.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- Configuration.java	6 Sep 2006 15:30:54 -0000	1.17
  +++ Configuration.java	13 Sep 2006 15:53:04 -0000	1.18
  @@ -8,6 +8,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.TreeCache;
   import org.jboss.cache.Version;
   import org.jboss.cache.lock.IsolationLevel;
   import org.w3c.dom.Attr;
  @@ -22,169 +23,93 @@
    */
   public class Configuration
   {
  +   private Log log = LogFactory.getLog(Configuration.class);
  +   private TreeCache cache; // back-reference to test whether the cache is running.
  +
  +   /**
  +    * Public enum that encapsulates cache mode
  +    */
      public enum CacheMode
      {
         LOCAL, REPL_SYNC, REPL_ASYNC, INVALIDATION_SYNC, INVALIDATION_ASYNC }
   
  +   /**
  +    * Public enum that encapsulates node locking scheme
  +    */
      public enum NodeLockingScheme
      {
         PESSIMISTIC, OPTIMISTIC }
   
  -   private Log log = LogFactory.getLog(Configuration.class);
  -
      /**
       * Default replication version, from {@link Version#getVersionShort}.
       */
      private static final short DEFAULT_REPLICATION_VERSION = Version.getVersionShort();
   
  -   /**
  -    * Default cluster name.
  -    */
  -   private String clusterName = "TreeCache-Group";
  +   // ------------------------------------------------------------------------------------------------------------
  +   //   CONFIGURATION OPTIONS
  +   // ------------------------------------------------------------------------------------------------------------
   
  -   /**
  -    * Default cluster properties.
  -    */
  +   private String clusterName = "TreeCache-Group";
      private String clusterConfig = null;
  -
  -   /**
  -    * True if replication is queued.
  -    */
      private boolean useReplQueue = false;
  -
  -   /**
  -    * Maximum number of replicated elements to queue.
  -    */
  +   @Dynamic
      private int replQueueMaxElements = 1000;
  -
  -   /**
  -    * Replicated element queue interval.
  -    */
  +   @Dynamic
      private long replQueueInterval = 5000;
  -
  -   /**
  -    * True if MBean interceptors are used.
  -    */
      private boolean useInterceptorMbeans = true;
  -
      private boolean fetchInMemoryState = true;
  -
      private short replicationVersion = DEFAULT_REPLICATION_VERSION;
      private String replVersionString = Version.getVersionString(DEFAULT_REPLICATION_VERSION);
  -
  +   @Dynamic
      private long lockAcquisitionTimeout = 10000;
  -
  +   @Dynamic
      private long syncReplTimeout = 15000;
      private String evictionPolicyClass = null;
      private CacheMode cacheMode = CacheMode.LOCAL;
      private boolean inactiveOnStartup = false;
  -
      private String serviceName;
  -
      private long initialStateRetrievalTimeout = 10000;
  -
  -   /**
  -    * Isolation level in use, default is {@link org.jboss.cache.lock.IsolationLevel#REPEATABLE_READ}.
  -    */
      private IsolationLevel isolationLevel = IsolationLevel.REPEATABLE_READ;
  -
  -   /**
  -    * Eviction policy configuration in xml Element
  -    */
  +   @Dynamic
      private Element evictionPolicyConfig = null;
  -
  -
  -   /**
  -    * True if we use region based marshalling.  Defaults to false.
  -    */
      private boolean useRegionBasedMarshalling = false;
  -
  -
  -   /**
  -    * Class of the implementation of TransactionManagerLookup
  -    */
      private String transactionManagerLookupClass = null;
  -
  -   /**
  -    * The XML Element from which to configure the CacheLoader
  -    */
      private Element cacheLoaderConfiguration = null;
  -
  -   /**
  -    * True if there is a synchronous commit phase, otherwise asynchronous commit.
  -    */
  +   @Dynamic
      private boolean syncCommitPhase = false;
  -
  -   /**
  -    * True if there is a synchronous rollback phase, otherwise asynchronous rollback.
  -    */
  +   @Dynamic
      private boolean syncRollbackPhase = false;
  -
  -   /**
  -    * Buddy replication configuration XML element
  -    */
      private Element buddyReplicationConfig;
  -
      private boolean nodeLockingOptimistic = false;
      private NodeLockingScheme nodeLockingScheme = NodeLockingScheme.PESSIMISTIC;
  -
  -   /**
  -    * The JGroups multiplexer service name; null if the multiplexer isn't used
  -    */
      private String muxServiceName = null;
  -
  -   /**
  -    * The JGroups multiplexer stack name, default is "fc-fast-minimalthreads"
  -    */
      private String muxStackName = "fc-fast-minimalthreads";
   
  -   String parseClusterConfigXml(Element config)
  -   {
  -      StringBuffer buffer = new StringBuffer();
  -      NodeList stack = config.getChildNodes();
  -      int length = stack.getLength();
  +   // ------------------------------------------------------------------------------------------------------------
  +   //   CONSTRUCTORS
  +   // ------------------------------------------------------------------------------------------------------------
   
  -      for (int s = 0; s < length; s++)
  -      {
  -         org.w3c.dom.Node node = stack.item(s);
  -         if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
  +   /**
  +    * Sets a reference to an existing TreeCache instance
  +    *
  +    * @param cache
  +    */
  +   public Configuration(TreeCache cache)
            {
  -            continue;
  +      this.cache = cache;
            }
   
  -         Element tag = (Element) node;
  -         String protocol = tag.getTagName();
  -         buffer.append(protocol);
  -         NamedNodeMap attrs = tag.getAttributes();
  -         int attrLength = attrs.getLength();
  -         if (attrLength > 0)
  -         {
  -            buffer.append('(');
  -         }
  -         for (int a = 0; a < attrLength; a++)
  -         {
  -            Attr attr = (Attr) attrs.item(a);
  -            String name = attr.getName();
  -            String value = attr.getValue();
  -            buffer.append(name);
  -            buffer.append('=');
  -            buffer.append(value);
  -            if (a < attrLength - 1)
  -            {
  -               buffer.append(';');
  -            }
  -         }
  -         if (attrLength > 0)
  +   /**
  +    * Default empty constructor
  +    */
  +   public Configuration()
            {
  -            buffer.append(')');
  -         }
  -         buffer.append(':');
  -      }
  -      // Remove the trailing ':'
  -      buffer.setLength(buffer.length() - 1);
  -      return buffer.toString();
      }
   
  +   // ------------------------------------------------------------------------------------------------------------
  +   //   SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
  +   // ------------------------------------------------------------------------------------------------------------
  +
      /**
       * Converts a list of elements to a Java Groups property string.
       */
  @@ -193,291 +118,349 @@
         setClusterConfig(parseClusterConfigXml(config));
      }
   
  -   public boolean isNodeLockingOptimistic()
  +   public void setClusterName(String clusterName)
      {
  -      return nodeLockingOptimistic;
  +      testImmutability("clusterName");
  +      this.clusterName = clusterName;
      }
   
  -   public boolean isUseReplQueue()
  +   public void setClusterConfig(String clusterConfig)
      {
  -      return useReplQueue;
  +      testImmutability("clusterConfig");
  +      this.clusterConfig = clusterConfig;
      }
   
  -   public String getClusterName()
  +   public void setReplQueueMaxElements(int replQueueMaxElements)
      {
  -      return clusterName;
  +      testImmutability("replQueueMaxElements");
  +      this.replQueueMaxElements = replQueueMaxElements;
      }
   
  -   public void setClusterName(String clusterName)
  +   public void setReplQueueInterval(long replQueueInterval)
      {
  -      this.clusterName = clusterName;
  +      testImmutability("replQueueInterval");
  +      this.replQueueInterval = replQueueInterval;
      }
   
  -   public String getClusterConfig()
  +   public void setUseInterceptorMbeans(boolean useInterceptorMbeans)
      {
  -      return clusterConfig;
  +      testImmutability("useInterceptorMbeans");
  +      this.useInterceptorMbeans = useInterceptorMbeans;
      }
   
  -   public void setClusterConfig(String clusterConfig)
  +   public void setFetchInMemoryState(boolean fetchInMemoryState)
      {
  -      this.clusterConfig = clusterConfig;
  +      testImmutability("fetchInMemoryState");
  +      this.fetchInMemoryState = fetchInMemoryState;
      }
   
  -   public int getReplQueueMaxElements()
  +   public void setReplicationVersion(short replicationVersion)
      {
  -      return replQueueMaxElements;
  +      testImmutability("replicationVersion");
  +      this.replicationVersion = replicationVersion;
      }
   
  -   public void setReplQueueMaxElements(int replQueueMaxElements)
  +   public void setReplVersionString(String replVersionString)
      {
  -      this.replQueueMaxElements = replQueueMaxElements;
  +      testImmutability("replVersionString");
  +      this.replVersionString = replVersionString;
      }
   
  -   public long getReplQueueInterval()
  +   public void setLockAcquisitionTimeout(long lockAcquisitionTimeout)
      {
  -      return replQueueInterval;
  +      testImmutability("lockAcquisitionTimeout");
  +      this.lockAcquisitionTimeout = lockAcquisitionTimeout;
      }
   
  -   public void setReplQueueInterval(long replQueueInterval)
  +   public void setSyncReplTimeout(long syncReplTimeout)
      {
  -      this.replQueueInterval = replQueueInterval;
  +      testImmutability("syncReplTimeout");
  +      this.syncReplTimeout = syncReplTimeout;
      }
   
  -   public boolean isUseInterceptorMbeans()
  +   public void setEvictionPolicyClass(String evictionPolicyClass)
      {
  -      return useInterceptorMbeans;
  +      testImmutability("evictionPolicyClass");
  +      this.evictionPolicyClass = evictionPolicyClass;
      }
   
  -   public void setUseInterceptorMbeans(boolean useInterceptorMbeans)
  +   public void setCacheMode(CacheMode cacheModeInt)
      {
  -      this.useInterceptorMbeans = useInterceptorMbeans;
  +      testImmutability("cacheMode");
  +      this.cacheMode = cacheModeInt;
      }
   
  -   public boolean isFetchInMemoryState()
  +   public void setCacheMode(String cacheMode)
      {
  -      return fetchInMemoryState;
  +      testImmutability("cacheMode");
  +      if (cacheMode == null) throw new ConfigurationException("Cache mode cannot be null", "CacheMode");
  +      this.cacheMode = CacheMode.valueOf(cacheMode.toUpperCase());
  +      if (this.cacheMode == null)
  +      {
  +         log.warn("Unknown cache mode '" + cacheMode + "', using defaults.");
  +         this.cacheMode = CacheMode.LOCAL;
  +      }
      }
   
  -   public void setFetchInMemoryState(boolean fetchInMemoryState)
  +   public void setInactiveOnStartup(boolean inactiveOnStartup)
      {
  -      this.fetchInMemoryState = fetchInMemoryState;
  +      testImmutability("inactiveOnStartup");
  +      this.inactiveOnStartup = inactiveOnStartup;
      }
   
  -   public short getReplicationVersion()
  +   public void setEvictionPolicyConfig(Element evictionPolicyConfig)
      {
  -      return replicationVersion;
  +      testImmutability("evictionPolicyConfig");
  +      this.evictionPolicyConfig = evictionPolicyConfig;
      }
   
  -   public void setReplicationVersion(short replicationVersion)
  +   public void setUseRegionBasedMarshalling(boolean useRegionBasedMarshalling)
      {
  -      this.replicationVersion = replicationVersion;
  +      testImmutability("useRegionBasedMarshalling");
  +      this.useRegionBasedMarshalling = useRegionBasedMarshalling;
      }
   
  -   public String getReplVersionString()
  +   public void setTransactionManagerLookupClass(String transactionManagerLookupClass)
      {
  -      return replVersionString;
  +      testImmutability("transactionManagerLookupClass");
  +      this.transactionManagerLookupClass = transactionManagerLookupClass;
      }
   
  -   public void setReplVersionString(String replVersionString)
  +   public void setCacheLoaderConfiguration(Element cacheLoaderConfiguration)
      {
  -      this.replVersionString = replVersionString;
  +      testImmutability("cacheLoaderConfiguration");
  +      this.cacheLoaderConfiguration = cacheLoaderConfiguration;
      }
   
  -   public long getLockAcquisitionTimeout()
  +   public void setSyncCommitPhase(boolean syncCommitPhase)
      {
  -      return lockAcquisitionTimeout;
  +      testImmutability("syncCommitPhase");
  +      this.syncCommitPhase = syncCommitPhase;
      }
   
  -   public void setLockAcquisitionTimeout(long lockAcquisitionTimeout)
  +   public void setSyncRollbackPhase(boolean syncRollbackPhase)
      {
  -      this.lockAcquisitionTimeout = lockAcquisitionTimeout;
  +      testImmutability("syncRollbackPhase");
  +      this.syncRollbackPhase = syncRollbackPhase;
      }
   
  -   public long getSyncReplTimeout()
  +   public void setBuddyReplicationConfig(Element buddyReplicationConfig)
      {
  -      return syncReplTimeout;
  +      testImmutability("buddyReplicationConfig");
  +      this.buddyReplicationConfig = buddyReplicationConfig;
      }
   
  -   public void setSyncReplTimeout(long syncReplTimeout)
  +   public void setNodeLockingScheme(NodeLockingScheme nodeLockingScheme)
      {
  -      this.syncReplTimeout = syncReplTimeout;
  +      testImmutability("nodeLockingScheme");
  +      testImmutability("nodeLockingOptimistic");
  +      this.nodeLockingScheme = nodeLockingScheme;
  +      this.nodeLockingOptimistic = (nodeLockingScheme == NodeLockingScheme.OPTIMISTIC);
      }
   
  -   public String getEvictionPolicyClass()
  +   public void setUseReplQueue(boolean useReplQueue)
      {
  -      return evictionPolicyClass;
  +      testImmutability("useReplQueue");
  +      this.useReplQueue = useReplQueue;
      }
   
  -   public void setEvictionPolicyClass(String evictionPolicyClass)
  +   public void setIsolationLevel(IsolationLevel isolationLevel)
      {
  -      this.evictionPolicyClass = evictionPolicyClass;
  +      testImmutability("isolationLevel");
  +      this.isolationLevel = isolationLevel;
      }
   
  -   public CacheMode getCacheMode()
  +   public void setNodeLockingOptimistic(boolean nodeLockingOptimistic)
      {
  -      return cacheMode;
  +      testImmutability("nodeLockingOptimistic");
  +      this.nodeLockingOptimistic = nodeLockingOptimistic;
      }
   
  -   public void setCacheMode(CacheMode cacheModeInt)
  +   public void setInitialStateRetrievalTimeout(long initialStateRetrievalTimeout)
      {
  -      this.cacheMode = cacheModeInt;
  +      testImmutability("initialStateRetrievalTimeout");
  +      this.initialStateRetrievalTimeout = initialStateRetrievalTimeout;
      }
   
  -   public void setCacheMode(String cacheMode)
  +   public void setNodeLockingScheme(String nodeLockingScheme)
      {
  -      if (cacheMode == null) throw new ConfigurationException("Cache mode cannot be null", "CacheMode");
  -      this.cacheMode = CacheMode.valueOf(cacheMode.toUpperCase());
  -      if (this.cacheMode == null)
  +      testImmutability("nodeLockingScheme");
  +      testImmutability("nodeLockingOptimistic");
  +      if (nodeLockingScheme == null)
  +         throw new ConfigurationException("Node locking scheme cannot be null", "NodeLockingScheme");
  +      this.nodeLockingScheme = NodeLockingScheme.valueOf(nodeLockingScheme.toUpperCase());
  +      if (this.nodeLockingScheme == null)
         {
  -         log.warn("Unknown cache mode '" + cacheMode + "', using defaults.");
  -         this.cacheMode = CacheMode.LOCAL;
  +         log.warn("Unknown node locking scheme '" + nodeLockingScheme + "', using defaults.");
  +         this.nodeLockingScheme = NodeLockingScheme.PESSIMISTIC;
         }
  +
  +      this.nodeLockingOptimistic = (this.nodeLockingScheme == NodeLockingScheme.OPTIMISTIC);
      }
   
  -   public boolean isInactiveOnStartup()
  +   public void setIsolationLevel(String isolationLevel)
      {
  -      return inactiveOnStartup;
  +      testImmutability("isolationLevel");
  +      if (isolationLevel == null) throw new ConfigurationException("Isolation level cannot be null", "IsolationLevel");
  +      this.isolationLevel = IsolationLevel.valueOf(isolationLevel.toUpperCase());
  +      if (this.isolationLevel == null)
  +      {
  +         log.warn("Unknown isolation level '" + isolationLevel + "', using defaults.");
  +         this.isolationLevel = IsolationLevel.REPEATABLE_READ;
  +      }
      }
   
  -   public void setInactiveOnStartup(boolean inactiveOnStartup)
  +   public void setMultiplexerStack(String stackName)
      {
  -      this.inactiveOnStartup = inactiveOnStartup;
  +      testImmutability("muxStackName");
  +      this.muxStackName = stackName;
      }
   
  -   public IsolationLevel getIsolationLevel()
  +   public void setMultiplexerService(String serviceName)
      {
  -      return isolationLevel;
  +      testImmutability("muxServiceName");
  +      this.muxServiceName = serviceName;
      }
   
  -   public Element getEvictionPolicyConfig()
  +   /**
  +    * Sets the JMX service name to bind the cache to.
  +    *
  +    * @param serviceName
  +    */
  +   public void setServiceName(String serviceName)
      {
  -      return evictionPolicyConfig;
  +      testImmutability("serviceName");
  +      this.serviceName = serviceName;
      }
   
  -   public void setEvictionPolicyConfig(Element evictionPolicyConfig)
  +   // ------------------------------------------------------------------------------------------------------------
  +   //   GETTERS
  +   // ------------------------------------------------------------------------------------------------------------
  +
  +
  +   public boolean isNodeLockingOptimistic()
      {
  -      this.evictionPolicyConfig = evictionPolicyConfig;
  +      return nodeLockingOptimistic;
      }
   
  -   public boolean isUseRegionBasedMarshalling()
  +   public boolean isUseReplQueue()
      {
  -      return useRegionBasedMarshalling;
  +      return useReplQueue;
      }
   
  -   public void setUseRegionBasedMarshalling(boolean useRegionBasedMarshalling)
  +   public String getClusterName()
      {
  -      this.useRegionBasedMarshalling = useRegionBasedMarshalling;
  +      return clusterName;
      }
   
  -   public String getTransactionManagerLookupClass()
  +   public String getClusterConfig()
      {
  -      return transactionManagerLookupClass;
  +      return clusterConfig;
      }
   
  -   public void setTransactionManagerLookupClass(String transactionManagerLookupClass)
  +   public int getReplQueueMaxElements()
      {
  -      this.transactionManagerLookupClass = transactionManagerLookupClass;
  +      return replQueueMaxElements;
      }
   
  -   public Element getCacheLoaderConfiguration()
  +   public long getReplQueueInterval()
      {
  -      return cacheLoaderConfiguration;
  +      return replQueueInterval;
      }
   
  -   public void setCacheLoaderConfiguration(Element cacheLoaderConfiguration)
  +   public boolean isUseInterceptorMbeans()
      {
  -      this.cacheLoaderConfiguration = cacheLoaderConfiguration;
  +      return useInterceptorMbeans;
      }
   
  -   public boolean isSyncCommitPhase()
  +   public boolean isFetchInMemoryState()
      {
  -      return syncCommitPhase;
  +      return fetchInMemoryState;
      }
   
  -   public void setSyncCommitPhase(boolean syncCommitPhase)
  +   public short getReplicationVersion()
      {
  -      this.syncCommitPhase = syncCommitPhase;
  +      return replicationVersion;
      }
   
  -   public boolean isSyncRollbackPhase()
  +   public String getReplVersionString()
      {
  -      return syncRollbackPhase;
  +      return replVersionString;
      }
   
  -   public void setSyncRollbackPhase(boolean syncRollbackPhase)
  +   public long getLockAcquisitionTimeout()
      {
  -      this.syncRollbackPhase = syncRollbackPhase;
  +      return lockAcquisitionTimeout;
      }
   
  -   public Element getBuddyReplicationConfig()
  +   public long getSyncReplTimeout()
      {
  -      return buddyReplicationConfig;
  +      return syncReplTimeout;
      }
   
  -   public void setBuddyReplicationConfig(Element buddyReplicationConfig)
  +   public String getEvictionPolicyClass()
      {
  -      this.buddyReplicationConfig = buddyReplicationConfig;
  +      return evictionPolicyClass;
      }
   
  -   public NodeLockingScheme getNodeLockingScheme()
  +   public CacheMode getCacheMode()
      {
  -      return nodeLockingScheme;
  +      return cacheMode;
      }
   
  -   public void setNodeLockingScheme(NodeLockingScheme nodeLockingScheme)
  +   public boolean isInactiveOnStartup()
      {
  -      this.nodeLockingScheme = nodeLockingScheme;
  -      this.nodeLockingOptimistic = (nodeLockingScheme == NodeLockingScheme.OPTIMISTIC);
  +      return inactiveOnStartup;
      }
   
  -   public void setUseReplQueue(boolean useReplQueue)
  +   public IsolationLevel getIsolationLevel()
      {
  -      this.useReplQueue = useReplQueue;
  +      return isolationLevel;
      }
   
  -   public void setIsolationLevel(IsolationLevel isolationLevel)
  +   public Element getEvictionPolicyConfig()
      {
  -      this.isolationLevel = isolationLevel;
  +      return evictionPolicyConfig;
      }
   
  -   public void setNodeLockingOptimistic(boolean nodeLockingOptimistic)
  +   public boolean isUseRegionBasedMarshalling()
      {
  -      this.nodeLockingOptimistic = nodeLockingOptimistic;
  +      return useRegionBasedMarshalling;
      }
   
  -   public long getInitialStateRetrievalTimeout()
  +   public String getTransactionManagerLookupClass()
      {
  -      return initialStateRetrievalTimeout;
  +      return transactionManagerLookupClass;
      }
   
  -   public void setInitialStateRetrievalTimeout(long initialStateRetrievalTimeout)
  +   public Element getCacheLoaderConfiguration()
      {
  -      this.initialStateRetrievalTimeout = initialStateRetrievalTimeout;
  +      return cacheLoaderConfiguration;
      }
   
  -   public void setNodeLockingScheme(String nodeLockingScheme)
  -   {
  -      if (nodeLockingScheme == null)
  -         throw new ConfigurationException("Node locking scheme cannot be null", "NodeLockingScheme");
  -      this.nodeLockingScheme = NodeLockingScheme.valueOf(nodeLockingScheme.toUpperCase());
  -      if (this.nodeLockingScheme == null)
  +   public boolean isSyncCommitPhase()
         {
  -         log.warn("Unknown node locking scheme '" + nodeLockingScheme + "', using defaults.");
  -         this.nodeLockingScheme = NodeLockingScheme.PESSIMISTIC;
  +      return syncCommitPhase;
         }
   
  -      this.nodeLockingOptimistic = (this.nodeLockingScheme == NodeLockingScheme.OPTIMISTIC);
  +   public boolean isSyncRollbackPhase()
  +   {
  +      return syncRollbackPhase;
      }
   
  -   public void setIsolationLevel(String isolationLevel)
  +   public Element getBuddyReplicationConfig()
      {
  -      if (isolationLevel == null) throw new ConfigurationException("Isolation level cannot be null", "IsolationLevel");
  -      this.isolationLevel = IsolationLevel.valueOf(isolationLevel.toUpperCase());
  -      if (this.isolationLevel == null)
  +      return buddyReplicationConfig;
  +   }
  +
  +   public NodeLockingScheme getNodeLockingScheme()
         {
  -         log.warn("Unknown isolation level '" + isolationLevel + "', using defaults.");
  -         this.isolationLevel = IsolationLevel.REPEATABLE_READ;
  +      return nodeLockingScheme;
         }
  +
  +   public long getInitialStateRetrievalTimeout()
  +   {
  +      return initialStateRetrievalTimeout;
      }
   
      public String getMultiplexerStack()
  @@ -485,39 +468,109 @@
         return muxStackName;
      }
   
  -   public void setMultiplexerStack(String stackName)
  +   public String getMultiplexerService()
      {
  -      this.muxStackName = stackName;
  +      return muxServiceName;
      }
   
  -   public String getMultiplexerService()
  +   /**
  +    * Retrieves the JMX service name to bind the cache to, if any.
  +    */
  +   public String getServiceName()
      {
  -      return muxServiceName;
  +      return serviceName;
      }
   
  -   public void setMultiplexerService(String serviceName)
  +   // ------------------------------------------------------------------------------------------------------------
  +   //   HELPERS
  +   // ------------------------------------------------------------------------------------------------------------
  +
  +
  +   /**
  +    * Parses the cluster config which is used to start a JGroups channel
  +    *
  +    * @param config
  +    */
  +   String parseClusterConfigXml(Element config)
      {
  -      this.muxServiceName = serviceName;
  +      StringBuffer buffer = new StringBuffer();
  +      NodeList stack = config.getChildNodes();
  +      int length = stack.getLength();
  +
  +      for (int s = 0; s < length; s++)
  +      {
  +         org.w3c.dom.Node node = stack.item(s);
  +         if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
  +         {
  +            continue;
  +         }
  +
  +         Element tag = (Element) node;
  +         String protocol = tag.getTagName();
  +         buffer.append(protocol);
  +         NamedNodeMap attrs = tag.getAttributes();
  +         int attrLength = attrs.getLength();
  +         if (attrLength > 0)
  +         {
  +            buffer.append('(');
  +         }
  +         for (int a = 0; a < attrLength; a++)
  +         {
  +            Attr attr = (Attr) attrs.item(a);
  +            String name = attr.getName();
  +            String value = attr.getValue();
  +            buffer.append(name);
  +            buffer.append('=');
  +            buffer.append(value);
  +            if (a < attrLength - 1)
  +            {
  +               buffer.append(';');
  +            }
  +         }
  +         if (attrLength > 0)
  +         {
  +            buffer.append(')');
  +         }
  +         buffer.append(':');
  +      }
  +      // Remove the trailing ':'
  +      buffer.setLength(buffer.length() - 1);
  +      return buffer.toString();
      }
   
      /**
  -    * Retrieves the JMX service name to bind the cache to, if any.
  +    * Checks field modifications via setters
  +    *
  +    * @param fieldName
       */
  -   public String getServiceName()
  +   private void testImmutability(String fieldName)
      {
  -      return serviceName;
  +      try
  +      {
  +         if (cache != null && cache.started && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
  +            throw new ConfigurationException("Attempted to modify a non-Dymnamic configuration element after the cache has started!");
  +      }
  +      catch (NoSuchFieldException e)
  +      {
  +         log.warn("Field " + fieldName + " not found!!");
  +      }
      }
   
      /**
  -    * Sets the JMX service name to bind the cache to.
  +    * Sets a back-reference to the cache associated with this configuration
       *
  -    * @param serviceName
  +    * @param cache
       */
  -   public void setServiceName(String serviceName)
  +   public void setTreeCache(TreeCache cache)
      {
  -      this.serviceName = serviceName;
  +      this.cache = cache;
      }
   
  +   // ------------------------------------------------------------------------------------------------------------
  +   //   OVERRIDDEN METHODS
  +   // ------------------------------------------------------------------------------------------------------------
  +
  +
      public boolean equals(Object o)
      {
         if (this == o) return true;
  @@ -592,6 +645,4 @@
         result = 29 * result + (muxStackName != null ? muxStackName.hashCode() : 0);
         return result;
      }
  -
  -
   }
  
  
  
  1.1      date: 2006/09/13 15:53:04;  author: msurtani;  state: Exp;JBossCache/src/org/jboss/cache/config/Dynamic.java
  
  Index: Dynamic.java
  ===================================================================
  package org.jboss.cache.config;
  
  import java.lang.annotation.Documented;
  import java.lang.annotation.ElementType;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  import java.lang.annotation.Target;
  
  /**
   * Annotation that marks fields in {@link Configuration} as being modifiable even after the cache has started.
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   * @since 2.0.0
   */
  
  // ensure this annotation is available at runtime.
  @Retention(RetentionPolicy.RUNTIME)
  
  // ensure that this annotation is documented on fields in Configuration
  @Documented
  
  // only applies to fields.
  @Target(ElementType.FIELD)
  
  public @interface Dynamic
  {
  }
  
  
  



More information about the jboss-cvs-commits mailing list