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

Jason Thomas Greene jgreene at jboss.com
Thu May 31 15:11:06 EDT 2007


  User: jgreene 
  Date: 07/05/31 15:11:06

  Modified:    src/org/jboss/cache/pojo/impl   CacheListenerAdaptor.java
                        InternalConstant.java
  Log:
  Add collection notifications
  
  Revision  Changes    Path
  1.2       +39 -11    JBossCache/src/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheListenerAdaptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- CacheListenerAdaptor.java	30 May 2007 06:08:01 -0000	1.1
  +++ CacheListenerAdaptor.java	31 May 2007 19:11:06 -0000	1.2
  @@ -22,9 +22,13 @@
   
   package org.jboss.cache.pojo.impl;
   
  +import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_OPERATION;
  +import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_STATUS;
  +
   import java.lang.reflect.Field;
   import java.util.Collection;
   import java.util.HashSet;
  +import java.util.List;
   import java.util.Map;
   import java.util.Set;
   import java.util.regex.Pattern;
  @@ -37,21 +41,25 @@
   import org.jboss.cache.pojo.notification.AttachNotification;
   import org.jboss.cache.pojo.notification.DetachNotification;
   import org.jboss.cache.pojo.notification.FieldModifyNotification;
  +import org.jboss.cache.pojo.notification.ListModifyNotification;
  +import org.jboss.cache.pojo.notification.MapModifyNotification;
   import org.jboss.cache.pojo.notification.Notification;
   import org.jboss.cache.pojo.notification.NotificationContext;
  +import org.jboss.cache.pojo.notification.SetModifyNotification;
  +
  +// $Id: CacheListenerAdaptor.java,v 1.2 2007/05/31 19:11:06 jgreene Exp $
   
   /**
    * Adapts the core cache listener API into the POJO listener API.
    *
    * @author Jason T. Greene
  - * @revision $Id: CacheListenerAdaptor.java,v 1.1 2007/05/30 06:08:01 jgreene Exp $
    */
   public class CacheListenerAdaptor extends AbstractCacheListener implements NotificationContext
   {
      private static final HashSet<String> internalKeys = new HashSet<String>();
      static
      {
  -      internalKeys.add(InternalConstant.POJOCACHE_STATUS);
  +      internalKeys.add(POJOCACHE_STATUS);
         internalKeys.add(PojoInstance.KEY);
         internalKeys.add(PojoReference.KEY);
         internalKeys.add(PojoTxLockInterceptor.LOCK_KEY);
  @@ -114,17 +122,40 @@
         
         if (modType == ModificationType.PUT_DATA)
         {
  -         if ("ATTACHED".equals(data.get(InternalConstant.POJOCACHE_STATUS)))
  +         if ("ATTACHED".equals(data.get(POJOCACHE_STATUS)))
            {
               Object o = cache.find(fqn.toString());
               sendNotification(new AttachNotification(this, o, isLocal), matched);
            }
  -         else if ("DETACHING".equals(data.get(InternalConstant.POJOCACHE_STATUS)))
  +         else if ("DETACHING".equals(data.get(POJOCACHE_STATUS)))
            {
               Object o = cache.find(fqn.toString());
               sendNotification(new DetachNotification(this, o, isLocal), matched);
            }
  -         else if ("ATTACHED".equals(cache.getCache().get(fqn, InternalConstant.POJOCACHE_STATUS)))
  +         else if (data.containsKey(POJOCACHE_OPERATION)) 
  +         {
  +            Object collection = cache.find(fqn.getParent().toString());
  +            if (collection instanceof List)
  +            {
  +               int i = Integer.parseInt(fqn.getLastElementAsString());
  +               ListModifyNotification.Operation operation = ListModifyNotification.Operation.valueOf(data.get(POJOCACHE_OPERATION).toString());
  +               Object value = cache.find(fqn.toString());
  +               sendNotification(new ListModifyNotification(this, (List)collection, operation, i, value, isLocal), matched);
  +            }
  +            else if (collection instanceof Set)
  +            {
  +               SetModifyNotification.Operation operation = SetModifyNotification.Operation.valueOf(data.get(POJOCACHE_OPERATION).toString());
  +               Object value = cache.find(fqn.toString());
  +               sendNotification(new SetModifyNotification(this, (Set)collection, operation, value, isLocal), matched);
  +            }
  +            else if (collection instanceof Map)
  +            {
  +               MapModifyNotification.Operation operation = MapModifyNotification.Operation.valueOf(data.get(POJOCACHE_OPERATION).toString());
  +               Object value = cache.find(fqn.toString());
  +               sendNotification(new MapModifyNotification(this, (Map)collection, operation, fqn.getLastElement(), value, isLocal), matched);
  +            }
  +         }
  +         else if ("ATTACHED".equals(cache.getCache().get(fqn, POJOCACHE_STATUS)))
            {
               for (Map.Entry<Object, Object> entry : data.entrySet())
               {
  @@ -153,12 +184,9 @@
   
      private Set<PojoCacheListener> matchListeners(Fqn fqn)
      {
  -      if (dispatcher.hasFilters())
  -      {        
            PojoInstance instance = (PojoInstance) cache.getCache().get(fqn, PojoInstance.KEY);
            if (instance != null)
               return dispatcher.getListeners(instance.getReferences());
  -      }
         
         return null;
      }
  
  
  
  1.2       +2 -1      JBossCache/src/org/jboss/cache/pojo/impl/InternalConstant.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InternalConstant.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/InternalConstant.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- InternalConstant.java	30 May 2007 06:08:01 -0000	1.1
  +++ InternalConstant.java	31 May 2007 19:11:06 -0000	1.2
  @@ -27,5 +27,6 @@
      public static final String JBOSS_INTERNAL_STATIC = "__jboss:static__";
      public static final String ENUM_KEY = "name";
      public static final String POJOCACHE_KEY_PREFIX = "POJOCache.";
  -   public static final String POJOCACHE_STATUS = POJOCACHE_KEY_PREFIX + "STATUS";
  +   public static final String POJOCACHE_STATUS = POJOCACHE_KEY_PREFIX + "Status";
  +   public static final String POJOCACHE_OPERATION = POJOCACHE_KEY_PREFIX + "Operation";
   }
  
  
  



More information about the jboss-cvs-commits mailing list