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

Ben Wang bwang at jboss.com
Fri Jul 28 05:46:07 EDT 2006


  User: bwang   
  Date: 06/07/28 05:46:07

  Modified:    src-50/org/jboss/cache/pojo/impl   PojoCacheDelegate.java
                        PojoCacheImpl.java
  Log:
  fixed event notification
  
  Revision  Changes    Path
  1.11      +16 -1     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.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- PojoCacheDelegate.java	27 Jul 2006 14:25:26 -0000	1.10
  +++ PojoCacheDelegate.java	28 Jul 2006 09:46:07 -0000	1.11
  @@ -111,11 +111,26 @@
         }
      }
   
  +   public Object putObjectI(Fqn fqn, Object obj) throws CacheException
  +   {
  +      // Skip some un-necessary update if obj is the same class as the old one
  +      Object oldValue = internal_.getPojo(fqn);
  +      if (oldValue == obj)
  +      {
  +         if (log.isDebugEnabled())
  +         {
  +            log.debug("putObject(): id: " + fqn + " pojo is already in the cache. Return right away.");
  +         }
  +         return obj;
  +      }
  +      return null;
  +   }
  +
      /**
       * Note that caller of this method will take care of synchronization within the <code>fqn</code> sub-tree.
       *
       */
  -   public Object putObject(Fqn fqn, Object obj) throws CacheException
  +   public Object putObjectII(Fqn fqn, Object obj) throws CacheException
      {
         // Skip some un-necessary update if obj is the same class as the old one
         Object oldValue = internal_.getPojo(fqn);
  
  
  
  1.15      +31 -6     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.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- PojoCacheImpl.java	27 Jul 2006 14:25:26 -0000	1.14
  +++ PojoCacheImpl.java	28 Jul 2006 09:46:07 -0000	1.15
  @@ -25,6 +25,8 @@
   import org.jboss.cache.pojo.annotation.Find;
   import org.jboss.cache.pojo.observable.Observer;
   import org.jboss.cache.pojo.observable.Subject;
  +import org.jboss.aop.proxy.ClassProxy;
  +import org.jboss.aop.Advised;
   
   import java.lang.reflect.Field;
   import java.util.Collection;
  @@ -38,7 +40,7 @@
    * Implementation class for PojoCache interface
    *
    * @author Ben Wang
  - * @version $Id: PojoCacheImpl.java,v 1.14 2006/07/27 14:25:26 bwang Exp $
  + * @version $Id: PojoCacheImpl.java,v 1.15 2006/07/28 09:46:07 bwang Exp $
    */
   public class PojoCacheImpl implements PojoCache, Observer
   {
  @@ -109,8 +111,14 @@
      public Object putObject(Fqn id, Object pojo)
              throws CacheException
      {
  +      Object obj = null;
  +
  +      // Maybe this is the same instance already.
  +      obj = delegate_.putObjectI(id, pojo);
  +      if(obj != null) return obj;
  +
         notifyAttach(pojo, true);
  -      Object obj = delegate_.putObject(id, pojo);
  +      obj = delegate_.putObjectII(id, pojo);
         notifyAttach(pojo, false);
         return obj;
      }
  @@ -249,7 +257,7 @@
   
      public Object XputObject(Fqn fqn, Object obj) throws CacheException
      {
  -      return delegate_.putObject(fqn, obj);
  +      return delegate_.putObjectII(fqn, obj);
      }
   
      /**
  @@ -309,21 +317,23 @@
   
      }
   
  -   protected void notifyAttach(Object pojo, boolean pre)
  +   private void notifyAttach(Object pojo, boolean pre)
      {
         if(pojo == null) return;
  +      if(!shouldNotify(pojo)) return;
  +
         boolean isLocal = true; // TODO Not yet supported. Always true now.
         if (hasListeners)
         {
            for (Iterator it = listeners.iterator(); it.hasNext();)
               ((PojoCacheListener) it.next()).attach(pojo, pre, isLocal);
         }
  -
      }
   
  -   protected void notifyDetach(Object pojo, boolean pre)
  +   private void notifyDetach(Object pojo, boolean pre)
      {
         if(pojo == null) return;
  +      if(!shouldNotify(pojo)) return;
   
         boolean isLocal = true; // TODO Not yet supported. Always true now.
         if (hasListeners)
  @@ -331,6 +341,21 @@
            for (Iterator it = listeners.iterator(); it.hasNext();)
               ((PojoCacheListener) it.next()).detach(pojo, pre, isLocal);
         }
  +   }
   
  +   /**
  +    * Decide whether we want to emit notification event or not.
  +    * @param pojo
  +    */
  +   private boolean shouldNotify(Object pojo)
  +   {
  +      // Not Advised or not Collection
  +      if(!(pojo instanceof Advised) &&
  +              !(pojo instanceof ClassProxy || pojo instanceof Collection ||
  +              pojo instanceof Map))
  +      {
  +         return false;
  +      }
  +      return true;
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list