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

Manik Surtani msurtani at jboss.com
Wed Jan 3 10:33:08 EST 2007


  User: msurtani
  Date: 07/01/03 10:33:08

  Modified:    src/org/jboss/cache/interceptors         
                        InvocationContextInterceptor.java
                        CreateIfNotExistsInterceptor.java
                        OptimisticNodeInterceptor.java
                        CacheLoaderInterceptor.java
                        ActivationInterceptor.java TxInterceptor.java
                        OptimisticValidatorInterceptor.java
                        OptimisticCreateIfNotExistsInterceptor.java
                        PassivationInterceptor.java
  Log:
  Improved notification mechanism, added a notification interceptor
  
  Revision  Changes    Path
  1.13      +0 -0      JBossCache/src/org/jboss/cache/interceptors/InvocationContextInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  
  
  
  1.23      +3 -3      JBossCache/src/org/jboss/cache/interceptors/CreateIfNotExistsInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CreateIfNotExistsInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CreateIfNotExistsInterceptor.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -b -r1.22 -r1.23
  --- CreateIfNotExistsInterceptor.java	2 Jan 2007 17:15:29 -0000	1.22
  +++ CreateIfNotExistsInterceptor.java	3 Jan 2007 15:33:08 -0000	1.23
  @@ -19,7 +19,7 @@
    * (depending on the create_if_not_exists argument)
    *
    * @author Bela Ban
  - * @version $Id: CreateIfNotExistsInterceptor.java,v 1.22 2007/01/02 17:15:29 msurtani Exp $
  + * @version $Id: CreateIfNotExistsInterceptor.java,v 1.23 2007/01/03 15:33:08 msurtani Exp $
    * @deprecated This code is not used anymore and will be removed in a future unlock
    */
   public class CreateIfNotExistsInterceptor extends Interceptor
  @@ -375,8 +375,8 @@
                     // (needed for abort/rollback of transaction)
                     // cache.addNode(tx, (Fqn)tmp_fqn.clone());
                  }
  -               cache.getNotifier().notifyNodeCreated(tmp_fqn, true);
  -               cache.getNotifier().notifyNodeCreated(tmp_fqn, false);
  +               cache.getNotifier().notifyNodeCreated(tmp_fqn, true, true);
  +               cache.getNotifier().notifyNodeCreated(tmp_fqn, false, true);
               }
               n = child_node;
            }
  
  
  
  1.43      +29 -5     JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticNodeInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -b -r1.42 -r1.43
  --- OptimisticNodeInterceptor.java	2 Jan 2007 19:19:05 -0000	1.42
  +++ OptimisticNodeInterceptor.java	3 Jan 2007 15:33:08 -0000	1.43
  @@ -42,7 +42,7 @@
   
      public Object invoke(MethodCall m) throws Throwable
      {
  -      // bypass for buddy group org metod calls.
  +      // bypass for buddy group org method calls.
         if (MethodDeclarations.isBuddyGroupOrganisationMethod(m.getMethodId())) return super.invoke(m);
   
         InvocationContext ctx = cache.getInvocationContext();
  @@ -89,7 +89,8 @@
         {
            // assign a global transaction here if we need to - should do all
            // this in the transaction interceptor
  -         WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(getFqn(args), workspace);
  +         Fqn fqn = getFqn(args);
  +         WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace);
   
   
            if (workspaceNode != null)
  @@ -129,22 +130,34 @@
            {
               case MethodDeclarations.putDataMethodLocal_id:
                  Boolean erase = (Boolean) args[3];
  +               cache.getNotifier().notifyNodeModified(fqn, true, workspaceNode == null ? null : workspaceNode.getData(), false);
                  putDataMap((Map<Object, Object>) args[2], erase, workspace, workspaceNode);
  +               cache.getNotifier().notifyNodeModified(fqn, false, workspaceNode.getData(), false);
                  break;
               case MethodDeclarations.putDataEraseMethodLocal_id:
  +               cache.getNotifier().notifyNodeModified(fqn, true, workspaceNode == null ? null : workspaceNode.getData(), false);
                  putDataMap((Map<Object, Object>) args[2], true, workspace, workspaceNode);
  +               cache.getNotifier().notifyNodeModified(fqn, false, workspaceNode.getData(), false);
                  break;
               case MethodDeclarations.putKeyValMethodLocal_id:
  +               cache.getNotifier().notifyNodeModified(fqn, true, workspaceNode == null ? null : workspaceNode.getData(), false);
                  result = putDataKeyValue(args, workspace, workspaceNode);
  +               cache.getNotifier().notifyNodeModified(fqn, false, workspaceNode.getData(), false);
                  break;
               case MethodDeclarations.removeNodeMethodLocal_id:
  +               cache.getNotifier().notifyNodeRemoved(fqn, true, workspaceNode == null ? null : workspaceNode.getData(), false);
                  removeNode(workspace, workspaceNode);
  +               cache.getNotifier().notifyNodeRemoved(fqn, false, null, false);
                  break;
               case MethodDeclarations.removeKeyMethodLocal_id:
  +               cache.getNotifier().notifyNodeModified(fqn, true, workspaceNode == null ? null : workspaceNode.getData(), false);
                  result = removeKey(args, workspace, workspaceNode);
  +               cache.getNotifier().notifyNodeModified(fqn, false, workspaceNode == null ? null : workspaceNode.getData(), false);
                  break;
               case MethodDeclarations.removeDataMethodLocal_id:
  +               cache.getNotifier().notifyNodeModified(fqn, true, workspaceNode == null ? null : workspaceNode.getData(), false);
                  removeData(workspace, workspaceNode);
  +               cache.getNotifier().notifyNodeModified(fqn, false, workspaceNode == null ? null : workspaceNode.getData(), false);
                  break;
               case MethodDeclarations.dataGravitationCleanupMethod_id:
                  result = super.invoke(m);
  @@ -215,13 +228,16 @@
         // parent pointer is calculated on the fly using Fqns.
   
         // now adjust Fqns of node and all children.
  +      // notify
  +      Fqn nodeNewFqn = new Fqn(parent.getFqn(), nodeFqn.getLastElement());
  +      cache.getNotifier().notifyNodeMoved(nodeFqn, nodeNewFqn, true, false);
         moveFqns(node, parent.getFqn(), ws);
   
         // remove old nodes. this may mark some nodes which have already been moved as deleted
         removeNode(ws, node);
  -      // now remove deletion markers on the nodes moved (and their children).
  -      WorkspaceNode newChild = getOrCreateWorkspaceNode(new Fqn(parent.getFqn(), nodeFqn.getLastElement()), ws);
  -      newChild.markAsDeleted(false, true);
  +
  +      // notify
  +      cache.getNotifier().notifyNodeMoved(nodeFqn, nodeNewFqn, false, false);
      }
   
      /**
  @@ -376,8 +392,10 @@
         else
         {
            //add this node into the wrokspace
  +         cache.getNotifier().notifyNodeVisited(fqn, true, false);
            Object val = workspaceNode.get(key);
            workspace.addNode(workspaceNode);
  +         cache.getNotifier().notifyNodeVisited(fqn, false, false);
            return val;
         }
      }
  @@ -395,7 +413,9 @@
         }
         else
         {
  +         cache.getNotifier().notifyNodeVisited(fqn, true, false);
            workspace.addNode(workspaceNode);
  +         cache.getNotifier().notifyNodeVisited(fqn, false, false);
            return workspaceNode.getNode();
         }
      }
  @@ -413,8 +433,10 @@
         }
         else
         {
  +         cache.getNotifier().notifyNodeVisited(fqn, true, false);
            Object keySet = workspaceNode.getKeys();
            workspace.addNode(workspaceNode);
  +         cache.getNotifier().notifyNodeVisited(fqn, false, false);
            return keySet;
         }
      }
  @@ -432,8 +454,10 @@
         }
         else
         {
  +         cache.getNotifier().notifyNodeVisited(fqn, true, false);
            Object nameSet = workspaceNode.getChildrenNames();
            workspace.addNode(workspaceNode);
  +         cache.getNotifier().notifyNodeVisited(fqn, false, false);
            return nameSet;
         }
      }
  
  
  
  1.68      +5 -5      JBossCache/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheLoaderInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -b -r1.67 -r1.68
  --- CacheLoaderInterceptor.java	1 Jan 2007 22:12:19 -0000	1.67
  +++ CacheLoaderInterceptor.java	3 Jan 2007 15:33:08 -0000	1.68
  @@ -29,7 +29,7 @@
    * Loads nodes that don't exist at the time of the call into memory from the CacheLoader
    *
    * @author Bela Ban
  - * @version $Id: CacheLoaderInterceptor.java,v 1.67 2007/01/01 22:12:19 msurtani Exp $
  + * @version $Id: CacheLoaderInterceptor.java,v 1.68 2007/01/03 15:33:08 msurtani Exp $
    */
   public class CacheLoaderInterceptor extends BaseCacheLoaderInterceptor implements CacheLoaderInterceptorMBean
   {
  @@ -558,13 +558,13 @@
   
         if (nodeExists)
         {
  -         cache.getNotifier().notifyNodeLoaded(fqn, true, Collections.emptyMap());
  -         cache.getNotifier().notifyNodeLoaded(fqn, false, nodeData);
  +         cache.getNotifier().notifyNodeLoaded(fqn, true, Collections.emptyMap(), true);
  +         cache.getNotifier().notifyNodeLoaded(fqn, false, nodeData, true);
   
            if (isActivation)
            {
  -            cache.getNotifier().notifyNodeActivated(fqn, true);
  -            cache.getNotifier().notifyNodeActivated(fqn, false);
  +            cache.getNotifier().notifyNodeActivated(fqn, true, true);
  +            cache.getNotifier().notifyNodeActivated(fqn, false, true);
            }
         }
   
  
  
  
  1.47      +3 -3      JBossCache/src/org/jboss/cache/interceptors/ActivationInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ActivationInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/ActivationInterceptor.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -b -r1.46 -r1.47
  --- ActivationInterceptor.java	30 Dec 2006 19:48:46 -0000	1.46
  +++ ActivationInterceptor.java	3 Jan 2007 15:33:08 -0000	1.47
  @@ -25,7 +25,7 @@
    * their attributes have been initialized and their children have been loaded in memory.
    *
    * @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
  - * @version $Id: ActivationInterceptor.java,v 1.46 2006/12/30 19:48:46 msurtani Exp $
  + * @version $Id: ActivationInterceptor.java,v 1.47 2007/01/03 15:33:08 msurtani Exp $
    */
   public class ActivationInterceptor extends CacheLoaderInterceptor implements ActivationInterceptorMBean
   {
  @@ -183,7 +183,7 @@
   
      private void remove(Fqn fqn) throws Exception
      {
  -      cache.getNotifier().notifyNodeActivated(fqn, true);
  +      cache.getNotifier().notifyNodeActivated(fqn, true, true);
         loader.remove(fqn);
         if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
         {
  @@ -339,7 +339,7 @@
      {
         Modification mod = new Modification(Modification.ModificationType.REMOVE_NODE, fqn);
         l.add(mod);
  -      cache.getNotifier().notifyNodeActivated(fqn, false);
  +      cache.getNotifier().notifyNodeActivated(fqn, false, true);
      }
   
   }
  
  
  
  1.71      +1 -0      JBossCache/src/org/jboss/cache/interceptors/TxInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TxInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/TxInterceptor.java,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -b -r1.70 -r1.71
  --- TxInterceptor.java	2 Jan 2007 18:26:06 -0000	1.70
  +++ TxInterceptor.java	3 Jan 2007 15:33:08 -0000	1.71
  @@ -981,6 +981,7 @@
                  e.printStackTrace();
               }
   
  +
               if (log.isTraceEnabled()) log.trace("calling aftercompletion for " + gtx);
               // set any transaction wide options as current for this thread.
               if ((entry = txTable.get(gtx)) != null)
  
  
  
  1.49      +2 -19     JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticValidatorInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -b -r1.48 -r1.49
  --- OptimisticValidatorInterceptor.java	31 Dec 2006 02:08:40 -0000	1.48
  +++ OptimisticValidatorInterceptor.java	3 Jan 2007 15:33:08 -0000	1.49
  @@ -179,14 +179,14 @@
               }
               else
               {
  -               cache.getNotifier().notifyNodeRemoved(dNode.getFqn(), true, dNode.getNodeSPI().getRawData());
                  Node parent = dNode.getParent();
                  if (parent == null)
                  {
                     throw new IllegalStateException("dNode " + dNode + " has no parent");
                  }
  +               cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
                  parent.removeChild(new Fqn(dNode.getFqn().getLastElement()));
  -               cache.getNotifier().notifyNodeRemoved(dNode.getFqn(), false, null);
  +               cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
               }
            }
            else
  @@ -205,16 +205,6 @@
                  // notify.
                  Map mergedData = wrappedNode.getMergedData();
                  Map rawData = current.getRawData();
  -               boolean needsNotify = !mergedData.equals(rawData);
  -
  -               if (needsNotify)
  -               {
  -                  if (log.isTraceEnabled())
  -                  {
  -                     log.trace("inserting merged data " + mergedData + " for " + current);
  -                  }
  -                  cache.getNotifier().notifyNodeModified(wrappedNode.getFqn(), true, rawData);
  -               }
   
                  Map raw = current.getNodeSPI().getRawData();
                  raw.clear();
  @@ -233,11 +223,6 @@
                  {
                     log.trace("Setting version of node " + current.getFqn() + " from " + wrappedNode.getVersion() + " to " + current.getVersion());
                  }
  -
  -               if (needsNotify)
  -               {
  -                  cache.getNotifier().notifyNodeModified(wrappedNode.getFqn(), false, mergedData);
  -               }
               }
               else
               {
  @@ -245,8 +230,6 @@
                  {
                     log.trace("Merging node " + wrappedNode.getFqn() + " not necessary since the node is not dirty");
                  }
  -               cache.getNotifier().notifyNodeVisited(wrappedNode.getFqn(), true);
  -               cache.getNotifier().notifyNodeVisited(wrappedNode.getFqn(), false);
               }
            }
         }
  
  
  
  1.38      +15 -12    JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticCreateIfNotExistsInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -b -r1.37 -r1.38
  --- OptimisticCreateIfNotExistsInterceptor.java	2 Jan 2007 19:19:05 -0000	1.37
  +++ OptimisticCreateIfNotExistsInterceptor.java	3 Jan 2007 15:33:08 -0000	1.38
  @@ -17,6 +17,7 @@
   import org.jboss.cache.factories.NodeFactory;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
  +import org.jboss.cache.notifications.Notifier;
   import org.jboss.cache.optimistic.DataVersion;
   import org.jboss.cache.optimistic.TransactionWorkspace;
   import org.jboss.cache.optimistic.WorkspaceNode;
  @@ -51,7 +52,7 @@
   
            if (!cache.getRoot().hasChild(fqn))
            {
  -            createNode(fqn);
  +            createNode(fqn, false);
            }
         }
         else if (m.getMethodId() == MethodDeclarations.moveMethodLocal_id)
  @@ -78,7 +79,7 @@
   
         for (Fqn f : fqns)
         {
  -         if (!cache.getRoot().hasChild(f)) createNode(f);
  +         if (!cache.getRoot().hasChild(f)) createNode(f, true);
         }
      }
   
  @@ -88,7 +89,7 @@
       * @param fqn
       * @throws CacheException
       */
  -   private void createNode(Fqn fqn) throws CacheException
  +   private void createNode(Fqn fqn, boolean suppressNotification) throws CacheException
      {
         // we do nothing if fqn is null
         if (fqn == null) return;
  @@ -248,17 +249,19 @@
         } // end sync block
         if (debug) log.debug("done synchronized access of GlobalTX");
   
  -      // run the notify outside the synch block as we do not know what that
  -      // code might do
  +      if (!suppressNotification)
  +      {
         if (nodesCreated.size() > 0)
         {
  +            Notifier n = cache.getNotifier();
            for (Fqn temp : nodesCreated)
            {
  -            cache.getNotifier().notifyNodeCreated(temp, true);
  -            cache.getNotifier().notifyNodeCreated(temp, false);
  +               n.notifyNodeCreated(temp, true, false);
  +               n.notifyNodeCreated(temp, false, false);
               if (log.isDebugEnabled()) log.debug("Notifying cache of node created in workspace " + temp);
            }
         }
      }
  +   }
   
   }
  
  
  
  1.38      +3 -3      JBossCache/src/org/jboss/cache/interceptors/PassivationInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PassivationInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PassivationInterceptor.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -b -r1.37 -r1.38
  --- PassivationInterceptor.java	2 Jan 2007 18:26:06 -0000	1.37
  +++ PassivationInterceptor.java	3 Jan 2007 15:33:08 -0000	1.38
  @@ -16,7 +16,7 @@
    * CacheLoader, either before each method call (no TXs), or at TX commit.
    *
    * @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
  - * @version $Id: PassivationInterceptor.java,v 1.37 2007/01/02 18:26:06 msurtani Exp $
  + * @version $Id: PassivationInterceptor.java,v 1.38 2007/01/03 15:33:08 msurtani Exp $
    */
   public class PassivationInterceptor extends Interceptor implements PassivationInterceptorMBean
   {
  @@ -56,11 +56,11 @@
                  // to get them manually
                  Map attributes = getNodeAttributes(fqn);
                  // notify listeners that this node is about to be passivated
  -               cache.getNotifier().notifyNodePassivated(fqn, true);
  +               cache.getNotifier().notifyNodePassivated(fqn, true, true);
   
                  loader.put(fqn, attributes);
   
  -               cache.getNotifier().notifyNodePassivated(fqn, false);
  +               cache.getNotifier().notifyNodePassivated(fqn, false, true);
               }
   
               if (getStatisticsEnabled() && configuration.getExposeManagementStatistics())
  
  
  



More information about the jboss-cvs-commits mailing list