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

Vladmir Blagojevic vladimir.blagojevic at jboss.com
Thu Aug 31 10:56:46 EDT 2006


  User: vblagojevic
  Date: 06/08/31 10:56:46

  Modified:    src/org/jboss/cache/loader              
                        DelegatingCacheLoader.java AsyncCacheLoader.java
                        SharedStoreCacheLoader.java NodeData.java
                        ClusteredCacheLoader.java ChainingCacheLoader.java
                        JDBCCacheLoader.java RpcDelegatingCacheLoader.java
                        TcpDelegatingCacheLoader.java
                        LocalDelegatingCacheLoader.java CacheLoader.java
                        FileCacheLoader.java RmiDelegatingCacheLoader.java
  Added:       src/org/jboss/cache/loader               NodeDataMarker.java
  Log:
  CacheLoader API change (remove byte based load/store)
  
  Revision  Changes    Path
  1.10      +27 -22    JBossCache/src/org/jboss/cache/loader/DelegatingCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DelegatingCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/DelegatingCacheLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- DelegatingCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.9
  +++ DelegatingCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.10
  @@ -11,6 +11,8 @@
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Modification;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  @@ -23,7 +25,7 @@
    * which delegates to a persistent cache.
    * @author Bela Ban
    * @author Daniel Gredler
  - * @version $Id: DelegatingCacheLoader.java,v 1.9 2006/07/19 08:29:18 msurtani Exp $
  + * @version $Id: DelegatingCacheLoader.java,v 1.10 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public abstract class DelegatingCacheLoader extends AbstractCacheLoader {
      Log    log=LogFactory.getLog(getClass());
  @@ -119,22 +121,25 @@
         transactions.remove(tx);
      }
   
  -   public byte[] loadEntireState() throws Exception {
  -      return delegateLoadEntireState();
  +   public void loadEntireState(ObjectOutputStream os) throws Exception
  +   {
  +      delegateLoadEntireState(os);
  +      
      }
   
  -   public void storeEntireState(byte[] state) throws Exception {
  -      delegateStoreEntireState(state);
  +   public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
  +   {
  +      delegateLoadState(subtree,os);      
      }
   
  -   public void storeState(byte[] state, Fqn fqn) throws Exception
  +   public void storeEntireState(ObjectInputStream is) throws Exception
      {
  -       delegateStoreState(state, fqn);
  +      delegateStoreEntireState(is);
      }
   
  -   public byte[] loadState(Fqn fqn) throws Exception
  +   public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
      {
  -       return delegateLoadState(fqn);
  +      delegateStoreState(subtree,is);
      }
   
      public void create() throws Exception {
  @@ -178,13 +183,13 @@
   
      protected abstract void delegateRemoveData(Fqn name) throws Exception;
   
  -   protected abstract byte[] delegateLoadState(Fqn fqn) throws Exception;
  +   protected abstract void delegateLoadEntireState(ObjectOutputStream os) throws Exception;
   
  -   protected abstract byte[] delegateLoadEntireState() throws Exception;
  +   protected abstract void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception;
   
  -   protected abstract void delegateStoreState(byte[] state, Fqn fqn) throws Exception;
  +   protected abstract void delegateStoreEntireState(ObjectInputStream is)throws Exception;  
   
  -   protected abstract void delegateStoreEntireState(byte[] state) throws Exception;
  +   protected abstract void delegateStoreState(Fqn subtree, ObjectInputStream is)throws Exception;  
   
      protected abstract void delegatePut(List<Modification> modifications) throws Exception;
   }
  
  
  
  1.15      +49 -9     JBossCache/src/org/jboss/cache/loader/AsyncCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AsyncCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AsyncCacheLoader.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- AsyncCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.14
  +++ AsyncCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.15
  @@ -15,6 +15,8 @@
   import org.jboss.cache.marshall.RegionManager;
   
   import java.io.IOException;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -265,16 +267,16 @@
         delegateTo.rollback( tx );
      }
   
  -   public byte[] loadEntireState() throws Exception
  +   /*public byte[] loadEntireState() throws Exception
      {
         return delegateTo.loadEntireState();
  -   }
  +   }*/
   
  -   public void storeState(byte[] state, Fqn subtree) throws Exception
  +   /*public void storeState(byte[] state, Fqn subtree) throws Exception
      {
         Modification mod = new Modification(Modification.STORE_STATE, subtree, null, state);
         enqueue(mod);
  -   }
  +   }*/
   
       public void setRegionManager(RegionManager manager)
       {
  @@ -285,15 +287,37 @@
        * Stores the entire state.
        * This is processed asynchronously.
        */
  -    public void storeEntireState(byte[] state) throws Exception
  +    /*public void storeEntireState(byte[] state) throws Exception
       {
          Modification mod = new Modification(Modification.STORE_STATE, null, null, state);
          enqueue(mod);
  -    }
  +    }*/
   
  -    public byte[] loadState(Fqn subtree) throws Exception
  +    /*public byte[] loadState(Fqn subtree) throws Exception
       {
           return new byte[0];
  +    }*/
  +    
  +    public void loadEntireState(ObjectOutputStream os) throws Exception
  +    {
  +       delegateTo.loadEntireState(os);       
  +    }
  +
  +    public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
  +    {
  +       delegateTo.loadState(subtree,os);           
  +    }
  +    
  +    public void storeEntireState(ObjectInputStream is) throws Exception
  +    {
  +       Modification mod = new Modification(Modification.STORE_STATE, null, null, is);
  +       enqueue(mod);
  +    }
  +
  +    public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
  +    {
  +       Modification mod = new Modification(Modification.STORE_STATE, subtree, null, is);
  +       enqueue(mod);
       }
   
       public void create() throws Exception
  @@ -421,7 +445,8 @@
               if (mod.getType() == Modification.STORE_STATE)
               {
                  log.trace("storeState");
  -               storeState(mod.getFqn(), (byte [])mod.getValue());
  +               ObjectInputStream is = (ObjectInputStream)mod.getValue();               
  +               storeState(mod.getFqn(),is);               
               }
               else
               {
  @@ -430,7 +455,7 @@
            }
         }
   
  -      private void storeState(Fqn fqn, byte b[]) {
  +      /*private void storeState(Fqn fqn, byte b[]) {
            try
            {
               if (fqn == null)
  @@ -443,6 +468,21 @@
               if (log.isWarnEnabled()) log.warn("Failed to store " + e);
               log.debug("Exception: ", e);
            }
  +      }*/
  +      
  +      private void storeState(Fqn fqn, ObjectInputStream is) {
  +         try
  +         {
  +            if (fqn == null)
  +               delegateTo.storeEntireState(is);
  +            else
  +               delegateTo.storeState(fqn,is);
  +         }
  +         catch (Exception e)
  +         {
  +            if (log.isWarnEnabled()) log.warn("Failed to store " + e);
  +            log.debug("Exception: ", e);
  +         }
         }
   
         private void put(List mods) {
  
  
  
  1.9       +25 -21    JBossCache/src/org/jboss/cache/loader/SharedStoreCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SharedStoreCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/SharedStoreCacheLoader.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- SharedStoreCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.8
  +++ SharedStoreCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.9
  @@ -10,6 +10,8 @@
   import org.jgroups.Address;
   import org.jgroups.View;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.List;
   import java.util.Map;
   import java.util.Properties;
  @@ -26,7 +28,7 @@
    * Whenever the current coordinator dies (or leaves), the second in line will take over. That SharedStoreCacheLoader
    * will then pass writes through to its underlying CacheLoader.
    * @author Bela Ban
  - * @version $Id: SharedStoreCacheLoader.java,v 1.8 2006/07/19 08:29:18 msurtani Exp $
  + * @version $Id: SharedStoreCacheLoader.java,v 1.9 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class SharedStoreCacheLoader extends AbstractCacheListener implements CacheLoader
   {
  @@ -126,23 +128,25 @@
            loader.rollback(tx);
      }
   
  -   public byte[] loadEntireState() throws Exception {
  -      return loader.loadEntireState();
  +   public void loadEntireState(ObjectOutputStream os) throws Exception
  +   {
  +      loader.loadEntireState(os);       
      }
   
  -   public void storeEntireState(byte[] state) throws Exception {
  -      if(active)
  -         loader.storeEntireState(state);
  +   public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
  +   {
  +      loader.loadState(subtree,os);       
      }
   
  -    public byte[] loadState(Fqn subtree) throws Exception
  +   public void storeEntireState(ObjectInputStream is) throws Exception
       {
  -        return loader.loadState(subtree);
  +      if(active)
  +         loader.storeEntireState(is);
       }
   
  -    public void storeState(byte[] state, Fqn subtree) throws Exception
  +   public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
       {
  -        if (active) loader.storeState(state, subtree);
  +      if (active) loader.storeState(subtree,is);       
       }
   
       public void setRegionManager(RegionManager manager)
  
  
  
  1.3       +6 -1      JBossCache/src/org/jboss/cache/loader/NodeData.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeData.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/NodeData.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- NodeData.java	8 Oct 2005 00:40:25 -0000	1.2
  +++ NodeData.java	31 Aug 2006 14:56:45 -0000	1.3
  @@ -11,7 +11,7 @@
   /**
    * Serializable representation of the data of a node (FQN and attributes)
    * @author Bela Ban
  - * @version $Id: NodeData.java,v 1.2 2005/10/08 00:40:25 bstansberry Exp $
  + * @version $Id: NodeData.java,v 1.3 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class NodeData implements Externalizable {
      Fqn     fqn=null;
  @@ -44,6 +44,11 @@
         return fqn;
      }
   
  +   public boolean isMarker()
  +   {
  +      return false;
  +   }
  +
      public void writeExternal(ObjectOutput out) throws IOException {
         out.writeObject(fqn);
         if(attrs != null) {
  
  
  
  1.13      +10 -12    JBossCache/src/org/jboss/cache/loader/ClusteredCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClusteredCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/ClusteredCacheLoader.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- ClusteredCacheLoader.java	30 Aug 2006 17:08:18 -0000	1.12
  +++ ClusteredCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.13
  @@ -18,6 +18,8 @@
   import org.jgroups.Address;
   import org.jgroups.blocks.GroupRequest;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  @@ -198,28 +200,24 @@
      {
      }
   
  -   /**
  -    * Returns an empty byte array.
  -    */
  -   public byte[] loadEntireState() throws Exception
  +   public void loadEntireState(ObjectOutputStream os) throws Exception
      {
  -      return new byte[0];
  +      //intentional no-op      
      }
   
  -   /**
  -    * Does nothing.
  -    */
  -   public void storeEntireState(byte[] state) throws Exception
  +   public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
      {
  +      // intentional no-op      
      }
   
  -   public byte[] loadState(Fqn subtree) throws Exception
  +   public void storeEntireState(ObjectInputStream is) throws Exception
      {
  -      return new byte[0];
  +      // intentional no-op      
      }
   
  -   public void storeState(byte[] state, Fqn subtree) throws Exception
  +   public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
      {
  +      // intentional no-op      
      }
   
      public void setRegionManager(RegionManager manager)
  
  
  
  1.9       +50 -64    JBossCache/src/org/jboss/cache/loader/ChainingCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ChainingCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/ChainingCacheLoader.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- ChainingCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.8
  +++ ChainingCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.9
  @@ -11,6 +11,8 @@
   import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.marshall.RegionManager;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.Iterator;
  @@ -276,53 +278,7 @@
           }
       }
   
  -    /**
  -     * Fetch the entire state for this cache from secondary storage (disk, DB) and return it as a byte buffer.
  -     * This is for initialization of a new cache from a remote cache. The new cache would then call
  -     * storeEntireState().<br/>
  -     *
  -     * Only fetches state from the loader with fetchPersistentState as true.
  -     *
  -     * todo: define binary format for exchanging state
  -     */
  -    public byte[] loadEntireState() throws Exception
  -    {
  -        byte[] answer = null;
  -        Iterator<CacheLoader> i = cacheLoaders.iterator();
  -        Iterator<CacheLoaderConfig.IndividualCacheLoaderConfig> cfgs = cacheLoaderConfigs.iterator();
  -        while (i.hasNext() && cfgs.hasNext())
  -        {
  -            CacheLoader l = i.next();
  -            CacheLoaderConfig.IndividualCacheLoaderConfig cfg = cfgs.next();
  -            if (cfg.isFetchPersistentState())
  -            {
  -                answer = l.loadEntireState();
  -                break;
  -            }
  -        }
  -        return answer;
  -    }
   
  -    /**
  -     * Store the given state in secondary storage. Overwrite whatever is currently in secondary storage.
  -     *
  -     * Only stores this state in a loader that has fetchPersistentState as true.
  -     */
  -    public void storeEntireState(byte[] state) throws Exception
  -    {
  -        Iterator<CacheLoader> i = writeCacheLoaders.iterator();
  -        Iterator<CacheLoaderConfig.IndividualCacheLoaderConfig> cfgs = cacheLoaderConfigs.iterator();
  -        while (i.hasNext())
  -        {
  -            CacheLoader l = i.next();
  -            CacheLoaderConfig.IndividualCacheLoaderConfig cfg = cfgs.next();
  -            if (cfg.isFetchPersistentState())
  -            {
  -                l.storeEntireState(state);
  -                break;
  -            }
  -        }
  -    }
   
       /**
        * Creates individual cache loaders.
  @@ -367,9 +323,16 @@
           }
       }
       
  -    public byte[] loadState(Fqn subtree) throws Exception
  +    /**
  +     * No-op, as this class doesn't directly use the RegionManager.
  +     */
  +    public void setRegionManager(RegionManager manager)
  +    {
  +       // no-op -- we don't do anything with the region manager       
  +    }   
  +    
  +    public void loadEntireState(ObjectOutputStream os) throws Exception
       {
  -       byte[] answer = null;
          Iterator<CacheLoader> i = cacheLoaders.iterator();
          Iterator<CacheLoaderConfig.IndividualCacheLoaderConfig> cfgs = cacheLoaderConfigs.iterator();
          while (i.hasNext() && cfgs.hasNext())
  @@ -378,22 +341,29 @@
              CacheLoaderConfig.IndividualCacheLoaderConfig cfg = cfgs.next();
              if (cfg.isFetchPersistentState())
              {
  -              answer = l.loadState(subtree);
  +               l.loadEntireState(os);
                 break;
              }
          }
  -       return answer;
       }
   
  -    /**
  -     * No-op, as this class doesn't directly use the RegionManager.
  -     */
  -    public void setRegionManager(RegionManager manager)
  +    public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
       {
  -       // no-op -- we don't do anything with the region manager       
  +       Iterator<CacheLoader> i = cacheLoaders.iterator();
  +       Iterator<CacheLoaderConfig.IndividualCacheLoaderConfig> cfgs = cacheLoaderConfigs.iterator();
  +       while (i.hasNext() && cfgs.hasNext())
  +       {
  +           CacheLoader l = i.next();
  +           CacheLoaderConfig.IndividualCacheLoaderConfig cfg = cfgs.next();
  +           if (cfg.isFetchPersistentState())
  +           {
  +              l.loadState(subtree,os);
  +              break;
  +           }
  +       }             
       }
   
  -    public void storeState(byte[] state, Fqn subtree) throws Exception
  +    public void storeEntireState(ObjectInputStream is) throws Exception
       {
          Iterator<CacheLoader> i = writeCacheLoaders.iterator();
          Iterator<CacheLoaderConfig.IndividualCacheLoaderConfig> cfgs = cacheLoaderConfigs.iterator();
  @@ -403,12 +373,28 @@
              CacheLoaderConfig.IndividualCacheLoaderConfig cfg = cfgs.next();
              if (cfg.isFetchPersistentState())
              {
  -              l.storeState(state, subtree);
  +               l.storeEntireState(is);
                 break;
              }
          }
  +       
       }
       
  +    public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
  +    {
  +       Iterator<CacheLoader> i = writeCacheLoaders.iterator();
  +       Iterator<CacheLoaderConfig.IndividualCacheLoaderConfig> cfgs = cacheLoaderConfigs.iterator();
  +       while (i.hasNext())
  +       {
  +           CacheLoader l = i.next();
  +           CacheLoaderConfig.IndividualCacheLoaderConfig cfg = cfgs.next();
  +           if (cfg.isFetchPersistentState())
  +           {
  +              l.storeState(subtree,is);
  +              break;
  +           }
  +       }       
  +    }  
       
       /**
        * Returns the number of cache loaders in the chain.
  
  
  
  1.13      +23 -46    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.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- JDBCCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.12
  +++ JDBCCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.13
  @@ -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.12 $</tt>
  + * @version <tt>$Revision: 1.13 $</tt>
    */
   public class JDBCCacheLoader extends AbstractCacheLoader
   {
  @@ -575,41 +575,19 @@
          }
       }
   
  -
  -
  -    /**
  -     * Overrides the {@link FileCacheLoader#loadEntireState() superclass method}
  -     * by taking advantage of any special classloader registered for the
  -     * root node.
  -     */
  -    public byte[] loadEntireState() throws Exception
  -    {
  -       return loadState(Fqn.ROOT);
  -    }
  -
  -    /**
  -     * Overrides the {@link FileCacheLoader#storeEntireState(byte[])}  superclass method}
  -     * by taking advantage of any special classloader registered for the
  -     * root node.
  -     */
  -    public void storeEntireState(byte[] state) throws Exception
  +    public void loadEntireState(ObjectOutputStream os) throws Exception
       {
  -       storeState(state, Fqn.ROOT);
  +       loadStateHelper(Fqn.ROOT,os);       
       }
   
  -    public byte[] loadState(Fqn subtree) throws Exception
  +    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);
  -
  -          ByteArrayOutputStream out_stream=new ByteArrayOutputStream(1024);
  -          ObjectOutputStream    out=new MarshalledValueOutputStream(out_stream);
  -          loadState(subtree, out);
  -          out.close();
  -          return out_stream.toByteArray();
  +          loadStateHelper(subtree, os);                   
          }
          finally
          {
  @@ -617,37 +595,36 @@
          }
       }
   
  -    public void storeState(byte[] state, Fqn subtree) throws Exception
  +    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);
  -
  -          ByteArrayInputStream in_stream=new ByteArrayInputStream(state);
  -          MarshalledValueInputStream in=new MarshalledValueInputStream(in_stream);
             NodeData nd;
   
             // remove entire existing state
             this.remove(subtree);
   
  -          boolean moveToBuddy =
  -             subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
  +          boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
   
             // store new state
             Fqn fqn = null;
  -          while(in.available() > 0)
  -          {
  -             nd=(NodeData)in.readObject();
   
  +          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)
  +             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
  @@ -854,7 +831,7 @@
       * @param out
       * @throws Exception
       */
  -   protected void loadState(Fqn fqn, ObjectOutputStream out) throws Exception {
  +   protected void loadStateHelper(Fqn fqn, ObjectOutputStream out) throws Exception {
         Map       attrs;
         Set       children_names;
         String    child_name;
  @@ -876,7 +853,7 @@
         for(Iterator it=children_names.iterator(); it.hasNext();) {
            child_name=(String)it.next();
            tmp_fqn=new Fqn(fqn, child_name);
  -         loadState(tmp_fqn, out);
  +         loadStateHelper(tmp_fqn, out);
         }
      }
   
  
  
  
  1.10      +29 -26    JBossCache/src/org/jboss/cache/loader/RpcDelegatingCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RpcDelegatingCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/RpcDelegatingCacheLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- RpcDelegatingCacheLoader.java	25 Aug 2006 14:10:08 -0000	1.9
  +++ RpcDelegatingCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.10
  @@ -16,6 +16,8 @@
   import org.jgroups.Address;
   import org.jboss.cache.marshall.MethodCall;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.lang.reflect.Method;
   import java.util.List;
   import java.util.Map;
  @@ -33,7 +35,7 @@
    * specified, it defaults to <tt>5000</tt>.
    * 
    * @author Daniel Gredler
  - * @version $Id: RpcDelegatingCacheLoader.java,v 1.9 2006/08/25 14:10:08 msurtani Exp $
  + * @version $Id: RpcDelegatingCacheLoader.java,v 1.10 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class RpcDelegatingCacheLoader extends DelegatingCacheLoader {
   
  @@ -201,28 +203,30 @@
         this.doMethodCall( METHOD_REMOVE_DATA, new Object[] { name } );
      }
   
  -    protected byte[] delegateLoadState(Fqn fqn) throws Exception
  +   @Override
  +   protected void delegateLoadEntireState(ObjectOutputStream os) throws Exception
       {
  -        throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
  -    }
  +      // TODO
   
  -    /**
  -     * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateLoadEntireState()
  -     */
  -    public byte[] delegateLoadEntireState() throws Exception {
  -       return (byte[]) this.doMethodCall( METHOD_GET_STATE, new Object[0] );
       }
   
  -    protected void delegateStoreState(byte[] state, Fqn fqn) throws Exception
  +   @Override
  +   protected void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception
       {
           throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
       }
   
  -    /**
  -     * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateStoreEntireState(byte[])
  -     */
  -    public void delegateStoreEntireState(byte[] state) throws Exception {
  -       this.doMethodCall( METHOD_SET_STATE, new Object[] { state } );
  +   @Override
  +   protected void delegateStoreEntireState(ObjectInputStream is) throws Exception
  +   {
  +      // TODO
  +      
  +   }
  +
  +   @Override
  +   protected void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception
  +   {
  +      throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
       }
   
      /**
  @@ -269,5 +273,4 @@
         }
         return response;
      }
  -
   }
  
  
  
  1.2       +21 -35    JBossCache/src/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TcpDelegatingCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/TcpDelegatingCacheLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- TcpDelegatingCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.1
  +++ TcpDelegatingCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.2
  @@ -30,7 +30,7 @@
    </pre>
    *
    * @author Bela Ban
  - * @version $Id: TcpDelegatingCacheLoader.java,v 1.1 2006/07/19 08:29:18 msurtani Exp $
  + * @version $Id: TcpDelegatingCacheLoader.java,v 1.2 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class TcpDelegatingCacheLoader extends DelegatingCacheLoader {
      private Socket     sock;
  @@ -218,42 +218,28 @@
            throw (Exception)retval;
      }
   
  -    protected byte[] delegateLoadState(Fqn fqn) throws Exception
  +   @Override
  +   protected void delegateLoadEntireState(ObjectOutputStream os) throws Exception
       {
           throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
       }
   
  -    /**
  -     * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateLoadEntireState()
  -     */
  -    public byte[] delegateLoadEntireState() throws Exception {
  +   @Override
  +   protected void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception
  +   {
          throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
  -//      out.writeInt(DelegatingCacheLoader.delegateLoadEntireState);
  -//      out.flush();
  -//      Object retval=in.readObject();
  -//      if(retval instanceof Exception)
  -//         throw (Exception)retval;
  -//      return (byte[])retval;
       }
   
  -    protected void delegateStoreState(byte[] state, Fqn fqn) throws Exception
  +   @Override
  +   protected void delegateStoreEntireState(ObjectInputStream is) throws Exception
       {
           throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
       }
   
  -    /**
  -     * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateStoreEntireState(byte[])
  -     */
  -    public void delegateStoreEntireState(byte[] state) throws Exception {
  +   @Override
  +   protected void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception
  +   {
          throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
  -//      out.writeInt(DelegatingCacheLoader.delegateStoreEntireState);
  -//      out.writeObject(state);
  -//      out.flush();
  -//      Object retval=in.readObject();
  -//      if(retval instanceof Exception)
  -//         throw (Exception)retval;
       }
   
  -
  -
   }
  
  
  
  1.10      +43 -38    JBossCache/src/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LocalDelegatingCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/LocalDelegatingCacheLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- LocalDelegatingCacheLoader.java	20 Jul 2006 21:58:21 -0000	1.9
  +++ LocalDelegatingCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.10
  @@ -11,6 +11,8 @@
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.Modification;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.*;
   
   /**
  @@ -26,7 +28,7 @@
    * </pre>
    * @author Bela Ban
    * @author Daniel Gredler
  - * @version $Id: LocalDelegatingCacheLoader.java,v 1.9 2006/07/20 21:58:21 bstansberry Exp $
  + * @version $Id: LocalDelegatingCacheLoader.java,v 1.10 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class LocalDelegatingCacheLoader extends DelegatingCacheLoader {
   
  @@ -118,12 +120,8 @@
         delegate.removeData(name);
      }
   
  -    protected byte[] delegateLoadState(Fqn fqn) throws Exception
  +   protected void delegateLoadEntireState(ObjectOutputStream os) throws Exception
       {
  -        throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
  -    }
  -
  -    protected byte[] delegateLoadEntireState() throws Exception {
          try
          {
   //          // We use the lock acquisition timeout rather than the
  @@ -135,7 +133,7 @@
   //             false);
             // Until flush is in place, use the old mechanism
             // where we wait the full state retrieval timeout
  -          return delegate.getStateTransferManager().getState(Fqn.ROOT, delegate.getConfiguration().getInitialStateRetrievalTimeout(), true, false);
  +         delegate.getStateTransferManager().getState(os,Fqn.ROOT, delegate.getConfiguration().getInitialStateRetrievalTimeout(), true, false);
          }
          catch (Exception e)
          {
  @@ -147,13 +145,20 @@
          }
       }
   
  -    protected void delegateStoreState(byte[] state, Fqn fqn) throws Exception
  +   protected void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception
       {
           throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
       }
   
  -    protected void delegateStoreEntireState(byte[] state) throws Exception {
  -       delegate.getStateTransferManager().setState(state, Fqn.ROOT, null);
  +   protected void delegateStoreEntireState(ObjectInputStream is) throws Exception
  +   {
  +      delegate.getStateTransferManager().setState(is, Fqn.ROOT, null);
  +      
  +   }
  +
  +   protected void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception
  +   {
  +      throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
       }
   
   }
  
  
  
  1.7       +24 -20    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.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- CacheLoader.java	19 Jul 2006 08:29:18 -0000	1.6
  +++ CacheLoader.java	31 Aug 2006 14:56:45 -0000	1.7
  @@ -11,6 +11,8 @@
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Modification;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.Properties;
   import java.util.Set;
   import java.util.Map;
  @@ -177,37 +179,39 @@
        */
       void rollback(Object tx);
   
  -
       /**
        * Fetches the entire state for this cache from secondary storage (disk, database)
  -     * and returns it as a byte buffer.  This is for initialization of a new
  +    * and writes it to a provided OutputStream. This is for initialization of a new
        * cache from a remote cache. The new cache would then call
  -     * {@link #storeEntireState}.
  +    *{@link #storeEntireState(ObjectInputStream)}
        *
  -     * @return a byte[] containing the state of the cache loader
  +    * @param os OutputStream to write state
        */
  -    byte[] loadEntireState() throws Exception;
  +    void loadEntireState(ObjectOutputStream os) throws Exception;
   
       /**
  -     * Stores the given state in secondary storage. Overwrites whatever is
  -     * currently in storage.
  +    * Stores the state in secondary storage by reading it from the give InputStream. 
  +    * Overwrites whatever is currently in storage.
  +    *
  +    * @param is InputStream to read state 
        *
  -     * @param state state to store
        */
  -    void storeEntireState(byte[] state) throws Exception;
  +    void storeEntireState(ObjectInputStream is) throws Exception;
   
       /**
       * Fetch a portion of the state for this cache from secondary storage
  -    * (disk, database) and return it as a byte buffer.
  +    * (disk, database) and write it to a provided OutputStream.
       * This is for activation of a portion of new cache from a remote cache.
  -    * The new cache would then call {@link #storeState(byte[], Fqn)}.
  +    * The new cache would then call {@link #storeState(Fqn, ObjectInputStream)}.
       *
       * @param subtree Fqn naming the root (i.e. highest level parent) node of
       *                the subtree for which state is requested.
       *
  +    * @param os OutputStream to write state               
  +    *
       * @see org.jboss.cache.Region#activate() 
       */
  -    byte[] loadState(Fqn subtree) throws Exception;
  +    void loadState(Fqn subtree,ObjectOutputStream os) throws Exception;
   
       /**
       * Store the given portion of the cache tree's state in secondary storage.
  @@ -225,7 +229,7 @@
       * "/_BUDDY_BACKUP_/192.168.1.2:5555/a"
       * </p>
       *
  -    * @param state   the state to store
  +    * @param is InputStream 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
       *                of the data included in <code>state</code> are not
  @@ -233,7 +237,7 @@
       *                Fqns should be altered to make them children of
       *                <code>subtree</code> before they are persisted.
       */
  -    void storeState(byte[] state, Fqn subtree) throws Exception;
  +    void storeState(Fqn subtree,ObjectInputStream is) throws Exception;
   
       /**
       * Sets the {@link org.jboss.cache.marshall.RegionManager} this object should use to manage
  
  
  
  1.17      +27 -46    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.16
  retrieving revision 1.17
  diff -u -b -r1.16 -r1.17
  --- FileCacheLoader.java	19 Jul 2006 08:29:18 -0000	1.16
  +++ FileCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.17
  @@ -15,6 +15,7 @@
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -27,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.16 2006/07/19 08:29:18 msurtani Exp $
  + * @version $Id: FileCacheLoader.java,v 1.17 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class FileCacheLoader extends AbstractCacheLoader
   {
  @@ -217,17 +218,12 @@
         transactions.remove(tx);
      }
   
  -   /**
  -    * Loads the entire state from the filesystem and returns it as a byte buffer. The format of the byte buffer
  -    * must be a list of NodeData elements
  -    * @return
  -    * @throws Exception
  -    */
  -   public byte[] loadEntireState() throws Exception {
  -      return loadState(Fqn.ROOT);
  +   public void loadEntireState(ObjectOutputStream os) throws Exception
  +   {
  +      loadState(Fqn.ROOT,os);      
      }
   
  -   public byte[] loadState(Fqn subtree) throws Exception 
  +   public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
      {
         ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
      
  @@ -235,63 +231,48 @@
         {
            // Set the TCCL to any classloader registered for subtree
            setUnmarshallingClassLoader(subtree);
  -         
  -         ByteArrayOutputStream out_stream=new ByteArrayOutputStream(1024);
  -         ObjectOutputStream    out=new MarshalledValueOutputStream(out_stream);
  -         loadStateFromFilessystem(subtree, out);
  -         out.close();
  -         
  -         return out_stream.toByteArray();
  +         loadStateFromFilessystem(subtree, os);                          
         }
         finally
         {
            Thread.currentThread().setContextClassLoader(currentCL);
         }
  +      
      }
   
  -   /** 
  -    * Stores the state given as a byte buffer to the filesystem. The byte
  -    * buffer contains a list of zero or more NodeData elements
  -    * @param state
  -    * @throws Exception
  -    */
  -   public void storeEntireState(byte[] state) throws Exception {
  -      storeState(state, Fqn.ROOT);
  +   public void storeEntireState(ObjectInputStream is) throws Exception
  +   {
  +      storeState(Fqn.ROOT,is);      
      }
   
  -   public void storeState(byte[] state, Fqn subtree) throws Exception 
  +   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);
  -         
  -         ByteArrayInputStream in_stream=new ByteArrayInputStream(state);
  -         MarshalledValueInputStream in=new MarshalledValueInputStream(in_stream);
            NodeData nd;
      
            // remove entire existing state
            this.remove(subtree);
            
  -         boolean moveToBuddy = 
  -            subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
  +         boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && subtree.size() > 1;
      
            // store new state
  -         Fqn fqn;
  -         while (in_stream.available() > 0) 
  -         {
  -            nd=(NodeData)in.readObject();
  +         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)
  +            if (nd.attrs != null)
                  this.put(fqn, nd.attrs, true); // creates a node with 0 or more attributes
               else
  -               this.put(fqn);  // creates a node with null attributes
  +               this.put(fqn, null); // creates a node with null attributes                          
            }
         }
         finally
  
  
  
  1.10      +26 -23    JBossCache/src/org/jboss/cache/loader/RmiDelegatingCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RmiDelegatingCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/RmiDelegatingCacheLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- RmiDelegatingCacheLoader.java	19 Jul 2006 21:34:44 -0000	1.9
  +++ RmiDelegatingCacheLoader.java	31 Aug 2006 14:56:45 -0000	1.10
  @@ -13,6 +13,8 @@
   import org.jboss.cache.Modification;
   import org.jboss.cache.loader.rmi.RemoteTreeCache;
   
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.rmi.Naming;
   import java.util.List;
   import java.util.Map;
  @@ -33,7 +35,7 @@
    * cacheloader's cache's cluster name.
    * 
    * @author Daniel Gredler
  - * @version $Id: RmiDelegatingCacheLoader.java,v 1.9 2006/07/19 21:34:44 msurtani Exp $
  + * @version $Id: RmiDelegatingCacheLoader.java,v 1.10 2006/08/31 14:56:45 vblagojevic Exp $
    */
   public class RmiDelegatingCacheLoader extends DelegatingCacheLoader {
   
  @@ -166,27 +168,29 @@
         if( this.remoteCache != null ) this.remoteCache.removeData(name);
      }
   
  -    protected byte[] delegateLoadState(Fqn fqn) throws Exception
  +   @Override
  +   protected void delegateLoadEntireState(ObjectOutputStream os) throws Exception
       {
           throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
       }
   
  -    /**
  -     * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateLoadEntireState()
  -     */
  -    public byte[] delegateLoadEntireState() throws Exception {
  -        throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");   }
  +   @Override
  +   protected void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception
  +   {
  +      throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
  +   }
   
  -    protected void delegateStoreState(byte[] state, Fqn fqn) throws Exception
  +   @Override
  +   protected void delegateStoreEntireState(ObjectInputStream is) throws Exception
       {
           throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
       }
   
  -    /**
  -     * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateStoreEntireState(byte[])
  -     */
  -    public void delegateStoreEntireState(byte[] state) throws Exception {
  -        throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");   }
  +   @Override
  +   protected void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception
  +   {
  +      throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
  +   }
   
      /**
       * Tries to initialize the remote cache object. If this cacheloader has been
  @@ -212,5 +216,4 @@
            log.error("Unable to lookup remote cache at '" + name + "'.", t);
         }
      }
  -
   }
  
  
  
  1.1      date: 2006/08/31 14:56:45;  author: vblagojevic;  state: Exp;JBossCache/src/org/jboss/cache/loader/NodeDataMarker.java
  
  Index: NodeDataMarker.java
  ===================================================================
  package org.jboss.cache.loader;
  
  public class NodeDataMarker extends NodeData
  {
     public NodeDataMarker()
     {
        super();      
     }
  
     public boolean isMarker()
     {
        return true;
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list