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

Jason Thomas Greene jgreene at jboss.com
Wed Jun 27 20:56:06 EDT 2007


  User: jgreene 
  Date: 07/06/27 20:56:06

  Modified:    src/org/jboss/cache/pojo/impl      
                        CollectionClassHandler.java InternalHelper.java
                        ObjectGraphHandler.java PojoCacheDelegate.java
                        PojoCacheImpl.java SerializableObjectHandler.java
  Log:
  Reduce dependency on CacheSPI
  
  Revision  Changes    Path
  1.4       +4 -3      JBossCache/src/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/org/jboss/cache/pojo/impl/CollectionClassHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- CollectionClassHandler.java	30 May 2007 06:08:01 -0000	1.3
  +++ CollectionClassHandler.java	28 Jun 2007 00:56:06 -0000	1.4
  @@ -11,6 +11,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.aop.advice.Interceptor;
   import org.jboss.aop.proxy.ClassProxy;
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  @@ -29,19 +30,19 @@
    *
    * @author Ben Wang
    *         Date: Aug 4, 2005
  - * @version $Id: CollectionClassHandler.java,v 1.3 2007/05/30 06:08:01 jgreene Exp $
  + * @version $Id: CollectionClassHandler.java,v 1.4 2007/06/28 00:56:06 jgreene Exp $
    */
   class CollectionClassHandler
   {
      private final Log log = LogFactory.getLog(CollectionClassHandler.class);
  -   private CacheSPI cache_;
  +   private Cache<Object, Object> cache_;
      private PojoCacheImpl pCache_;
      private InternalHelper internal_;
   
      public CollectionClassHandler(PojoCacheImpl pCache, InternalHelper internal)
      {
         pCache_ = pCache;
  -      cache_ = (CacheSPI) pCache_.getCache();
  +      cache_ = pCache_.getCache();
         internal_ = internal;
      }
   
  
  
  
  1.7       +7 -8      JBossCache/src/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/org/jboss/cache/pojo/impl/InternalHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- InternalHelper.java	22 Jun 2007 23:01:08 -0000	1.6
  +++ InternalHelper.java	28 Jun 2007 00:56:06 -0000	1.7
  @@ -6,17 +6,16 @@
    */
   package org.jboss.cache.pojo.impl;
   
  +import java.util.Map;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
  -import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.config.Option;
   import org.jboss.cache.pojo.PojoCacheException;
   import org.jboss.cache.pojo.util.ObjectUtil;
   
  -import java.util.Map;
  -
   /**
    * Internal helper class to handle internal cache sotre, that is, the portion that is not part of
    * user's data.
  @@ -27,9 +26,9 @@
   {
      private static  Log log = LogFactory.getLog(InternalHelper.class.getName());
   
  -   private CacheSPI cache;
  +   private Cache cache;
   
  -   InternalHelper(CacheSPI cache)
  +   InternalHelper(Cache cache)
      {
         this.cache = cache;
      }
  @@ -87,14 +86,14 @@
   
      private Object get(Fqn fqn, Object key, boolean gravitate) throws CacheException
      {
  -      // TODO let's find a better way to decouple this.
  -      if (gravitate && cache.getBuddyManager() != null)
  +      if (gravitate)
         {
            cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
            Object obj = cache.get(fqn, key);
            cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(false);
            return obj;
         }
  +
         return cache.get(fqn, key);
      }
   
  
  
  
  1.7       +7 -8      JBossCache/src/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/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	22 Jun 2007 23:01:08 -0000	1.6
  +++ ObjectGraphHandler.java	28 Jun 2007 00:56:06 -0000	1.7
  @@ -13,6 +13,7 @@
   import org.jboss.aop.InstanceAdvisor;
   import org.jboss.aop.advice.Interceptor;
   import org.jboss.aop.proxy.ClassProxy;
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  @@ -26,19 +27,17 @@
    *
    * @author Ben Wang
    *         Date: Aug 4, 2005
  - * @version $Id: ObjectGraphHandler.java,v 1.6 2007/06/22 23:01:08 jgreene Exp $
  + * @version $Id: ObjectGraphHandler.java,v 1.7 2007/06/28 00:56:06 jgreene Exp $
    */
   class ObjectGraphHandler
   {
  -   private CacheSPI cache_;
  -   private PojoCacheImpl pCache_;
  +   private PojoCacheImpl cache;
      private InternalHelper internal_;
      private final static Log log = LogFactory.getLog(ObjectGraphHandler.class);
   
      public ObjectGraphHandler(PojoCacheImpl cache, InternalHelper internal)
      {
  -      pCache_ = cache;
  -      cache_ = (CacheSPI) pCache_.getCache();
  +      this.cache = cache;
         internal_ = internal;
      }
   
  @@ -47,7 +46,7 @@
         // Note this is actually the aliasFqn, not the real fqn!
         Object obj;
   
  -      obj = pCache_.getObject(fqn);
  +      obj = cache.getObject(fqn);
         if (obj == null)
            throw new PojoCacheException("ObjectGraphHandler.get(): null object from internal ref node." +
                                         " Internal ref node: " + fqn);
  @@ -57,7 +56,7 @@
   
      void put(Fqn fqn, Object obj, String field) throws CacheException
      {
  -      CachedType type = pCache_.getCachedType(obj.getClass());
  +      CachedType type = cache.getCachedType(obj.getClass());
   
         InstanceAdvisor advisor = null;
         Interceptor interceptor = null;
  @@ -132,7 +131,7 @@
            {
               // No one is referring it so it is safe to remove
               // TODO we should make sure the parent nodes are also removed they are empty as well.
  -            pCache_.detach(referencingFqn);
  +            cache.detach(referencingFqn);
            }
         }
      }
  
  
  
  1.10      +29 -27    JBossCache/src/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/org/jboss/cache/pojo/impl/PojoCacheDelegate.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- PojoCacheDelegate.java	22 Jun 2007 23:01:08 -0000	1.9
  +++ PojoCacheDelegate.java	28 Jun 2007 00:56:06 -0000	1.10
  @@ -13,10 +13,12 @@
   import org.jboss.aop.InstanceAdvisor;
   import org.jboss.aop.advice.Interceptor;
   import org.jboss.aop.proxy.ClassProxy;
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  +import org.jboss.cache.Region;
   import org.jboss.cache.pojo.PojoCacheException;
   import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
   import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
  @@ -39,8 +41,8 @@
    */
   public class PojoCacheDelegate
   {
  -   private PojoCacheImpl pCache_;
  -   private CacheSPI cache_;
  +   private PojoCacheImpl pojoCache;
  +   private Cache<Object, Object> cache;
      private final static Log log = LogFactory.getLog(PojoCacheDelegate.class);
      private InternalHelper internal_;
      private AdvisedPojoHandler advisedHandler_;
  @@ -54,13 +56,13 @@
   
      public PojoCacheDelegate(PojoCacheImpl cache)
      {
  -      pCache_ = cache;
  -      cache_ = (CacheSPI) pCache_.getCache();
  -      internal_ = new InternalHelper(cache_);
  -      graphHandler_ = new ObjectGraphHandler(pCache_, internal_);
  -      collectionHandler_ = new CollectionClassHandler(pCache_, internal_);
  -      serializableHandler_ = new SerializableObjectHandler(pCache_, internal_);
  -      advisedHandler_ = new AdvisedPojoHandler(pCache_, internal_, util_);
  +      pojoCache = cache;
  +      this.cache = pojoCache.getCache();
  +      internal_ = new InternalHelper(this.cache);
  +      graphHandler_ = new ObjectGraphHandler(pojoCache, internal_);
  +      collectionHandler_ = new CollectionClassHandler(pojoCache, internal_);
  +      serializableHandler_ = new SerializableObjectHandler(pojoCache, internal_);
  +      advisedHandler_ = new AdvisedPojoHandler(pojoCache, internal_, util_);
      }
   
      public void setBulkRemove(boolean bulk)
  @@ -93,10 +95,10 @@
         ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
         try
         {
  -         if (cache_.getRegionManager() != null)
  -         {
  -            cache_.getRegionManager().setContextClassLoaderAsCurrent(fqn);
  -         }
  +         Region region = cache.getRegion(fqn, false);
  +         if (region != null)
  +            Thread.currentThread().setContextClassLoader(region.getClassLoader());
  +
            return getObjectInternal(fqn, field);
         }
         finally
  @@ -138,7 +140,7 @@
   
         // remove old value before overwriting it. This is necessary to detach any interceptor.
         // TODO Or can we simply walk thru that somewhere? Well, there is also implication of Collection though
  -      pCache_.detach(fqn, field);
  +      pojoCache.detach(fqn, field);
   
         if (obj == null)
         {
  @@ -179,7 +181,7 @@
            }
            
            // Used by notification sub-system
  -         cache_.put(internalFqn, InternalConstant.POJOCACHE_STATUS, "ATTACHED");
  +         cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS, "ATTACHED");
   
            setPojoReference(fqn, obj, field, internalFqn);
         }
  @@ -190,13 +192,13 @@
      Fqn createInternalFqn(Fqn fqn, Object obj) throws CacheException
      {
         // Create an internal Fqn name
  -      return AopUtil.createInternalFqn(fqn, cache_);
  +      return AopUtil.createInternalFqn(fqn, cache);
      }
   
      Fqn setPojoReference(Fqn fqn, Object obj, String field, Fqn internalFqn) throws CacheException
      {
         // Create PojoReference
  -      CachedType type = pCache_.getCachedType(obj.getClass());
  +      CachedType type = pojoCache.getCachedType(obj.getClass());
         PojoReference pojoReference = new PojoReference();
         pojoReference.setPojoClass(type.getType());
   
  @@ -217,7 +219,7 @@
         Fqn f = internalFqn.getSubFqn(0, size - 1);
         Fqn child = internalFqn.getSubFqn(size - 1, size);
   
  -      Node base = cache_.getRoot().getChild(f);
  +      Node base = cache.getRoot().getChild(f);
         if (base == null)
         {
            log.debug("The node retrieved is null from fqn: " + f);
  @@ -256,7 +258,7 @@
                      + " with the corresponding internal id: " + internalFqn);
         }
   
  -      Object result = pCache_.getObject(internalFqn);
  +      Object result = pojoCache.getObject(internalFqn);
         if (result == null)
         {
            return null;
  @@ -268,7 +270,7 @@
         }
         else
         {
  -         cache_.put(internalFqn, InternalConstant.POJOCACHE_STATUS, "DETACHING");
  +         cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS, "DETACHING");
            if (Advised.class.isAssignableFrom(clazz))
            {
               advisedHandler_.remove(internalFqn, result, clazz);
  @@ -423,7 +425,7 @@
         }
         else
         {
  -         cache_.removeNode(fqn);// interceptor has been removed so it is safe to do bulk remove now.
  +         cache.removeNode(fqn);// interceptor has been removed so it is safe to do bulk remove now.
         }
         return true;
      }
  @@ -483,7 +485,7 @@
         // store object in cache
         if (obj instanceof Advised)
         {
  -         CachedType type = pCache_.getCachedType(obj.getClass());
  +         CachedType type = pojoCache.getCachedType(obj.getClass());
            // add interceptor
            InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
            if (advisor == null)
  @@ -517,7 +519,7 @@
                  throw new CacheException("field access failed", e);
               }
   
  -            CachedType fieldType = pCache_.getCachedType(field.getType());
  +            CachedType fieldType = pojoCache.getCachedType(field.getType());
   
               // we simply treat field that has @Serializable as a primitive type.
               if (fieldType.isImmediate() ||
  @@ -601,7 +603,7 @@
      private void findChildObjects(Fqn fqn, Map map) throws CacheException
      {
         // We need to traverse then
  -      Node root = cache_.getRoot();
  +      Node root = cache.getRoot();
         Node current = root.getChild(fqn);
   
         if (current == null) return;
  
  
  
  1.11      +16 -16    JBossCache/src/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/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- PojoCacheImpl.java	30 May 2007 06:08:01 -0000	1.10
  +++ PojoCacheImpl.java	28 Jun 2007 00:56:06 -0000	1.11
  @@ -33,11 +33,11 @@
    * Implementation class for PojoCache interface
    *
    * @author Ben Wang
  - * @version $Id: PojoCacheImpl.java,v 1.10 2007/05/30 06:08:01 jgreene Exp $
  + * @version $Id: PojoCacheImpl.java,v 1.11 2007/06/28 00:56:06 jgreene Exp $
    */
   public class PojoCacheImpl implements PojoCache
   {
  -   private CacheSPI cache_ = null;
  +   private CacheSPI<Object, Object> cache = null;
      protected final Log log_ = LogFactory.getLog(PojoCacheImpl.this.getClass());
      private PojoCacheDelegate delegate_;
      // Class -> CachedType
  @@ -73,7 +73,7 @@
      {
         try
         {
  -         cache_ = (CacheSPI) DefaultCacheFactory.getInstance().createCache(config, toStart);
  +         cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(config, toStart);
         }
         catch (Exception e)
         {
  @@ -83,9 +83,9 @@
         delegate_ = new PojoCacheDelegate(this);
      }
   
  -   public CacheSPI getUnderlyingCache()
  +   public CacheSPI getCacheSPI()
      {
  -      return cache_;
  +      return cache;
      }
   
      public Object attach(String id, Object pojo) throws PojoCacheException
  @@ -235,7 +235,7 @@
         log_.info("PojoCache version: " + getVersion());
         try
         {
  -         cache_.create();
  +         cache.create();
         }
         catch (Exception e)
         {
  @@ -255,7 +255,7 @@
         try
         {
            log_.info("PojoCache version: " + getVersion());
  -         cache_.start();
  +         cache.start();
         }
         catch (Exception e)
         {
  @@ -265,12 +265,12 @@
   
      public void stop() throws PojoCacheException
      {
  -      cache_.stop();
  +      cache.stop();
      }
   
      public void destroy() throws PojoCacheException
      {
  -      cache_.destroy();
  +      cache.destroy();
      }
   
      public Collection<PojoCacheListener> getListeners()
  @@ -291,7 +291,7 @@
         synchronized (listenerAdaptor)
         {
            listenerAdaptor.addListener(listener, pattern);
  -         cache_.addCacheListener(listenerAdaptor);
  +         cache.addCacheListener(listenerAdaptor);
         }
      }
   
  @@ -301,13 +301,13 @@
         {
            listenerAdaptor.removeListener(listener);
            if (listenerAdaptor.isEmpty())
  -            cache_.removeCacheListener(listenerAdaptor);
  +            cache.removeCacheListener(listenerAdaptor);
         }
      }
   
      public Cache<Object,Object> getCache()
      {
  -      return cache_;
  +      return cache;
      }
   
      /**
  @@ -351,7 +351,7 @@
      public String toString()
      {
         return getClass().getName() +
  -              " cache=" + cache_ +
  +              " cache=" + cache +
                 " delegate=" + delegate_ +
                 " types=" + cachedTypes_.size();
      }
  
  
  
  1.4       +9 -8      JBossCache/src/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/org/jboss/cache/pojo/impl/SerializableObjectHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- SerializableObjectHandler.java	30 May 2007 06:08:02 -0000	1.3
  +++ SerializableObjectHandler.java	28 Jun 2007 00:56:06 -0000	1.4
  @@ -7,32 +7,33 @@
   
   package org.jboss.cache.pojo.impl;
   
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
   
  -import java.util.HashMap;
  -import java.util.Map;
  -
   /**
    * Handle Serializable object cache management.
    *
    * @author Ben Wang
  - * @version $Id: SerializableObjectHandler.java,v 1.3 2007/05/30 06:08:02 jgreene Exp $
  + * @version $Id: SerializableObjectHandler.java,v 1.4 2007/06/28 00:56:06 jgreene Exp $
    */
   class SerializableObjectHandler
   {
  -   private CacheSPI cache_;
  -   private PojoCacheImpl pCache_;
  +   private Cache<Object, Object> cache;
  +   private PojoCacheImpl pojoCache;
      private InternalHelper internal_;
      private final Log log_ = LogFactory.getLog(SerializableObjectHandler.class);
   
      public SerializableObjectHandler(PojoCacheImpl cache, InternalHelper internal)
      {
  -      pCache_ = cache;
  -      cache_ = (CacheSPI) pCache_.getCache();
  +      pojoCache = cache;
  +      this.cache = pojoCache.getCache();
         internal_ = internal;
      }
   
  
  
  



More information about the jboss-cvs-commits mailing list