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

Manik Surtani manik at jboss.org
Thu Jun 28 12:53:35 EDT 2007


  User: msurtani
  Date: 07/06/28 12:53:35

  Modified:    src/org/jboss/cache          CacheSPI.java
                        InvocationContext.java Cache.java
                        ConsoleListener.java TreeCacheView.java
                        RegionManager.java CacheImpl.java
  Removed:     src/org/jboss/cache          AbstractCacheListener.java
                        CacheListener.java
  Log:
  Notification changes
  
  Revision  Changes    Path
  1.37      +2 -3      JBossCache/src/org/jboss/cache/CacheSPI.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheSPI.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheSPI.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -b -r1.36 -r1.37
  --- CacheSPI.java	11 Jun 2007 15:06:02 -0000	1.36
  +++ CacheSPI.java	28 Jun 2007 16:53:35 -0000	1.37
  @@ -27,7 +27,7 @@
   /**
    * A more detailed interface to {@link Cache}, which is used when writing plugins for or extending JBoss Cache.  A reference
    * to this interface should only be obtained when it is passed in to your code, for example when you write an
  - * {@link Interceptor}, {@link CacheLoader} or {@link CacheListener}.
  + * {@link Interceptor} or {@link CacheLoader}.
    * <p/>
    * <B><I>You should NEVER attempt to directly cast a {@link Cache} instance to this interface.  In future, the implementation may not allow it.</I></B>
    * <p/>
  @@ -38,7 +38,6 @@
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @see NodeSPI
    * @see Cache
  - * @see org.jboss.cache.CacheListener
    * @see org.jboss.cache.loader.CacheLoader
    * @see org.jboss.cache.interceptors.Interceptor
    * @since 2.0.0
  @@ -148,7 +147,7 @@
   
      /**
       * @return the notifier attached with this instance of the cache.  See {@link Notifier}, a class
  -    *         that is responsible for emitting notifications to registered {@link CacheListener}s.
  +    *         that is responsible for emitting notifications to registered CacheListeners.
       */
      Notifier getNotifier();
   
  
  
  
  1.15      +0 -28     JBossCache/src/org/jboss/cache/InvocationContext.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InvocationContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/InvocationContext.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- InvocationContext.java	24 May 2007 20:34:04 -0000	1.14
  +++ InvocationContext.java	28 Jun 2007 16:53:35 -0000	1.15
  @@ -11,9 +11,6 @@
   import org.jboss.cache.transaction.GlobalTransaction;
   
   import javax.transaction.Transaction;
  -import java.util.ArrayList;
  -import java.util.LinkedList;
  -import java.util.List;
   
   /**
    * This context holds information specific to a method invocation.
  @@ -22,7 +19,6 @@
    */
   public class InvocationContext implements Cloneable
   {
  -   private transient List<MethodCall> cacheListenerEvents = new LinkedList<MethodCall>();
      private Transaction transaction;
      private GlobalTransaction globalTransaction;
      private Option optionOverrides;
  @@ -127,29 +123,6 @@
         this.originLocal = originLocal;
      }
   
  -   /**
  -    * @return a list of cache listener events set during the course of this invocation
  -    */
  -   public List<MethodCall> getCacheListenerEvents()
  -   {
  -      return new ArrayList<MethodCall>(cacheListenerEvents);
  -   }
  -
  -   /**
  -    * Adds a cache listener event to the list of events created by the current invocation.
  -    *
  -    * @param event
  -    */
  -   public void addCacheListenerEvent(MethodCall event)
  -   {
  -      cacheListenerEvents.add(event);
  -   }
  -
  -   public void clearCacheListenerEvents()
  -   {
  -      cacheListenerEvents.clear();
  -   }
  -
      public String toString()
      {
         return "InvocationContext{" +
  @@ -187,7 +160,6 @@
         optionOverrides = null;
         originLocal = true;
         txHasMods = false;
  -      cacheListenerEvents.clear();
      }
   
      public InvocationContext clone() throws CloneNotSupportedException
  
  
  
  1.30      +24 -20    JBossCache/src/org/jboss/cache/Cache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Cache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Cache.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -b -r1.29 -r1.30
  --- Cache.java	11 Jun 2007 15:06:02 -0000	1.29
  +++ Cache.java	28 Jun 2007 16:53:35 -0000	1.30
  @@ -95,48 +95,52 @@
      Node<K, V> getRoot();
   
      /**
  -    * Adds a {@link CacheListener} to the entire cache.
  +    * Adds a {@link CacheListener} to the entire cache.  The object passed in needs to be properly annotated with the
  +    * {@link @org.jboss.cache.notifications.annotation.CacheListener} annotation otherwise an {@link org.jboss.cache.notifications.IncorrectCacheListenerException} will be thrown.
       *
  -    * @param l listener to add
  +    * @param listener listener to add
       */
  -   void addCacheListener(CacheListener l);
  +   void addCacheListener(Object listener);
   
      /**
  -    * Adds a {@link CacheListener} to a given region.
  +    * Adds a {@link CacheListener} to a given region.  The object passed in needs to be properly annotated with the
  +    * {@link @org.jboss.cache.notifications.annotation.CacheListener} annotation otherwise an {@link org.jboss.cache.notifications.IncorrectCacheListenerException} will be thrown.
       *
  -    * @param region
  -    * @param l
  +    * @param region   region to add listener to
  +    * @param listener listener to add
       */
  -   void addCacheListener(Fqn<?> region, CacheListener l);
  +   void addCacheListener(Fqn<?> region, Object listener);
   
      /**
  -    * Removes a {@link CacheListener} from the cache
  +    * Removes a {@link CacheListener} from the cache.  The object passed in needs to be properly annotated with the
  +    * {@link @org.jboss.cache.notifications.annotation.CacheListener} annotation otherwise an {@link org.jboss.cache.notifications.IncorrectCacheListenerException} will be thrown.
       *
  -    * @param l listener to remove
  +    * @param listener listener to remove
       */
  -   void removeCacheListener(CacheListener l);
  +   void removeCacheListener(Object listener);
   
      /**
  -    * Removes a {@link CacheListener} from a given region.
  +    * Removes a {@link CacheListener} from a given region.  The object passed in needs to be properly annotated with the
  +    * {@link @org.jboss.cache.notifications.annotation.CacheListener} annotation otherwise an {@link org.jboss.cache.notifications.IncorrectCacheListenerException} will be thrown.
       *
  -    * @param region
  -    * @param l
  +    * @param region   region from which to remove listener
  +    * @param listener listener to remove
       */
  -   void removeCacheListener(Fqn<?> region, CacheListener l);
  +   void removeCacheListener(Fqn<?> region, Object listener);
   
      /**
  -    * Retrieves an immutable {@link List} of {@link CacheListener}s attached to the cache.
  +    * Retrieves an immutable {@link List} of objects annotated as {@link org.jboss.cache.notifications.annotation.CacheListener}s attached to the cache.
       *
  -    * @return an immutable {@link List} of {@link CacheListener}s attached to the cache.
  +    * @return an immutable {@link List} of objects annotated as {@link org.jboss.cache.notifications.annotation.CacheListener}s attached to the cache.
       */
  -   Set<CacheListener> getCacheListeners();
  +   Set<Object> getCacheListeners();
   
      /**
  -    * Retrieves an immutable {@link List} of {@link CacheListener}s attached to a specific region.
  +    * Retrieves an immutable {@link List} of objects annotated as {@link org.jboss.cache.notifications.annotation.CacheListener}s attached to a specific region.
       *
  -    * @return an immutable {@link List} of {@link CacheListener}s attached to a specific region.
  +    * @return an immutable {@link List} of objects annotated as {@link org.jboss.cache.notifications.annotation.CacheListener}s attached to a specific region.
       */
  -   Set<CacheListener> getCacheListeners(Fqn<?> region);
  +   Set<Object> getCacheListeners(Fqn<?> region);
   
      /**
       * Associates the specified value with the specified key for a {@link Node} in this cache.
  
  
  
  1.18      +37 -197   JBossCache/src/org/jboss/cache/ConsoleListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConsoleListener.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/ConsoleListener.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- ConsoleListener.java	11 Jun 2007 15:06:02 -0000	1.17
  +++ ConsoleListener.java	28 Jun 2007 16:53:35 -0000	1.18
  @@ -1,10 +1,21 @@
   package org.jboss.cache;
   
  -import org.jgroups.View;
  -
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Set;
  +import org.jboss.cache.notifications.annotation.CacheListener;
  +import org.jboss.cache.notifications.annotation.CacheStarted;
  +import org.jboss.cache.notifications.annotation.CacheStopped;
  +import org.jboss.cache.notifications.annotation.NodeActivated;
  +import org.jboss.cache.notifications.annotation.NodeCreated;
  +import org.jboss.cache.notifications.annotation.NodeEvicted;
  +import org.jboss.cache.notifications.annotation.NodeLoaded;
  +import org.jboss.cache.notifications.annotation.NodeModified;
  +import org.jboss.cache.notifications.annotation.NodeMoved;
  +import org.jboss.cache.notifications.annotation.NodePassivated;
  +import org.jboss.cache.notifications.annotation.NodeRemoved;
  +import org.jboss.cache.notifications.annotation.NodeVisited;
  +import org.jboss.cache.notifications.annotation.ViewChanged;
  +import org.jboss.cache.notifications.event.Event;
  +import org.jboss.cache.notifications.event.NodeEvent;
  +import org.jboss.cache.notifications.event.ViewChangedEvent;
   
   /**
    * This class provides a non-graphical view of <em>JBossCache</em> replication
  @@ -19,7 +30,8 @@
    *
    * @author Jimmy Wilson 12-2004
    */
  -public class ConsoleListener extends AbstractCacheListener
  + at CacheListener
  +public class ConsoleListener
   {
      private CacheImpl _cache;
      private boolean _startCache;
  @@ -101,111 +113,40 @@
         }
      }
   
  -   /*
  -   * TreeCacheListener implementation.
  -   */
   
  -   public void cacheStarted(CacheSPI cache)
  +   @CacheStarted
  +   @CacheStopped
  +   public void printDetails(Event e)
      {
         printEvent("Cache started.");
      }
   
  -   public void cacheStopped(CacheSPI cache)
  -   {
  -      printEvent("Cache stopped.");
  -   }
  -
  -   public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
  -   {
  -      if (pre) printNode(fqn, "created");
  -   }
  -
  -   public void nodeLoaded(Fqn fqn, boolean pre, Map data)
  -   {
  -      if (pre) printNode(fqn, "loaded");
  -   }
  -
  -   public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
  -   {
  -      if (pre)
  -      {
  -         printEvent("DataNode about to be modified: " + fqn);
  -      }
  -      else
  -      {
  -         printEvent("DataNode modified: " + fqn);
  -      }
  -   }
  -
  -   public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
  -   {
  -      if (pre)
  -      {
  -         printEvent("DataNode about to be removed: " + fqn);
  -      }
  -      else
  -      {
  -         printEvent("DataNode removed: " + fqn);
  -      }
  -
  -   }
   
  -   public void nodeMoved(Fqn from, Fqn to, boolean pre, boolean isLocal)
  +   @NodeCreated
  +   @NodeLoaded
  +   @NodeModified
  +   @NodeRemoved
  +   @NodeVisited
  +   @NodeMoved
  +   @NodeEvicted
  +   @NodeActivated
  +   @NodePassivated
  +   public void printDetailsWithFqn(NodeEvent e)
      {
  -      if (pre)
  +      if (e.isPre())
         {
  -         printEvent("About to move " + from + " to " + to);
  +         printEvent("Event " + e.getType() + " on node [" + e.getFqn() + "] about to be invoked");
         }
         else
         {
  -         printEvent("Moved " + from + " to " + to);
  +         printEvent("Event " + e.getType() + " on node [" + e.getFqn() + "] invoked");
         }
      }
   
  -   public void nodeVisited(Fqn fqn, boolean pre)
  +   @ViewChanged
  +   public void printNewView(ViewChangedEvent e)
      {
  -      if (pre) printEvent("DataNode visited: " + fqn);
  -   }
  -
  -   public void viewChange(View new_view)
  -   {
  -      printEvent("View change: " + new_view);
  -   }
  -
  -   public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
  -   {
  -      if (pre)
  -      {
  -         printEvent("DataNode about to be evicted: " + fqn);
  -      }
  -      else
  -      {
  -         printEvent("DataNode evicted: " + fqn);
  -      }
  -   }
  -
  -   public void nodeActivated(Fqn fqn, boolean pre, Map data)
  -   {
  -      if (pre)
  -      {
  -         printEvent("DataNode about to be activated: " + fqn);
  -      }
  -      else
  -      {
  -         printEvent("DataNode activated: " + fqn);
  -      }
  -   }
  -
  -   public void nodePassivated(Fqn fqn, boolean pre, Map data)
  -   {
  -      if (pre)
  -      {
  -         printEvent("DataNode about to be evicted: " + fqn);
  -      }
  -      else
  -      {
  -         printEvent("DataNode evicted: " + fqn);
  -      }
  +      printEvent("View change: " + e.getNewView());
      }
   
      /**
  @@ -222,107 +163,6 @@
      }
   
      /**
  -    * Prints the contents of the specified node.
  -    *
  -    * @param fqn         the fully qualified name of the node to print.
  -    * @param eventDetail a description of why the node is being printed.
  -    */
  -   private void printNode(Fqn fqn, String eventDetail)
  -   {
  -      System.out.print("EVENT");
  -      System.out.print(' ');
  -      System.out.print("DataNode");
  -      System.out.print(' ');
  -      System.out.print(eventDetail);
  -      System.out.print(':');
  -      System.out.print(' ');
  -      System.out.print(fqn);
  -      System.out.println();
  -
  -      printNodeMap(fqn);
  -
  -      System.out.println();
  -   }
  -
  -   /**
  -    * Prints the contents of the specified node's <code>Map</code>.
  -    *
  -    * @param fqn the fully qualified name of the node containing the
  -    *            <code>Map</code> to be printed.
  -    */
  -   private void printNodeMap(Fqn fqn)
  -   {
  -      try
  -      {
  -         Set keys = _cache.getKeys(fqn);
  -
  -         if (keys != null)
  -         {
  -            int maxKeyLength = 0;
  -            Iterator iterator = keys.iterator();
  -
  -            while (iterator.hasNext())
  -            {
  -               String key = (String) iterator.next();
  -
  -               int keyLength = key.length();
  -
  -               if (keyLength > maxKeyLength)
  -               {
  -                  maxKeyLength = keyLength;
  -               }
  -            }
  -
  -            iterator = keys.iterator();
  -
  -            while (iterator.hasNext())
  -            {
  -               String key = (String) iterator.next();
  -
  -               System.out.print('\t');
  -               System.out.print('[');
  -
  -               pad(key, maxKeyLength);
  -
  -               System.out.print(',');
  -               System.out.print(' ');
  -               System.out.print(_cache.get(fqn, key));
  -               System.out.println(']');
  -            }
  -         }
  -      }
  -      catch (Exception e)
  -      {
  -         e.printStackTrace(System.out);
  -      }
  -   }
  -
  -   /**
  -    * Pads standard output for printing of the specified key.
  -    *
  -    * @param key          the to be printed in a padded fashion.
  -    * @param maxKeyLength the maximum length of the keys printed using this
  -    *                     method.  All keys whose length is less than this
  -    *                     value will be printed in padded fashion.
  -    */
  -   private void pad(String key, int maxKeyLength)
  -   {
  -      System.out.print(key);
  -
  -      int keyLength = key.length();
  -
  -      if (keyLength < maxKeyLength)
  -      {
  -         int padCount = maxKeyLength - keyLength;
  -
  -         for (int i = 0; i < padCount; i++)
  -         {
  -            System.out.print(' ');
  -         }
  -      }
  -   }
  -
  -   /**
       * This class provides a shutdown hook for shutting down the cache.
       */
      private class ListenerShutdownHook extends Thread
  
  
  
  1.29      +52 -97    JBossCache/src/org/jboss/cache/TreeCacheView.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheView.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -b -r1.28 -r1.29
  --- TreeCacheView.java	14 Jun 2007 15:30:14 -0000	1.28
  +++ TreeCacheView.java	28 Jun 2007 16:53:35 -0000	1.29
  @@ -7,13 +7,19 @@
    */
   package org.jboss.cache;
   
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.jmx.CacheJmxWrapper;
   import org.jboss.cache.jmx.CacheJmxWrapperMBean;
  -import org.jgroups.View;
  +import org.jboss.cache.notifications.annotation.CacheListener;
  +import org.jboss.cache.notifications.annotation.NodeCreated;
  +import org.jboss.cache.notifications.annotation.NodeEvicted;
  +import org.jboss.cache.notifications.annotation.NodeLoaded;
  +import org.jboss.cache.notifications.annotation.NodeRemoved;
  +import org.jboss.cache.notifications.annotation.ViewChanged;
  +import org.jboss.cache.notifications.event.NodeEvent;
  +import org.jboss.cache.notifications.event.ViewChangedEvent;
   
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
  @@ -46,7 +52,6 @@
   import java.util.Set;
   import java.util.Vector;
   
  -
   /**
    * Graphical view of a ReplicatedTree (using the MVC paradigm). An instance of this class needs to be given a
    * reference to the underlying model (ReplicatedTree) and needs to registers as a ReplicatedTreeListener. Changes
  @@ -56,7 +61,7 @@
    * data needs to be displayed, the underlying cache will be accessed directly.
    *
    * @author Bela Ban
  - * @version $Revision: 1.28 $
  + * @version $Revision: 1.29 $
    */
   public class TreeCacheView implements TreeCacheViewMBean
   {
  @@ -261,7 +266,7 @@
               c.setReplQueueMaxElements(queue_max_elements);
            }
   
  -         cache.getNotifier().addCacheListener(new MyListener());
  +         //cache.getNotifier().addCacheListener(new AbstractCacheListener(){});
   
            log.info("registering the cache as " + mbean_name);
            CacheJmxWrapper mbean = new CacheJmxWrapper(cache);
  @@ -335,18 +340,11 @@
                            "[-use_queue <true/false>] [-queue_interval <ms>] " +
                            "[-queue_max_elements <num>]");
      }
  -
  -
  -   public static class MyListener extends AbstractCacheListener
  -   {
  -   }
  -
  -
   }
   
   
  -class TreeCacheGui extends JFrame implements WindowListener, CacheListener,
  -      TreeSelectionListener, TableModelListener
  + at CacheListener
  +class TreeCacheGui extends JFrame implements WindowListener, TreeSelectionListener, TableModelListener
   {
      private static final long serialVersionUID = 8576324868563647538L;
      CacheSPI cache;
  @@ -546,13 +544,15 @@
   
      /* ------------------ ReplicatedTree.ReplicatedTreeListener interface ------------ */
   
  -   public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
  +   @NodeCreated
  +   @NodeLoaded
  +   public void nodeCreated(NodeEvent e)
      {
  -      if (!pre)
  +      if (!e.isPre())
         {
            MyNode n, p;
   
  -         n = root.add(fqn);
  +         n = root.add(e.getFqn());
            if (n != null)
            {
               p = (MyNode) n.getParent();
  @@ -562,14 +562,16 @@
         }
      }
   
  -   public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
  +   @NodeRemoved
  +   @NodeEvicted
  +   public void nodeRemoved(NodeEvent e)
      {
  -      if (!pre)
  +      if (!e.isPre())
         {
            MyNode n;
            TreeNode par;
   
  -         n = root.findNode(fqn);
  +         n = root.findNode(e.getFqn());
            if (n != null)
            {
               n.removeAllChildren();
  @@ -580,62 +582,15 @@
         }
      }
   
  -   public void nodeVisited(Fqn fqn, boolean pre)
  -   {
  -   }
  -
  -   public void nodeLoaded(Fqn fqn, boolean pre, Map data)
  -   {
  -      nodeCreated(fqn, pre, false);
  -   }
  -
  -   public void nodeMoved(Fqn from, Fqn to, boolean pre, boolean isLocal)
  -   {
  -   }
  -
  -   public void nodeActivated(Fqn fqn, boolean pre, Map data)
  -   {
  -   }
  -
  -   public void nodePassivated(Fqn fqn, boolean pre, Map data)
  -   {
  -   }
  -
  -   public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
  -   {
  -      nodeRemoved(fqn, pre, isLocal, null);
  -   }
  -
  -   public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
  -   {
  -      // Map data;
  -      //data=getData(fqn);
  -      //populateTable(data); REVISIT
  -      /*
  -        poulateTable is the current table being shown is the info of the node. that is modified.
  -      */
  -   }
  -
  -   public void nodeVisited(Fqn fqn, boolean pre, boolean isLocal)
  -   {
  -   }
  -
  -   public void cacheStarted(CacheSPI cache)
  -   {
  -   }
  -
  -   public void cacheStopped(CacheSPI cache)
  -   {
  -   }
  -
  -   public void viewChange(final View new_view)
  +   @ViewChanged
  +   public void viewChange(final ViewChangedEvent e)
      {
         new Thread()
         {
            public void run()
            {
               Vector mbrship;
  -            if (new_view != null && (mbrship = new_view.getMembers()) != null)
  +            if (e.getNewView() != null && (mbrship = e.getNewView().getMembers()) != null)
               {
                  put(SEP, "members", mbrship);
                  put(SEP, "coordinator", mbrship.firstElement());
  
  
  
  1.38      +10 -1     JBossCache/src/org/jboss/cache/RegionManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RegionManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionManager.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -b -r1.37 -r1.38
  --- RegionManager.java	24 May 2007 18:14:00 -0000	1.37
  +++ RegionManager.java	28 Jun 2007 16:53:35 -0000	1.38
  @@ -774,10 +774,19 @@
       */
      public void startEvictionThread()
      {
  -      evictionTimerTask.init(evictionConfig.getWakeupIntervalSeconds(), cache.getNotifier());
  +      evictionTimerTask.init(evictionConfig.getWakeupIntervalSeconds());
      }
   
      /**
  +    * Stops the eviction processing thread
  +    */
  +   public void stopEvictionThread()
  +   {
  +      evictionTimerTask.stop();
  +   }
  +
  +
  +   /**
       * Returns a string containing debug information on every region.
       */
      public String dumpRegions()
  
  
  
  1.96      +143 -104  JBossCache/src/org/jboss/cache/CacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -b -r1.95 -r1.96
  --- CacheImpl.java	18 Jun 2007 16:28:21 -0000	1.95
  +++ CacheImpl.java	28 Jun 2007 16:53:35 -0000	1.96
  @@ -35,6 +35,7 @@
   import org.jboss.cache.marshall.NodeData;
   import org.jboss.cache.marshall.VersionAwareMarshaller;
   import org.jboss.cache.notifications.Notifier;
  +import org.jboss.cache.notifications.event.NodeModifiedEvent;
   import org.jboss.cache.optimistic.DataVersion;
   import org.jboss.cache.statetransfer.StateTransferManager;
   import org.jboss.cache.transaction.GlobalTransaction;
  @@ -959,12 +960,12 @@
            cacheLoaderManager.stopCacheLoader();
         }
   
  +      if (regionManager.isUsingEvictions()) regionManager.stopEvictionThread();
  +
         if (notifier != null)
         {
            notifier.notifyCacheStopped(this, getInvocationContext());
  -         notifier.drainNotificationQueue();
            notifier.removeAllCacheListeners();
  -         notifier.setEvictionPolicyListener(null);
         }
   
         // unset transaction manager reference
  @@ -2259,9 +2260,10 @@
            log.trace("_put(" + tx + ", \"" + fqn + "\", " + data + " undo=" + create_undo_ops + " erase=" + erase_contents + ")");
         }
         InvocationContext ctx = getInvocationContext();
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
         NodeSPI<K, V> n = findNodeCheck(tx, fqn);
         Map<K, V> rawData = n.getDataDirect();
  -      notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.PUT_MAP, rawData, ctx);
  +      if (!isRollback) notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, rawData, ctx);
   
         // create a compensating method call (reverting the effect of
         // this modification) and put it into the TX's undo list.
  @@ -2276,8 +2278,8 @@
            n.clearDataDirect();
         n.putAllDirect(data);
   
  -      notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.PUT_MAP, n.getDataDirect(), ctx);
  -
  +      if (!isRollback)
  +         notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_MAP, n.getDataDirect(), ctx);
      }
   
      /**
  @@ -2291,6 +2293,21 @@
         return _put(tx, Fqn.fromString(fqn), key, value, create_undo_ops);
      }
   
  +   private boolean checkIsRollingBack(Transaction tx)
  +   {
  +      try
  +      {
  +         return tx != null && (
  +                 tx.getStatus() == javax.transaction.Status.STATUS_ROLLEDBACK ||
  +                         tx.getStatus() == javax.transaction.Status.STATUS_ROLLING_BACK ||
  +                         tx.getStatus() == javax.transaction.Status.STATUS_MARKED_ROLLBACK);
  +      }
  +      catch (Exception e)
  +      {
  +         // can't get a hold of a transaction - probably no tx rolling back
  +         return false;
  +      }
  +   }
   
      /**
       * Internal put method.
  @@ -2305,15 +2322,16 @@
            log.trace(new StringBuffer("_put(").append(tx).append(", \"").
                  append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
         }
  -      // TODO remove before release
  -      if (key instanceof Map)
  -      {
  -         log.warn("using a map as a key in a map, did you mean to do that?");
  -      }
  +
  +
         InvocationContext ctx = getInvocationContext();
  +      // if this is a rollback then don't fire notifications.
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
  +
         NodeSPI<K, V> n = findNodeCheck(tx, fqn);
         Map<K, V> rawData = n.getDataDirect();
  -      notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.PUT_DATA, rawData, ctx);
  +      if (!isRollback)
  +         notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA, rawData, ctx);
   
         V old_value = n.putDirect(key, value);
   
  @@ -2335,7 +2353,8 @@
         }
   
         Map<K, V> newData = Collections.singletonMap(key, value);
  -      notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.PUT_DATA, newData, ctx);
  +      if (!isRollback)
  +         notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_DATA, newData, ctx);
         return old_value;
      }
   
  @@ -2403,12 +2422,12 @@
         }
         InvocationContext ctx = getInvocationContext();
         // check if this is triggered by a rollback operation ...
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
         if (tx != null)
         {
            try
            {
  -            int status = tx_table.getLocalTransaction(tx).getStatus();
  -            if (status == Status.STATUS_MARKED_ROLLBACK || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_ROLLING_BACK)
  +            if (isRollback)
               {
                  log.trace("This remove call is triggered by a transaction rollback, as a compensation operation.  Do a realRemove() instead.");
                  return realRemove(fqn, true);
  @@ -2432,6 +2451,8 @@
            return false;
         }
   
  +      if (!isRollback)
  +      {
         if (eviction)
         {
            notifier.notifyNodeEvicted(fqn, true, ctx);
  @@ -2440,6 +2461,7 @@
         {
            notifier.notifyNodeRemoved(fqn, true, n.getDataDirect(), ctx);
         }
  +      }
   
         parent_node = n.getParent();
         boolean found;
  @@ -2474,6 +2496,8 @@
            tx_table.addUndoOperation(tx, undo_op);
         }
   
  +      if (!isRollback)
  +      {
         if (eviction)
         {
            notifier.notifyNodeEvicted(fqn, false, ctx);
  @@ -2482,6 +2506,7 @@
         {
            notifier.notifyNodeRemoved(fqn, false, null, ctx);
         }
  +      }
   
         return found;
      }
  @@ -2526,7 +2551,9 @@
            return null;
         }
         InvocationContext ctx = getInvocationContext();
  -      notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.REMOVE_DATA, n.getDataDirect(), ctx);
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
  +      if (!isRollback)
  +         notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.REMOVE_DATA, n.getDataDirect(), ctx);
   
         old_value = n.removeDirect(key);
   
  @@ -2540,7 +2567,8 @@
         }
   
         Map<K, V> removedData = Collections.singletonMap(key, old_value);
  -      notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.REMOVE_DATA, removedData, ctx);
  +      if (!isRollback)
  +         notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.REMOVE_DATA, removedData, ctx);
   
         return old_value;
      }
  @@ -2605,6 +2633,7 @@
   
         Map<K, V> data = n.getDataDirect();
         InvocationContext ctx = getInvocationContext();
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
         // create a compensating method call (reverting the effect of
         // this modification) and put it into the TX's undo list.
         if (tx != null && create_undo_ops && !eviction)
  @@ -2616,13 +2645,16 @@
            }
         }
   
  +      if (!isRollback)
  +      {
         if (eviction)
         {
            notifier.notifyNodeEvicted(fqn, true, ctx);
         }
         else
         {
  -         notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.REMOVE_DATA, data, ctx);
  +            notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.REMOVE_DATA, data, ctx);
  +         }
         }
   
         n.clearDataDirect();
  @@ -2631,6 +2663,8 @@
            n.setDataLoaded(false);
         }
   
  +      if (!isRollback)
  +      {
         if (sendNodeEvent)
         {
            notifier.notifyNodeVisited(fqn, false, ctx);
  @@ -2643,7 +2677,8 @@
            }
            else
            {
  -            notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.REMOVE_DATA, data, ctx);
  +               notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.REMOVE_DATA, data, ctx);
  +            }
            }
         }
   
  @@ -2761,8 +2796,9 @@
            return;
         }
         InvocationContext ctx = getInvocationContext();
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
         Fqn fqn = new Fqn(parent_fqn, child_name);
  -      notifier.notifyNodeCreated(fqn, true, ctx);
  +      if (!isRollback) notifier.notifyNodeCreated(fqn, true, ctx);
         parentNode.addChild(child_name, childNode);
   
         childNode.markAsDeleted(false, true);
  @@ -2773,7 +2809,7 @@
            tx_table.addUndoOperation(gtx, MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, gtx, fqn, false));
         }
   
  -      notifier.notifyNodeCreated(fqn, false, ctx);
  +      if (!isRollback) notifier.notifyNodeCreated(fqn, false, ctx);
      }
   
   
  @@ -3204,13 +3240,16 @@
         newParent.addChild(nodeName, node);
         InvocationContext ctx = getInvocationContext();
         // parent pointer is calculated on the fly using Fqns.
  +      boolean isRollback = checkIsRollingBack(ctx.getTransaction());
   
         // notify
  +      if (!isRollback)
         notifier.notifyNodeMoved(nodeToMoveFqn, new Fqn(newParentFqn, nodeToMoveFqn.getLastElement()), true, ctx);
   
         // now adjust Fqns of node and all children.
         moveFqns(node, newParent.getFqn());
   
  +      if (!isRollback)
         notifier.notifyNodeMoved(nodeToMoveFqn, new Fqn(newParentFqn, nodeToMoveFqn.getLastElement()), false, ctx);
   
         // now register an undo op
  @@ -4180,36 +4219,36 @@
         return modifiable == null ? null : Collections.unmodifiableList(modifiable);
      }
   
  -   public void addCacheListener(CacheListener l)
  +   public void addCacheListener(Object listener)
      {
  -      getNotifier().addCacheListener(l);
  +      getNotifier().addCacheListener(listener);
      }
   
  -   public void addCacheListener(Fqn<?> region, CacheListener l)
  +   public void addCacheListener(Fqn<?> region, Object listener)
      {
         throw new UnsupportedOperationException("Not implemented in this release");
      }
   
  -   public void removeCacheListener(CacheListener l)
  +   public void removeCacheListener(Object listener)
      {
         // BES 2007/5/23 workaround to avoid NPE while we decide whether
         // to remove notifier in destroy()
         Notifier n = getNotifier();
         if (n != null)
  -         n.removeCacheListener(l);
  +         n.removeCacheListener(listener);
      }
   
  -   public void removeCacheListener(Fqn<?> region, CacheListener l)
  +   public void removeCacheListener(Fqn<?> region, Object listener)
      {
         throw new UnsupportedOperationException("Not implemented in this release");
      }
   
  -   public Set<CacheListener> getCacheListeners()
  +   public Set<Object> getCacheListeners()
      {
         return getNotifier().getCacheListeners();
      }
   
  -   public Set<CacheListener> getCacheListeners(Fqn<?> region)
  +   public Set<Object> getCacheListeners(Fqn<?> region)
      {
         throw new UnsupportedOperationException("Not implemented in this release");
      }
  
  
  



More information about the jboss-cvs-commits mailing list