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

Vladmir Blagojevic vladimir.blagojevic at jboss.com
Tue Sep 12 16:16:55 EDT 2006


  User: vblagojevic
  Date: 06/09/12 16:16:55

  Modified:    src/org/jboss/cache/loader     CacheLoader.java
                        JDBCCacheLoader.java FileCacheLoader.java
                        AbstractCacheLoader.java
  Log:
  store/load moved to AbstractCacheLoader 
  
  Revision  Changes    Path
  1.9       +24 -2     JBossCache/src/org/jboss/cache/loader/CacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/CacheLoader.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- CacheLoader.java	1 Sep 2006 18:46:43 -0000	1.8
  +++ CacheLoader.java	12 Sep 2006 20:16:55 -0000	1.9
  @@ -192,6 +192,12 @@
       * contents of the cache are written to the ObjectOutputStream as a sequence of 
       * NodeData objects.
       * 
  +    * <p>
  +    * Default implementation is provided by {@link AbstractCacheLoader} and ensures cacheloader 
  +    * interoperability. Implementors are encouraged to consider extending AbstractCacheLoader 
  +    * prior to implementing completely custom cacheloader.  
  +    * 
  +    * @see AbstractCacheLoader#loadEntireState(ObjectOutputStream)
       * @see NodeData
       *
       * @param os ObjectOutputStream to write state
  @@ -209,7 +215,12 @@
       * contents of the cache are read from the ObjectInputStream as a sequence of 
       * NodeData objects.
       *  
  +    * <p>
  +    * Default implementation is provided by {@link AbstractCacheLoader} and ensures cacheloader 
  +    * interoperability. Implementors are encouraged to consider extending AbstractCacheLoader 
  +    * prior to implementing completely custom cacheloader. 
       * 
  +    * @see AbstractCacheLoader#storeEntireState(ObjectInputStream)
       * @see NodeData    
       * @param is ObjectInputStream to read state 
       * 
  @@ -229,6 +240,10 @@
       * contents of the cache are written to the ObjectOutputStream as a sequence of 
       * NodeData objects.
       *     
  +    * <p>
  +    * Default implementation is provided by {@link AbstractCacheLoader} and ensures cacheloader 
  +    * interoperability. Implementors are encouraged to consider extending AbstractCacheLoader 
  +    * prior to implementing completely custom cacheloader.     
       * 
       *
       * @param subtree Fqn naming the root (i.e. highest level parent) node of
  @@ -236,6 +251,7 @@
       *                
       * @param os ObjectOutputStream to write state               
       *
  +    * @see AbstractCacheLoader#loadState(Fqn, ObjectOutputStream)
       * @see org.jboss.cache.Region#activate() 
       * @see NodeData
       */
  @@ -266,6 +282,11 @@
       * NodeData objects.
       * <p> 
       *     
  +    * <p>
  +    * Default implementation is provided by {@link AbstractCacheLoader} and ensures cacheloader 
  +    * interoperability. Implementors are encouraged to consider extending AbstractCacheLoader 
  +    * prior to implementing completely custom cacheloader. 
  +    *     
       * @param is ObjectInputStream to read state 
       * @param subtree Fqn naming the root (i.e. highest level parent) node of
       *                the subtree included in <code>state</code>.  If the Fqns
  @@ -274,6 +295,7 @@
       *                Fqns should be altered to make them children of
       *                <code>subtree</code> before they are persisted.
       *                
  +    * @see AbstractCacheLoader#storeState(Fqn, ObjectInputStream)               
       * @see NodeData
       *
       */
  
  
  
  1.14      +3 -146    JBossCache/src/org/jboss/cache/loader/JDBCCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JDBCCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/JDBCCacheLoader.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- JDBCCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.13
  +++ JDBCCacheLoader.java	12 Sep 2006 20:16:55 -0000	1.14
  @@ -75,7 +75,7 @@
    *
    * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
    * @author <a href="mailto:hmesha at novell.com">Hany Mesha </a>
  - * @version <tt>$Revision: 1.13 $</tt>
  + * @version <tt>$Revision: 1.14 $</tt>
    */
   public class JDBCCacheLoader extends AbstractCacheLoader
   {
  @@ -561,81 +561,6 @@
         cf.rollback(tx);
      }
   
  -    /**
  -     * Checks the RegionManager for a classloader registered for the
  -     * given, and if found sets it as the TCCL
  -     *
  -     * @param subtree
  -     */
  -    private void setUnmarshallingClassLoader(Fqn subtree)
  -    {
  -       if (regionManager != null)
  -       {
  -          regionManager.setUnmarshallingClassLoader(subtree);
  -       }
  -    }
  -    
  -    public void loadEntireState(ObjectOutputStream os) throws Exception
  -    {
  -       loadStateHelper(Fqn.ROOT,os);       
  -    }
  -
  -    public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
  -    {
  -       ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  -       try
  -       {
  -          // Set the TCCL to any classloader registered for subtree
  -          setUnmarshallingClassLoader(subtree);                   
  -          loadStateHelper(subtree, os);                   
  -       }
  -       finally
  -       {
  -          Thread.currentThread().setContextClassLoader(currentCL);
  -       }       
  -    }
  -    
  -    public void storeEntireState(ObjectInputStream is) throws Exception
  -    {
  -       storeState(Fqn.ROOT,is);       
  -    }
  -
  -    public void storeState(Fqn subtree, ObjectInputStream in) throws Exception
  -    {
  -       ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  -       try
  -       {
  -          // Set the TCCL to any classloader registered for subtree
  -          setUnmarshallingClassLoader(subtree);         
  -          NodeData nd;
  -
  -          // remove entire existing state
  -          this.remove(subtree);
  -
  -          boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
  -
  -          // store new state
  -          Fqn fqn = null;
  -           
  -          for (nd = (NodeData) in.readObject(); nd != null && !nd.isMarker(); nd = (NodeData) in.readObject())
  -          {
  -             if (moveToBuddy)
  -                fqn = BuddyManager.getBackupFqn(subtree, nd.fqn);
  -             else
  -                fqn = nd.fqn;
  -
  -             if (nd.attrs != null)
  -                this.put(fqn, nd.attrs, true); // creates a node with 0 or more attributes
  -             else
  -                this.put(fqn, null); // creates a node with null attributes                          
  -          }
  -       }
  -       finally
  -       {
  -          Thread.currentThread().setContextClassLoader(currentCL);
  -       }
  -    }  
  -
       // Service implementation
   
      public void create() throws Exception
  @@ -791,75 +716,7 @@
         }
      }
   
  -/*
  -   void loadState(Fqn fqn, ObjectOutputStream out)
  -      throws Exception
  -   {
  -      Map attrs;
  -      Set children_names;
  -      String child_name;
  -      int num_attrs;
  -      Fqn tmp_fqn;
  -
  -      children_names = getChildrenNames(fqn);
  -      attrs = get(fqn);
  -      num_attrs = attrs == null ? -1 : attrs.size();
  -      out.writeObject(fqn);
  -      out.writeInt(num_attrs);
  -      if(attrs != null)
  -      {
  -         out.writeObject(attrs);
  -      }
  -
  -      if(children_names == null)
  -      {
  -         return;
  -      }
  -
  -      for(Iterator it = children_names.iterator(); it.hasNext();)
  -      {
  -         child_name = (String) it.next();
  -         tmp_fqn = new Fqn(fqn, child_name);
  -         loadState(tmp_fqn, out);
  -      }
  -   }
  -*/
  -
  -   /**
  -    * Do a preorder traversal: visit the node first, then the node's children
  -    * @param fqn Start node
  -    * @param out
  -    * @throws Exception
  -    */
  -   protected void loadStateHelper(Fqn fqn, ObjectOutputStream out) throws Exception {
  -      Map       attrs;
  -      Set       children_names;
  -      String    child_name;
  -      Fqn       tmp_fqn;
  -      NodeData  nd;
  -
  -      // first handle the current node
  -      attrs=get(fqn);
  -      if(attrs == null || attrs.size() == 0)
  -         nd=new NodeData(fqn);
  -      else
  -         nd=new NodeData(fqn, attrs);
  -      out.writeObject(nd);
  -
  -      // then visit the children
  -      children_names=getChildrenNames(fqn);
  -      if(children_names == null)
  -         return;
  -      for(Iterator it=children_names.iterator(); it.hasNext();) {
  -         child_name=(String)it.next();
  -         tmp_fqn=new Fqn(fqn, child_name);
  -         loadStateHelper(tmp_fqn, out);
  -      }
  -   }
  -
  -
  -
  -   final void put(Fqn name, Map attributes, boolean override) throws Exception
  +   public void put(Fqn name, Map attributes, boolean override) throws Exception
      {
         Map oldNode = loadNode(name);
         if(oldNode != null)
  
  
  
  1.18      +2 -112    JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FileCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- FileCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.17
  +++ FileCacheLoader.java	12 Sep 2006 20:16:55 -0000	1.18
  @@ -28,7 +28,7 @@
   /**
    * Simple file-based CacheLoader implementation. Nodes are directories, attributes of a node is a file in the directory
    * @author Bela Ban
  - * @version $Id: FileCacheLoader.java,v 1.17 2006/08/31 14:56:45 vblagojevic Exp $
  + * @version $Id: FileCacheLoader.java,v 1.18 2006/09/12 20:16:55 vblagojevic Exp $
    */
   public class FileCacheLoader extends AbstractCacheLoader
   {
  @@ -218,105 +218,10 @@
         transactions.remove(tx);
      }
   
  -   public void loadEntireState(ObjectOutputStream os) throws Exception
  -   {
  -      loadState(Fqn.ROOT,os);      
  -   }
  -
  -   public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
  -   {
  -      ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  -      
  -      try
  -      {
  -         // Set the TCCL to any classloader registered for subtree
  -         setUnmarshallingClassLoader(subtree);                          
  -         loadStateFromFilessystem(subtree, os);                          
  -      }
  -      finally
  -      {
  -         Thread.currentThread().setContextClassLoader(currentCL);
  -      }
  -      
  -   }
  -   
  -   public void storeEntireState(ObjectInputStream is) throws Exception
  -   {
  -      storeState(Fqn.ROOT,is);      
  -   }
  -
  -   public void storeState(Fqn subtree, ObjectInputStream in) throws Exception
  -   {
  -      ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  -      try
  -      {
  -         // Set the TCCL to any classloader registered for subtree
  -         setUnmarshallingClassLoader(subtree);         
  -         NodeData nd;
  -
  -         // remove entire existing state
  -         this.remove(subtree);
   
  -         boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
  -
  -         // store new state
  -         Fqn fqn = null;
  -          
  -         for (nd = (NodeData) in.readObject(); nd != null && !nd.isMarker(); nd = (NodeData) in.readObject())
  -         {
  -            if (moveToBuddy)
  -               fqn = BuddyManager.getBackupFqn(subtree, nd.fqn);
  -            else
  -               fqn = nd.fqn;
  -
  -            if (nd.attrs != null)
  -               this.put(fqn, nd.attrs, true); // creates a node with 0 or more attributes
  -            else
  -               this.put(fqn, null); // creates a node with null attributes                          
  -         }
  -      }
  -      finally
  -      {
  -         Thread.currentThread().setContextClassLoader(currentCL);
  -      }
  -   }  
   
      /* ----------------------- Private methods ------------------------ */
   
  -
  -   /**
  -    * Do a preorder traversal: visit the node first, then the node's children
  -    * @param fqn Start node
  -    * @param out
  -    * @throws Exception
  -    */
  -   protected void loadStateFromFilessystem(Fqn fqn, ObjectOutputStream out) throws Exception {
  -      Map       attrs;
  -      Set       children_names;
  -      String    child_name;
  -      Fqn       tmp_fqn;
  -      NodeData  nd;
  -
  -      // first handle the current node
  -      attrs=get(fqn);
  -      if(attrs == null || attrs.size() == 0)
  -         nd=new NodeData(fqn);
  -      else
  -         nd=new NodeData(fqn, attrs);
  -      out.writeObject(nd);
  -
  -      // then visit the children
  -      children_names=getChildrenNames(fqn);
  -      if(children_names == null)
  -         return;
  -      for(Iterator it=children_names.iterator(); it.hasNext();) {
  -         child_name=(String)it.next();
  -         tmp_fqn=new Fqn(fqn, child_name);
  -         loadStateFromFilessystem(tmp_fqn, out);
  -      }
  -   }
  -
  -
      File getDirectory(Fqn fqn, boolean create) {
         File f=new File(getFullPath(fqn));
         if(!f.exists()) {
  @@ -405,19 +310,4 @@
         output.writeObject(attrs);
         out.close();
      }
  -   
  -   /**
  -    * Checks the RegionManager for a classloader registered for the 
  -    * given, and if found sets it as the TCCL
  -    * 
  -    * @param subtree
  -    */
  -   private void setUnmarshallingClassLoader(Fqn subtree)
  -   {
  -      if (regionManager != null)
  -      {
  -         regionManager.setUnmarshallingClassLoader(subtree);
  -      }
  -   }
  -
   }
  
  
  
  1.2       +125 -0    JBossCache/src/org/jboss/cache/loader/AbstractCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AbstractCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AbstractCacheLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- AbstractCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.1
  +++ AbstractCacheLoader.java	12 Sep 2006 20:16:55 -0000	1.2
  @@ -6,7 +6,15 @@
    */
   package org.jboss.cache.loader;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Set;
  +
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.buddyreplication.BuddyManager;
   import org.jboss.cache.marshall.RegionManager;
   
   /**
  @@ -19,6 +27,77 @@
       protected CacheSPI cache;
       protected RegionManager regionManager;
   
  +    public void put(Fqn fqn, Map attributes, boolean erase) throws Exception
  +    {
  +       if(erase)
  +       {
  +          removeData(fqn);
  +       }
  +       put(fqn, attributes);
  +    }
  +    
  +    public void storeEntireState(ObjectInputStream is) throws Exception
  +    {
  +       storeState(Fqn.ROOT,is);      
  +    }  
  +    
  +    public void storeState(Fqn subtree, ObjectInputStream in) throws Exception
  +    {
  +       ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  +       try
  +       {
  +          // Set the TCCL to any classloader registered for subtree
  +          setUnmarshallingClassLoader(subtree);                   
  +
  +          // remove entire existing state
  +          this.remove(subtree);
  +
  +          boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
  +
  +          // store new state
  +          Fqn fqn = null;
  +          NodeData nd = null;
  +           
  +          for (nd = (NodeData) in.readObject(); nd != null && !nd.isMarker(); nd = (NodeData) in.readObject())
  +          {
  +             if (moveToBuddy)
  +                fqn = BuddyManager.getBackupFqn(subtree, nd.fqn);
  +             else
  +                fqn = nd.fqn;
  +
  +             if (nd.attrs != null)
  +                this.put(fqn, nd.attrs, true); // creates a node with 0 or more attributes
  +             else
  +                this.put(fqn, null); // creates a node with null attributes                          
  +          }
  +       }
  +       finally
  +       {
  +          Thread.currentThread().setContextClassLoader(currentCL);
  +       }
  +    }
  +    
  +    public void loadEntireState(ObjectOutputStream os) throws Exception
  +    {
  +       loadState(Fqn.ROOT,os);       
  +    }
  +
  +    public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
  +    {
  +       ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  +       try
  +       {
  +          // Set the TCCL to any classloader registered for subtree
  +          setUnmarshallingClassLoader(subtree);                   
  +          loadStateHelper(subtree, os);                   
  +       }
  +       finally
  +       {
  +          Thread.currentThread().setContextClassLoader(currentCL);
  +       }       
  +    }
  +    
  +    
       public void setCache(CacheSPI c)
       {
           this.cache = c;
  @@ -28,4 +107,50 @@
       {
           this.regionManager = regionManager;
       }
  +    
  +    /**
  +     * Checks the RegionManager for a classloader registered for the 
  +     * given, and if found sets it as the TCCL
  +     * 
  +     * @param subtree
  +     */
  +    protected void setUnmarshallingClassLoader(Fqn subtree)
  +    {
  +       if (regionManager != null)
  +       {
  +          regionManager.setUnmarshallingClassLoader(subtree);
  +       }
  +    }
  +    
  +    /**
  +     * Do a preorder traversal: visit the node first, then the node's children
  +     * @param fqn Start node
  +     * @param out
  +     * @throws Exception
  +     */
  +    protected void loadStateHelper(Fqn fqn, ObjectOutputStream out) throws Exception {
  +       Map       attrs;
  +       Set       children_names;
  +       String    child_name;
  +       Fqn       tmp_fqn;
  +       NodeData  nd;
  +
  +       // first handle the current node
  +       attrs=get(fqn);
  +       if(attrs == null || attrs.size() == 0)
  +          nd=new NodeData(fqn);
  +       else
  +          nd=new NodeData(fqn, attrs);
  +       out.writeObject(nd);
  +
  +       // then visit the children
  +       children_names=getChildrenNames(fqn);
  +       if(children_names == null)
  +          return;
  +       for(Iterator it=children_names.iterator(); it.hasNext();) {
  +          child_name=(String)it.next();
  +          tmp_fqn=new Fqn(fqn, child_name);
  +          loadStateHelper(tmp_fqn, out);
  +       }
  +    }
   }
  
  
  



More information about the jboss-cvs-commits mailing list