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

Manik Surtani manik at jboss.org
Fri Jun 8 11:39:29 EDT 2007


  User: msurtani
  Date: 07/06/08 11:39:29

  Modified:    src/org/jboss/cache/notifications  Notifier.java
  Log:
  JBCACHE-1022
  
  Revision  Changes    Path
  1.27      +69 -288   JBossCache/src/org/jboss/cache/notifications/Notifier.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Notifier.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/notifications/Notifier.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -b -r1.26 -r1.27
  --- Notifier.java	8 Jun 2007 15:03:06 -0000	1.26
  +++ Notifier.java	8 Jun 2007 15:39:29 -0000	1.27
  @@ -48,8 +48,8 @@
      private final Set<CacheListener> listeners = new ConcurrentHashSet<CacheListener>();
      private static final Log log = LogFactory.getLog(Notifier.class);
   
  -   // --- the java.lang.reflect.Methods of CacheListener
  -   private static Method nodeCreated, nodeModified, nodeRemoved, nodeVisited, nodeEvicted, nodeLoaded, nodePassivated, nodeActivated, nodeMoved, cacheStarted, cacheStopped, viewChange;
  +   // --- the java.lang.reflect.Methods of CacheListener - only the ones that are put on the notification queue
  +   private static Method nodeCreated, nodeModified, nodeRemoved, nodeVisited, nodeLoaded, nodePassivated, nodeActivated, nodeMoved;
   
      private static Class emptyMap = Collections.emptyMap().getClass();
      private static Class singletonMap = Collections.singletonMap(null, null).getClass();
  @@ -62,14 +62,10 @@
            nodeModified = CacheListener.class.getMethod("nodeModified", Fqn.class, boolean.class, boolean.class, CacheListener.ModificationType.class, Map.class);
            nodeRemoved = CacheListener.class.getMethod("nodeRemoved", Fqn.class, boolean.class, boolean.class, Map.class);
            nodeVisited = CacheListener.class.getMethod("nodeVisited", Fqn.class, boolean.class);
  -         nodeEvicted = CacheListener.class.getMethod("nodeEvicted", Fqn.class, boolean.class, boolean.class);
            nodeLoaded = CacheListener.class.getMethod("nodeLoaded", Fqn.class, boolean.class, Map.class);
            nodePassivated = CacheListener.class.getMethod("nodePassivated", Fqn.class, boolean.class, Map.class);
            nodeActivated = CacheListener.class.getMethod("nodeActivated", Fqn.class, boolean.class, Map.class);
            nodeMoved = CacheListener.class.getMethod("nodeMoved", Fqn.class, Fqn.class, boolean.class, boolean.class);
  -         cacheStarted = CacheListener.class.getMethod("cacheStarted", CacheSPI.class);
  -         cacheStopped = CacheListener.class.getMethod("cacheStopped", CacheSPI.class);
  -         viewChange = CacheListener.class.getMethod("viewChange", View.class);
         }
         catch (Exception e)
         {
  @@ -150,37 +146,13 @@
       * @param fqn
       * @param pre
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx)
      {
  -      sendImmediately = false;
         boolean originLocal = ctx.isOriginLocal();
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeCreated(fqn, pre, originLocal);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeCreated(fqn, pre, originLocal);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
            MethodCall call = new MethodCall(nodeCreated, new Object[]{fqn, pre, originLocal});
            ctx.addCacheListenerEvent(call);
         }
  -   }
   
      /**
       * Notifies all registered listeners of a nodeModified event.
  @@ -190,38 +162,14 @@
       * @param modificationType
       * @param data
       * @param ctx              context of invocation
  -    * @param sendImmediately  whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeModified(Fqn fqn, boolean pre, CacheListener.ModificationType modificationType, Map<K, V> data, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeModified(Fqn fqn, boolean pre, CacheListener.ModificationType modificationType, Map<K, V> data, InvocationContext ctx)
      {
  -      sendImmediately = false;
         boolean originLocal = ctx.isOriginLocal();
         Map dataCopy = copy(data);
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeModified(fqn, pre, originLocal, modificationType, dataCopy);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeModified(fqn, pre, originLocal, modificationType, dataCopy);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
            MethodCall call = new MethodCall(nodeModified, new Object[]{fqn, pre, originLocal, modificationType, dataCopy});
            ctx.addCacheListenerEvent(call);
         }
  -   }
   
      /**
       * Notifies all registered listeners of a nodeRemoved event.
  @@ -230,107 +178,34 @@
       * @param pre
       * @param data
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeRemoved(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeRemoved(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx)
      {
  -      sendImmediately = false;
         boolean originLocal = ctx.isOriginLocal();
         Map dataCopy = copy(data);
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeRemoved(fqn, pre, originLocal, dataCopy);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeRemoved(fqn, pre, originLocal, dataCopy);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
            MethodCall call = new MethodCall(nodeRemoved, new Object[]{fqn, pre, originLocal, dataCopy});
            ctx.addCacheListenerEvent(call);
         }
   
  -   }
  -
      /**
       * Notifies all registered listeners of a nodeVisited event.
       *
       * @param fqn
       * @param pre
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeVisited(Fqn fqn, boolean pre, InvocationContext ctx, boolean sendImmediately)
  -   {
  -      sendImmediately = false;
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeVisited(fqn, pre);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeVisited(fqn, pre);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  +   public void notifyNodeVisited(Fqn fqn, boolean pre, InvocationContext ctx)
         {
            MethodCall call = new MethodCall(nodeVisited, new Object[]{fqn, pre});
            ctx.addCacheListenerEvent(call);
         }
   
  -   }
  -
  -   public void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre, InvocationContext ctx)
      {
  -      sendImmediately = false;
         boolean originLocal = ctx.isOriginLocal();
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeMoved(originalFqn, newFqn, pre, originLocal);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeMoved(originalFqn, newFqn, pre, originLocal);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
            MethodCall call = new MethodCall(nodeMoved, new Object[]{originalFqn, newFqn, pre, originLocal});
            ctx.addCacheListenerEvent(call);
         }
  -   }
   
   
      /**
  @@ -339,13 +214,11 @@
       * @param fqn
       * @param pre
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeEvicted(Fqn fqn, boolean pre, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeEvicted(Fqn fqn, boolean pre, InvocationContext ctx)
      {
         boolean originLocal = ctx.isOriginLocal();
  -      if (sendImmediately)
  -      {
  +      // always send eviction calls immediately - they do not go on the queue
            if (hasListenersOrEvictionListener)
            {
               InvocationContext backup = resetInvocationContext(ctx);
  @@ -363,12 +236,6 @@
               restoreInvocationContext(backup);
            }
         }
  -      else
  -      {
  -         MethodCall call = new MethodCall(nodeEvicted, new Object[]{fqn, pre, originLocal});
  -         ctx.addCacheListenerEvent(call);
  -      }
  -   }
   
      /**
       * Notifies all registered listeners of a nodeLoaded event.
  @@ -377,36 +244,13 @@
       * @param pre
       * @param data
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeLoaded(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeLoaded(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx)
      {
         Map<K, V> dataCopy = copy(data);
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeLoaded(fqn, pre, (Map<Object, Object>) dataCopy);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeLoaded(fqn, pre, (Map<Object, Object>) dataCopy);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
            MethodCall call = new MethodCall(nodeLoaded, new Object[]{fqn, pre, dataCopy});
            ctx.addCacheListenerEvent(call);
         }
  -   }
   
      /**
       * Notifies all registered listeners of a nodeActivated event.
  @@ -415,36 +259,13 @@
       * @param pre
       * @param data
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyNodeActivated(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx, boolean sendImmediately)
  +   public void notifyNodeActivated(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx)
      {
         Map<K, V> dataCopy = copy(data);
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodeActivated(fqn, pre, (Map<Object, Object>) dataCopy);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodeActivated(fqn, pre, (Map<Object, Object>) dataCopy);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
  -         MethodCall call = new MethodCall(nodeActivated, new Object[]{fqn, pre});
  +      MethodCall call = new MethodCall(nodeActivated, new Object[]{fqn, pre, dataCopy});
            ctx.addCacheListenerEvent(call);
         }
  -   }
   
      /**
       * Notifies all registered listeners of a nodePassivated event.
  @@ -458,42 +279,17 @@
      public void notifyNodePassivated(Fqn fqn, boolean pre, Map<K, V> data, InvocationContext ctx, boolean sendImmediately)
      {
         Map<K, V> dataCopy = copy(data);
  -      if (sendImmediately)
  -      {
  -         if (hasListenersOrEvictionListener)
  -         {
  -            InvocationContext backup = resetInvocationContext(ctx);
  -            if (evictionPolicyListener != null)
  -            {
  -               evictionPolicyListener.nodePassivated(fqn, pre, (Map<Object, Object>) dataCopy);
  -            }
  -            if (hasListeners)
  -            {
  -               for (CacheListener listener : listeners)
  -               {
  -                  listener.nodePassivated(fqn, pre, (Map<Object, Object>) dataCopy);
  -               }
  -            }
  -            restoreInvocationContext(backup);
  -         }
  -      }
  -      else
  -      {
  -         MethodCall call = new MethodCall(nodePassivated, new Object[]{fqn, pre});
  +      MethodCall call = new MethodCall(nodePassivated, new Object[]{fqn, pre, dataCopy});
            ctx.addCacheListenerEvent(call);
         }
  -   }
   
      /**
       * Notifies all registered listeners of a cacheStarted event.
       *
       * @param cache           cache instance to notify
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyCacheStarted(CacheSPI cache, InvocationContext ctx, boolean sendImmediately)
  -   {
  -      if (sendImmediately)
  +   public void notifyCacheStarted(CacheSPI cache, InvocationContext ctx)
         {
            if (hasListenersOrEvictionListener)
            {
  @@ -512,23 +308,14 @@
               restoreInvocationContext(backup);
            }
         }
  -      else
  -      {
  -         MethodCall call = new MethodCall(cacheStarted, new Object[]{cache});
  -         ctx.addCacheListenerEvent(call);
  -      }
  -   }
   
      /**
       * Notifies all registered listeners of a cacheStopped event.
       *
       * @param cache           cache instance to notify
       * @param ctx             context of invocation
  -    * @param sendImmediately whether notifications are deferred to the NotificationInterceptor (sendImmediately = false)
       */
  -   public void notifyCacheStopped(CacheSPI cache, InvocationContext ctx, boolean sendImmediately)
  -   {
  -      if (sendImmediately)
  +   public void notifyCacheStopped(CacheSPI cache, InvocationContext ctx)
         {
            if (hasListenersOrEvictionListener)
            {
  @@ -547,12 +334,6 @@
               restoreInvocationContext(backup);
            }
         }
  -      else
  -      {
  -         MethodCall call = new MethodCall(cacheStopped, new Object[]{cache});
  -         ctx.addCacheListenerEvent(call);
  -      }
  -   }
   
      /**
       * Notifies all registered listeners of a viewChange event.  Note that viewChange notifications are ALWAYS sent
  
  
  



More information about the jboss-cvs-commits mailing list