[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/impl ...

Ben Wang bwang at jboss.com
Tue Sep 5 02:11:25 EDT 2006


  User: bwang   
  Date: 06/09/05 02:11:25

  Modified:    src-50/org/jboss/cache/pojo/impl       
                        AdvisedPojoHandler.java CollectionClassHandler.java
                        InternalHelper.java ObjectGraphHandler.java
                        PojoCacheDelegate.java PojoCacheImpl.java
                        SerializableObjectHandler.java
  Log:
  First cuto of the using 2.0 Cache API
  
  Revision  Changes    Path
  1.10      +11 -6     JBossCache/src-50/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AdvisedPojoHandler.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- AdvisedPojoHandler.java	31 Jul 2006 02:44:42 -0000	1.9
  +++ AdvisedPojoHandler.java	5 Sep 2006 06:11:25 -0000	1.10
  @@ -9,7 +9,6 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.CachedType;
   import org.jboss.cache.pojo.PojoInstance;
   import org.jboss.cache.pojo.PojoUtil;
  @@ -19,6 +18,8 @@
   import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.CacheException;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.config.Option;
   import org.jboss.aop.InstanceAdvisor;
   import org.jboss.aop.Advised;
   import org.jboss.aop.ClassInstanceAdvisor;
  @@ -36,12 +37,12 @@
    *
    * @author Ben Wang
    *         Date: Aug 4, 2005
  - * @version $Id: AdvisedPojoHandler.java,v 1.9 2006/07/31 02:44:42 bwang Exp $
  + * @version $Id: AdvisedPojoHandler.java,v 1.10 2006/09/05 06:11:25 bwang Exp $
    */
   class AdvisedPojoHandler
   {
      private final Log log = LogFactory.getLog(AdvisedPojoHandler.class);
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private PojoCacheImpl pCache_;
      private InternalHelper internal_;
      private PojoUtil util_;
  @@ -51,7 +52,7 @@
                                PojoUtil util, Observer observer)
      {
         pCache_ = pCache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         internal_ = internal;
         util_ = util;
         observer_ = observer;
  @@ -90,6 +91,7 @@
            advisor = new ClassInstanceAdvisor(obj);
            ((Advised) obj)._setInstanceAdvisor(advisor);
         }
  +
         // Let's do batch update via Map instead
         Map map = new HashMap();
         // Always initialize the ref count so we can mark this as an AopNode.
  @@ -147,7 +149,10 @@
         }
   
         // Use option to skip locking since we have parent lock already.
  -      cache_.put(fqn, map, internal_.getLockOption());
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
  +
  +      cache_.getRoot().addChild(fqn).put(map);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
         // This is in-memory operation only
         InternalHelper.setPojo(pojoInstance, obj);
   
  @@ -199,7 +204,7 @@
         }
   
         // batch remove
  -      cache_.removeData(fqn);
  +      cache_.getRoot().getChild(fqn).clearData();
         // Determine if we want to keep the interceptor for later use.
         CacheFieldInterceptor interceptor = (CacheFieldInterceptor) AopUtil.findCacheInterceptor(advisor);
         // Remember to remove the interceptor from in-memory object but make sure it belongs to me first.
  
  
  
  1.8       +4 -3      JBossCache/src-50/org/jboss/cache/pojo/impl/CollectionClassHandler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CollectionClassHandler.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/CollectionClassHandler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- CollectionClassHandler.java	26 Jul 2006 17:02:13 -0000	1.7
  +++ CollectionClassHandler.java	5 Sep 2006 06:11:25 -0000	1.8
  @@ -13,6 +13,7 @@
   import org.jboss.aop.proxy.ClassProxy;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
   import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
   import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
  @@ -30,19 +31,19 @@
    *
    * @author Ben Wang
    *         Date: Aug 4, 2005
  - * @version $Id: CollectionClassHandler.java,v 1.7 2006/07/26 17:02:13 bwang Exp $
  + * @version $Id: CollectionClassHandler.java,v 1.8 2006/09/05 06:11:25 bwang Exp $
    */
   class CollectionClassHandler
   {
      private final Log log = LogFactory.getLog(CollectionClassHandler.class);
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private PojoCacheImpl pCache_;
      private InternalHelper internal_;
   
      public CollectionClassHandler(PojoCacheImpl pCache, InternalHelper internal)
      {
         pCache_ = pCache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         internal_ = internal;
      }
   
  
  
  
  1.6       +26 -53    JBossCache/src-50/org/jboss/cache/pojo/impl/InternalHelper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InternalHelper.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/InternalHelper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- InternalHelper.java	17 Jul 2006 09:07:08 -0000	1.5
  +++ InternalHelper.java	5 Sep 2006 06:11:25 -0000	1.6
  @@ -9,11 +9,10 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.CacheException;
  -import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.config.Option;
   import org.jboss.cache.pojo.util.ObjectUtil;
  -import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.PojoInstance;
   import org.jboss.cache.pojo.InternalConstant;
   import org.jboss.cache.pojo.PojoReference;
  @@ -37,9 +36,9 @@
      private Option gravitateOption_;
      private Option localModeOption_;
   
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
   
  -   InternalHelper(PojoTreeCache cache)
  +   InternalHelper(CacheSPI cache)
      {
         cache_ = cache;
   
  @@ -129,28 +128,39 @@
         // TODO let's find a better way to decouple this.
         if (gravitate && cache_.getBuddyManager() != null)
         {
  -         return cache_.get(fqn, key, gravitateOption_);
  +         cache_.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
  +         Object obj = cache_.get(fqn, key);
  +         cache_.getInvocationContext().getOptionOverrides().setForceDataGravitation(false);
  +         return obj;
         } else if (cache_.getCacheLoader() != null)
         {
            // We have cache loader, we can't get it directly from the local get.
  -         return cache_.get(fqn, key, skipLockOption_);
  +         cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
  +         Object obj = cache_.get(fqn, key);
  +         cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
  +         return obj;
         } else
         {
  -         return cache_._get(fqn, key, false);
  +//         return cache_._get(fqn, key, false);
  +         return cache_.get(fqn, key);
         }
      }
   
      private void put(Fqn fqn, Object key, Object value) throws CacheException
      {
         // Use option to ski locking since we have parent lock already.
  -      cache_.put(fqn, key, value, skipLockOption_);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
  +      cache_.put(fqn, key, value);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
   //      cache_.put(fqn, key, value);
      }
   
      void put(Fqn fqn, Map map) throws CacheException
      {
         // Use option to ski locking since we have parent lock already.
  -      cache_.put(fqn, map, skipLockOption_);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
  +      cache_.put(fqn, map);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
   //      cache_.put(fqn, key, value);
      }
   
  @@ -158,7 +168,9 @@
      {
         // Use option to ski locking since we have parent lock already.
         // TODO Need to make sure there is no tx here otherwise it won't work.
  -      cache_.put(fqn, key, value, localModeOption_);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
  +      cache_.put(fqn, key, value);
  +//      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(false);
      }
   
   
  @@ -336,14 +348,14 @@
      void cleanUp(Fqn fqn) throws CacheException
      {
         // We can't do a brute force remove anymore?
  -      if (!cache_._get(fqn).hasChildren())
  +      if (cache_.getRoot().getChild(fqn).getChildren() != null)
         {
            // remove everything
  -         cache_.remove(fqn);
  +         cache_.removeNode(fqn);
         } else
         {
            // Assume everything here is all PojoCache data for optimization
  -         cache_.removeData(fqn);
  +         cache_.getRoot().getChild(fqn).clearData();
            if (log.isTraceEnabled())
            {
               log.trace("cleanup(): fqn: " + fqn + " is not empty. That means it has sub-pojos. Will not remove node");
  @@ -385,11 +397,8 @@
      {
         String indirectFqn = getIndirectFqn(oldFqn);
         Fqn tmpFqn = getInternalFqn(oldFqn);
  -      if (cache_.exists(tmpFqn, indirectFqn)) // No need to update if it doesn't exist.
  -      {
            put(tmpFqn, indirectFqn, newFqn);
         }
  -   }
   
      void updateIndirectFqn(Fqn originalFqn, Fqn newFqn) throws CacheException
      {
  @@ -407,42 +416,6 @@
         return ai.getAndRemoveFirstFqnInList();
      }
   
  -   void relocate(Fqn thisFqn, Fqn newFqn) throws CacheException
  -   {
  -      /**
  -       DataNode node = cache_.get(thisFqn);
  -       DataNode newParent = (DataNode)cache_.get(newFqn).getParent();
  -       node.relocate(newParent, newFqn); // relocation
  -       updateIndirectFqn(thisFqn, newFqn);
  -       */
  -
  -      // Let's do cache-wide copy then. It won't be fast and atomic but
  -      // at least it preserves the pojo structure and also do replication
  -      // TODO Can TreeCache provide a method to do this??
  -
  -      // First do a recursive copy using the new base fqn
  -      DataNode node = cache_.get(thisFqn);
  -      Map value = node.getData();
  -      cache_.put(newFqn, value);
  -
  -      Map children = node.getChildren();
  -      if (children == null || children.size() == 0)
  -      {
  -         cache_.remove(thisFqn);
  -         return; // we are done
  -      }
  -
  -      for (Object key : children.keySet())
  -      {
  -         Fqn thisChildFqn = new Fqn(thisFqn, key);
  -         Fqn newChildFqn = new Fqn(newFqn, key);
  -         relocate(thisChildFqn, newChildFqn);
  -      }
  -
  -      // Finally do a remove
  -      cache_.remove(thisFqn);
  -   }
  -
      /**
       * Test if this internal node.
       *
  
  
  
  1.7       +4 -3      JBossCache/src-50/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ObjectGraphHandler.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/ObjectGraphHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- ObjectGraphHandler.java	27 Jul 2006 14:25:26 -0000	1.6
  +++ ObjectGraphHandler.java	5 Sep 2006 06:11:25 -0000	1.7
  @@ -15,6 +15,7 @@
   import org.jboss.aop.advice.Interceptor;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.pojo.util.AopUtil;
   import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
   import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
  @@ -30,11 +31,11 @@
    *
    * @author Ben Wang
    *         Date: Aug 4, 2005
  - * @version $Id: ObjectGraphHandler.java,v 1.6 2006/07/27 14:25:26 bwang Exp $
  + * @version $Id: ObjectGraphHandler.java,v 1.7 2006/09/05 06:11:25 bwang Exp $
    */
   class ObjectGraphHandler
   {
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private PojoCacheImpl pCache_;
      private InternalHelper internal_;
      private final static Log log = LogFactory.getLog(ObjectGraphHandler.class);
  @@ -42,7 +43,7 @@
      public ObjectGraphHandler(PojoCacheImpl cache, InternalHelper internal)
      {
         pCache_ = cache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         internal_ = internal;
      }
   
  
  
  
  1.13      +11 -10    JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoCacheDelegate.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheDelegate.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- PojoCacheDelegate.java	31 Jul 2006 02:44:42 -0000	1.12
  +++ PojoCacheDelegate.java	5 Sep 2006 06:11:25 -0000	1.13
  @@ -15,12 +15,13 @@
   import org.jboss.aop.proxy.ClassProxy;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Node;
   import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
   import org.jboss.cache.pojo.memory.FieldPersistentReference;
   import org.jboss.cache.pojo.util.AopUtil;
   import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
   import org.jboss.cache.pojo.observable.Observer;
  -import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.PojoUtil;
   import org.jboss.cache.pojo.CachedType;
   import org.jboss.cache.pojo.PojoInstance;
  @@ -43,7 +44,7 @@
   public class PojoCacheDelegate
   {
      private PojoCacheImpl pCache_;
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private final static Log log = LogFactory.getLog(PojoCacheDelegate.class);
      private InternalHelper internal_;
      private AdvisedPojoHandler advisedHandler_;
  @@ -60,7 +61,7 @@
      public PojoCacheDelegate(PojoCacheImpl cache, Observer observer)
      {
         pCache_ = cache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         internal_ = new InternalHelper(cache_);
         graphHandler_ = new ObjectGraphHandler(pCache_, internal_);
         collectionHandler_ = new CollectionClassHandler(pCache_, internal_);
  @@ -160,7 +161,6 @@
            + internalFqn);
         }
   
  -
         if( (obj instanceof Advised || obj instanceof ClassProxy) && isMultipleReferencedPut(obj))
         {
            // we pass in the originating fqn intentionaly
  @@ -556,13 +556,14 @@
      private void findChildObjects(Fqn fqn, Map map) throws CacheException
      {
         // We need to traverse then
  -      Set set = cache_.getChildrenNames(fqn);
  -      if (set == null) return; // We stop here.
  -      for (Object aSet : set)
  -      {
  -         String obj = (String) aSet;
  -         Fqn newFqn = new Fqn(fqn, obj);
  +      Node root = cache_.getRoot();
  +      Node current = root.getChild(fqn);
   
  +      Collection<Node> col = current.getChildren();
  +      if(col == null) return;
  +      for(Node n : col)
  +      {
  +         Fqn newFqn = n.getFqn();
            if(InternalHelper.isInternalNode(newFqn)) continue; // skip
   
            Object pojo = getObject(newFqn);
  
  
  
  1.19      +16 -12    JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoCacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- PojoCacheImpl.java	21 Aug 2006 16:58:44 -0000	1.18
  +++ PojoCacheImpl.java	5 Sep 2006 06:11:25 -0000	1.19
  @@ -12,15 +12,16 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.TreeCache;
   import org.jboss.cache.Version;
  -//import org.jboss.cache.PropertyConfigurator;
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.config.Configuration;
   import org.jboss.cache.factories.XmlConfigurationParser;
  +import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.pojo.CachedType;
   import org.jboss.cache.pojo.PojoCache;
   import org.jboss.cache.pojo.PojoCacheException;
   import org.jboss.cache.pojo.PojoCacheListener;
  -import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.util.AopUtil;
   import org.jboss.cache.pojo.annotation.Attach;
   import org.jboss.cache.pojo.annotation.Detach;
  @@ -42,11 +43,11 @@
    * Implementation class for PojoCache interface
    *
    * @author Ben Wang
  - * @version $Id: PojoCacheImpl.java,v 1.18 2006/08/21 16:58:44 bwang Exp $
  + * @version $Id: PojoCacheImpl.java,v 1.19 2006/09/05 06:11:25 bwang Exp $
    */
   public class PojoCacheImpl implements PojoCache, Observer
   {
  -   private PojoTreeCache cache_ = null;
  +   private CacheSPI cache_ = null;
      protected final Log log = LogFactory.getLog(PojoCacheImpl.this.getClass());
      private PojoCacheDelegate delegate_;
      // Class -> CachedType
  @@ -68,11 +69,14 @@
      {
         try
         {
  -         cache_ = new PojoTreeCache();
  -//         PropertyConfigurator config = new PropertyConfigurator();
  -//         config.configure(cache_, configStr);
  +//         cache_ = new PojoTreeCache();
  +//         cache_.setConfiguration(new XmlConfigurationParser().parseFile(configStr));
   
  -         cache_.setConfiguration(new XmlConfigurationParser().parseFile(configStr));
  +         XmlConfigurationParser parser = new XmlConfigurationParser();
  +         Configuration expected = parser.parseFile( configStr );
  +
  +         DefaultCacheFactory factory = new DefaultCacheFactory();
  +         cache_ = (CacheSPI)factory.createCache(expected);
         } catch (Exception e)
         {
            e.printStackTrace();
  @@ -86,7 +90,7 @@
         delegate_ = new PojoCacheDelegate(this, this);
      }
   
  -   public PojoTreeCache getUnderlyingCache() { return cache_; }
  +   public CacheSPI getUnderlyingCache() { return cache_; }
   
      public Object attach(String id, Object pojo) throws PojoCacheException
      {
  @@ -256,10 +260,10 @@
         }
      }
   
  -   public TreeCache getCache()
  +   public Cache getCache()
      {
         // TODO Need to return the real Cache interface later on.
  -      return cache_;
  +      return (Cache)cache_;
      }
   
      /**
  
  
  
  1.7       +4 -3      JBossCache/src-50/org/jboss/cache/pojo/impl/SerializableObjectHandler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SerializableObjectHandler.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/SerializableObjectHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- SerializableObjectHandler.java	17 Jul 2006 09:07:08 -0000	1.6
  +++ SerializableObjectHandler.java	5 Sep 2006 06:11:25 -0000	1.7
  @@ -11,6 +11,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.Fqn;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.pojo.PojoTreeCache;
   import org.jboss.cache.pojo.PojoInstance;
   import org.jboss.cache.pojo.InternalConstant;
  @@ -22,11 +23,11 @@
    * Handle Serializable object cache management.
    *
    * @author Ben Wang
  - * @version $Id: SerializableObjectHandler.java,v 1.6 2006/07/17 09:07:08 bwang Exp $
  + * @version $Id: SerializableObjectHandler.java,v 1.7 2006/09/05 06:11:25 bwang Exp $
    */
   class SerializableObjectHandler
   {
  -   private PojoTreeCache cache_;
  +   private CacheSPI cache_;
      private PojoCacheImpl pCache_;
      private InternalHelper internal_;
      private final Log log_ = LogFactory.getLog(SerializableObjectHandler.class);
  @@ -34,7 +35,7 @@
      public SerializableObjectHandler(PojoCacheImpl cache, InternalHelper internal)
      {
         pCache_ = cache;
  -      cache_ = (PojoTreeCache)pCache_.getCache();
  +      cache_ = (CacheSPI)pCache_.getCache();
         internal_ = internal;
      }
   
  
  
  



More information about the jboss-cvs-commits mailing list