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

Manik Surtani msurtani at jboss.com
Sat Dec 30 12:49:57 EST 2006


  User: msurtani
  Date: 06/12/30 12:49:57

  Modified:    src/org/jboss/cache/statetransfer    
                        StateTransferManager.java
                        DefaultStateTransferIntegrator.java
                        DefaultStateTransferGenerator.java
                        StateTransferFactory.java
  Log:
  Major changes to restructure cache and node object model
  
  Revision  Changes    Path
  1.20      +20 -20    JBossCache/src/org/jboss/cache/statetransfer/StateTransferManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StateTransferManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/statetransfer/StateTransferManager.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- StateTransferManager.java	21 Dec 2006 21:41:10 -0000	1.19
  +++ StateTransferManager.java	30 Dec 2006 17:49:57 -0000	1.20
  @@ -9,9 +9,9 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.CacheException;
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  -import org.jboss.cache.TreeCache;
   import org.jboss.cache.config.Option;
   import org.jboss.cache.loader.CacheLoaderManager;
   import org.jboss.cache.loader.NodeData;
  @@ -32,14 +32,14 @@
   
      public static final String PARTIAL_STATE_DELIMETER = "_PARTIAL_STATE_DELIMETER";
   
  -   private final TreeCache cache;
  +   private final CacheImpl cache;
   
  -   public StateTransferManager(TreeCache cache)
  +   public StateTransferManager(CacheImpl cache)
      {
         this.cache = cache;
      }
   
  -   public TreeCache getTreeCache()
  +   public CacheImpl getTreeCache()
      {
         return cache;
      }
  @@ -47,7 +47,7 @@
      /**
       * Writes the state for the portion of the tree named by <code>fqn</code> to 
       * the provided OutputStream.
  -    * 
  +    * <p/>
       * <p/>
       *
       * @param fqn            Fqn indicating the uppermost node in the
  @@ -98,21 +98,21 @@
         {
            out.writeBoolean(false);
            Exception e = null;
  -         if(!canProvideState)
  +         if (!canProvideState)
            {
  -            String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn +".";
  +            String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn + ".";
               
  -            if(marshaller.isInactive(fqn.toString()))
  +            if (marshaller.isInactive(fqn.toString()))
               {
                  exceptionMessage += " Region for fqn " + fqn + " is inactive.";
               }
  -            if(cache.findNode(fqn) == null)
  +            if (cache.findNode(fqn) == null)
               {
                  exceptionMessage += " There is no cache node at fqn " + fqn;
               }
               e = new CacheException(exceptionMessage);           
            }
  -         if(!fetchPersistentState && !fetchTransientState)
  +         if (!fetchPersistentState && !fetchTransientState)
            {
               e = new CacheException("Cache instance at " + cache.getLocalAddress() + " is not configured to provide state");
            }
  @@ -161,7 +161,7 @@
       */
      public void setState(ObjectInputStream in, Fqn targetRoot, ClassLoader cl) throws Exception
      {
  -      TreeCache cache = getTreeCache();
  +      CacheImpl cache = getTreeCache();
         Node target = cache.findNode(targetRoot);
         if (target == null)
         {
  @@ -171,7 +171,7 @@
            target = cache.findNode(targetRoot);
         }
         boolean hasState = in.readBoolean();
  -      if(hasState)
  +      if (hasState)
         {
            setState(in, target, cl);
         }
  
  
  
  1.10      +24 -24    JBossCache/src/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DefaultStateTransferIntegrator.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- DefaultStateTransferIntegrator.java	21 Dec 2006 21:41:10 -0000	1.9
  +++ DefaultStateTransferIntegrator.java	30 Dec 2006 17:49:57 -0000	1.10
  @@ -9,10 +9,10 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.CacheException;
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  -import org.jboss.cache.TreeCache;
  -import org.jboss.cache.TreeNode;
  +import org.jboss.cache.NodeSPI;
   import org.jboss.cache.buddyreplication.BuddyManager;
   import org.jboss.cache.factories.NodeFactory;
   import org.jboss.cache.loader.CacheLoader;
  @@ -30,24 +30,24 @@
   
      protected Log log = LogFactory.getLog(getClass().getName());
   
  -   private TreeCache cache;
  +   private CacheImpl cache;
   
      private Fqn targetFqn;
   
      private NodeFactory factory;
   
  -   private byte nodeType;
  +   private NodeFactory.NodeType nodeType;
   
      private Set internalFqns;
   
  -   public DefaultStateTransferIntegrator(Fqn targetFqn, TreeCache cache)
  +   public DefaultStateTransferIntegrator(Fqn targetFqn, CacheImpl cache)
      {
         this.targetFqn = targetFqn;
         this.cache = cache;
         this.factory = NodeFactory.getInstance();
         this.nodeType = cache.getConfiguration().isNodeLockingOptimistic()
  -              ? NodeFactory.NODE_TYPE_OPTIMISTIC_NODE
  -              : NodeFactory.NODE_TYPE_TREENODE;
  +              ? NodeFactory.NodeType.VERSIONED_NODE
  +              : NodeFactory.NodeType.UNVERSIONED_NODE;
         this.internalFqns = cache.getInternalFqns();
      }
   
  @@ -87,7 +87,7 @@
               // Clear any existing state from the targetRoot
               log.warn("transient state integration failed, removing all children of " + target);
               target.clearData();
  -            ((TreeNode) target).removeChildren();
  +            target.getNodeSPI().removeChildren();
            }
   
            resetClassLoader(oldCL);
  @@ -161,7 +161,7 @@
         }
      }
   
  -   protected TreeCache getCache()
  +   protected CacheImpl getCache()
      {
         return cache;
      }
  @@ -171,7 +171,7 @@
         return factory;
      }
   
  -   protected byte getNodeType()
  +   protected NodeFactory.NodeType getNodeType()
      {
         return nodeType;
      }
  @@ -187,7 +187,7 @@
       */
      private void notifyAllNodesCreated(Node curr)
      {
  -      TreeNode n;
  +      Node n;
   
         if (curr == null) return;
         getCache().getNotifier().notifyNodeCreated(curr.getFqn(), true);
  @@ -195,7 +195,7 @@
         Set children = curr.getChildren();
         for (Iterator it = children.iterator(); it.hasNext();)
         {
  -         n = (TreeNode) it.next();
  +         n = (Node) it.next();
            notifyAllNodesCreated(n);
         }
      }
  @@ -224,7 +224,7 @@
      {
         Set retainedNodes = retainInternalNodes(target);
   
  -      ((TreeNode) target).removeChildren();
  +      target.getNodeSPI().removeChildren();
   
         // Read the first NodeData and integrate into our target     
         NodeData nd = readNode(in);
  @@ -293,8 +293,8 @@
   
            // We handle this NodeData.  Create a TreeNode and
            // integrate its data            
  -         Node target = factory.createDataNode(nodeType, name, fqn, parent, nd.getAttributes(), false, null, cache.getCacheSPI());
  -         ((TreeNode) parent).addChild(name, target);
  +         Node target = factory.createDataNode(nodeType, name, fqn, parent, nd.getAttributes(), false, null, cache);
  +         parent.getNodeSPI().addChild(name, target);
   
            // Recursively call, which will walk down the tree
            // and return the next NodeData that's a child of our parent
  @@ -312,7 +312,7 @@
            Fqn internalFqn = (Fqn) it.next();
            if (internalFqn.isChildOf(targetFqn))
            {
  -            TreeNode internalNode = getInternalNode(target, internalFqn);
  +            Node internalNode = getInternalNode(target, internalFqn);
               if (internalNode != null)
               {
                  result.add(internalNode);
  @@ -323,10 +323,10 @@
         return result;
      }
   
  -   private TreeNode getInternalNode(Node parent, Fqn internalFqn)
  +   private Node getInternalNode(Node parent, Fqn internalFqn)
      {
         Object name = internalFqn.get(parent.getFqn().size());
  -      TreeNode result = (TreeNode) parent.getChild(new Fqn(name));
  +      Node result = parent.getChild(new Fqn(name));
         if (result != null)
         {
            if (internalFqn.size() < result.getFqn().size())
  @@ -343,7 +343,7 @@
         Fqn rootFqn = root.getFqn();
         for (Iterator it = retainedNodes.iterator(); it.hasNext();)
         {
  -         TreeNode retained = (TreeNode) it.next();
  +         Node retained = (Node) it.next();
            if (retained.getFqn().isChildOf(rootFqn))
            {
               integrateRetainedNode(root, retained);
  @@ -351,17 +351,17 @@
         }
      }
   
  -   private void integrateRetainedNode(Node ancestor, TreeNode descendant)
  +   private void integrateRetainedNode(Node ancestor, Node descendant)
      {
         Fqn descFqn = descendant.getFqn();
         Fqn ancFqn = ancestor.getFqn();
         Object name = descFqn.get(ancFqn.size());
  -      TreeNode child = (TreeNode) ancestor.getChild(new Fqn(name));
  +      Node child = ancestor.getChild(new Fqn(name));
         if (ancFqn.size() == descFqn.size() + 1)
         {
            if (child == null)
            {
  -            ((TreeNode) ancestor).addChild(name, descendant);
  +            ancestor.getNodeSPI().addChild(name, descendant);
            }
            else
            {
  @@ -375,8 +375,8 @@
               // Missing level -- have to create empty node
               // This shouldn't really happen -- internal fqns should
               // be immediately under the root
  -            child = factory.createDataNode(nodeType, name, new Fqn(ancFqn, name), ancestor, null, true, null, cache.getCacheSPI());
  -            ((TreeNode) ancestor).addChild(name, child);
  +            child = factory.createDataNode(nodeType, name, new Fqn(ancFqn, name), ancestor, null, true, null, cache);
  +            ((NodeSPI) ancestor).addChild(name, child);
            }
   
            // Keep walking down the tree
  
  
  
  1.8       +7 -7      JBossCache/src/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DefaultStateTransferGenerator.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- DefaultStateTransferGenerator.java	21 Dec 2006 21:41:10 -0000	1.7
  +++ DefaultStateTransferGenerator.java	30 Dec 2006 17:49:57 -0000	1.8
  @@ -8,9 +8,9 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  -import org.jboss.cache.TreeCache;
   import org.jboss.cache.Version;
   import org.jboss.cache.loader.CacheLoader;
   import org.jboss.cache.loader.NodeData;
  @@ -28,11 +28,11 @@
   
      private Log log = LogFactory.getLog(getClass().getName());
   
  -   private TreeCache cache;
  +   private CacheImpl cache;
   
      private Set internalFqns;
   
  -   protected DefaultStateTransferGenerator(TreeCache cache)
  +   protected DefaultStateTransferGenerator(CacheImpl cache)
      {
         this.cache = cache;
         this.internalFqns = cache.getInternalFqns();
  @@ -158,7 +158,7 @@
         // no-op in this base class      
      }
   
  -   protected TreeCache getTreeCache()
  +   protected CacheImpl getTreeCache()
      {
         return cache;
      }
  
  
  
  1.13      +22 -24    JBossCache/src/org/jboss/cache/statetransfer/StateTransferFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StateTransferFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/statetransfer/StateTransferFactory.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- StateTransferFactory.java	12 Sep 2006 21:12:45 -0000	1.12
  +++ StateTransferFactory.java	30 Dec 2006 17:49:57 -0000	1.13
  @@ -6,19 +6,19 @@
    */
   package org.jboss.cache.statetransfer;
   
  -import java.io.IOException;
  -import java.io.ObjectInputStream;
  -
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.TreeCache;
   import org.jboss.cache.Version;
   
  +import java.io.IOException;
  +import java.io.ObjectInputStream;
  +
   /**
    * Factory class able to create {@link StateTransferGenerator} and 
    * {@link StateTransferIntegrator} instances.
    * 
    * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  - * @version $Revision: 1.12 $
  + * @version $Revision: 1.13 $
    */
   public abstract class StateTransferFactory
   {
  @@ -28,13 +28,11 @@
       * Gets the StateTransferGenerator able to handle the given cache instance.
       * 
       * @param cache the cache
  -    * 
       * @return the {@link StateTransferGenerator}
  -    * 
       * @throws IllegalStateException if the cache's ReplicationVersion is < 2.0.0
       */
      public static StateTransferGenerator 
  -         getStateTransferGenerator(TreeCache cache)
  +   getStateTransferGenerator(CacheImpl cache)
      {
         short version = cache.getConfiguration().getReplicationVersion();
         
  @@ -46,7 +44,7 @@
            return new DefaultStateTransferGenerator(cache); // current default
      } 
   
  -   public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream in, Fqn fqn, TreeCache treeCache)
  +   public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream in, Fqn fqn, CacheImpl cache)
            throws Exception
      {
         short version = 0;      
  @@ -61,8 +59,8 @@
            {
               in.close();
            }
  -         catch(IOException ignored){}
  -         throw new IllegalStateException("Stream corrupted ",io);                         
  +         catch (IOException ignored) {}
  +         throw new IllegalStateException("Stream corrupted ", io);
         }
   
         // Compiler won't let me use a switch
  @@ -70,7 +68,7 @@
         if (version < RV_200 && version > 0) // <= 0 is actually a version > 15.31.63
            throw new IllegalStateException("State transfer with cache replication version < 2.0.0 not supported");
         else
  -         return new DefaultStateTransferIntegrator(fqn, treeCache); // current default
  +         return new DefaultStateTransferIntegrator(fqn, cache); // current default
      }      
              
   }
  
  
  



More information about the jboss-cvs-commits mailing list