[infinispan-commits] Infinispan SVN: r1139 - in trunk/core/src: main/java/org/infinispan/notifications/cachelistener and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Nov 11 13:27:38 EST 2009


Author: galder.zamarreno at jboss.com
Date: 2009-11-11 13:27:37 -0500 (Wed, 11 Nov 2009)
New Revision: 1139

Added:
   trunk/core/src/test/java/org/infinispan/context/
   trunk/core/src/test/java/org/infinispan/context/InvocationContextResumeTest.java
Modified:
   trunk/core/src/main/java/org/infinispan/context/InvocationContextContainerImpl.java
   trunk/core/src/main/java/org/infinispan/notifications/cachelistener/CacheNotifierImpl.java
Log:
[ISPN-269] (When runtime exceptions are thrown from listener event implementations invocation ctx is not resumed) Fixed by moving icc.resume() calls to a finally section. Removed some unused imports in ctx container.

Modified: trunk/core/src/main/java/org/infinispan/context/InvocationContextContainerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/context/InvocationContextContainerImpl.java	2009-11-11 17:51:05 UTC (rev 1138)
+++ trunk/core/src/main/java/org/infinispan/context/InvocationContextContainerImpl.java	2009-11-11 18:27:37 UTC (rev 1139)
@@ -26,17 +26,13 @@
 import org.infinispan.context.impl.NonTxInvocationContext;
 import org.infinispan.context.impl.RemoteTxInvocationContext;
 import org.infinispan.factories.annotations.Inject;
-import org.infinispan.transaction.xa.GlobalTransaction;
 import org.infinispan.transaction.xa.TransactionTable;
 import org.infinispan.transaction.xa.TransactionXaAdapter;
 
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
-
 /**
  * Default implementation for {@link org.infinispan.context.InvocationContextContainer}.
  *

Modified: trunk/core/src/main/java/org/infinispan/notifications/cachelistener/CacheNotifierImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/notifications/cachelistener/CacheNotifierImpl.java	2009-11-11 17:51:05 UTC (rev 1138)
+++ trunk/core/src/main/java/org/infinispan/notifications/cachelistener/CacheNotifierImpl.java	2009-11-11 18:27:37 UTC (rev 1139)
@@ -115,15 +115,18 @@
       if (!cacheEntryCreatedListeners.isEmpty()) {
          boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_CREATED);
-         for (ListenerInvocation listener : cacheEntryCreatedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_CREATED);
+            for (ListenerInvocation listener : cacheEntryCreatedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -131,16 +134,19 @@
       if (!cacheEntryModifiedListeners.isEmpty()) {
          boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setValue(value);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_MODIFIED);
-         for (ListenerInvocation listener : cacheEntryModifiedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setValue(value);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_MODIFIED);
+            for (ListenerInvocation listener : cacheEntryModifiedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -148,30 +154,36 @@
       if (!cacheEntryRemovedListeners.isEmpty()) {
          boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setValue(value);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_REMOVED);
-         for (ListenerInvocation listener : cacheEntryRemovedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setValue(value);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_REMOVED);
+            for (ListenerInvocation listener : cacheEntryRemovedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
    public void notifyCacheEntryVisited(Object key, boolean pre, InvocationContext ctx) {
       if (!cacheEntryVisitedListeners.isEmpty()) {
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_VISITED);
-         for (ListenerInvocation listener : cacheEntryVisitedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_VISITED);
+            for (ListenerInvocation listener : cacheEntryVisitedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -179,15 +191,18 @@
       if (!cacheEntryEvictedListeners.isEmpty()) {
          final boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_EVICTED);
-         for (ListenerInvocation listener : cacheEntryEvictedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_EVICTED);
+            for (ListenerInvocation listener : cacheEntryEvictedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -195,15 +210,18 @@
       if (!cacheEntryInvalidatedListeners.isEmpty()) {
          final boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_INVALIDATED);
-         for (ListenerInvocation listener : cacheEntryInvalidatedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_INVALIDATED);
+            for (ListenerInvocation listener : cacheEntryInvalidatedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -211,15 +229,18 @@
       if (!cacheEntryLoadedListeners.isEmpty()) {
          boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_LOADED);
-         for (ListenerInvocation listener : cacheEntryLoadedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_LOADED);
+            for (ListenerInvocation listener : cacheEntryLoadedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -227,15 +248,18 @@
       if (!cacheEntryActivatedListeners.isEmpty()) {
          boolean originLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(originLocal);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_ACTIVATED);
-         for (ListenerInvocation listener : cacheEntryActivatedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(originLocal);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_ACTIVATED);
+            for (ListenerInvocation listener : cacheEntryActivatedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -249,14 +273,17 @@
    public void notifyCacheEntryPassivated(Object key, boolean pre, InvocationContext ctx) {
       if (!cacheEntryPassivatedListeners.isEmpty()) {
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setPre(pre);
-         e.setKey(key);
-         setTx(ctx, e);
-         e.setType(CACHE_ENTRY_PASSIVATED);
-         for (ListenerInvocation listener : cacheEntryPassivatedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setPre(pre);
+            e.setKey(key);
+            setTx(ctx, e);
+            e.setType(CACHE_ENTRY_PASSIVATED);
+            for (ListenerInvocation listener : cacheEntryPassivatedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -264,14 +291,17 @@
       if (!transactionCompletedListeners.isEmpty()) {
          boolean isOriginLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(isOriginLocal);
-         e.setTransactionId(transaction);
-         e.setTransactionSuccessful(successful);
-         e.setType(TRANSACTION_COMPLETED);
-         for (ListenerInvocation listener : transactionCompletedListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(isOriginLocal);
+            e.setTransactionId(transaction);
+            e.setTransactionSuccessful(successful);
+            e.setType(TRANSACTION_COMPLETED);
+            for (ListenerInvocation listener : transactionCompletedListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 
@@ -279,13 +309,16 @@
       if (!transactionRegisteredListeners.isEmpty()) {
          boolean isOriginLocal = ctx.isOriginLocal();
          InvocationContext contexts = icc.suspend();
-         EventImpl e = new EventImpl();
-         e.setCache(cache);
-         e.setOriginLocal(isOriginLocal);
-         e.setTransactionId(globalTransaction);
-         e.setType(TRANSACTION_REGISTERED);
-         for (ListenerInvocation listener : transactionRegisteredListeners) listener.invoke(e);
-         icc.resume(contexts);
+         try {
+            EventImpl e = new EventImpl();
+            e.setCache(cache);
+            e.setOriginLocal(isOriginLocal);
+            e.setTransactionId(globalTransaction);
+            e.setType(TRANSACTION_REGISTERED);
+            for (ListenerInvocation listener : transactionRegisteredListeners) listener.invoke(e);
+         } finally {
+            icc.resume(contexts);
+         }
       }
    }
 }

Added: trunk/core/src/test/java/org/infinispan/context/InvocationContextResumeTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/context/InvocationContextResumeTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/context/InvocationContextResumeTest.java	2009-11-11 18:27:37 UTC (rev 1139)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.context;
+
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.config.Configuration;
+import org.infinispan.context.Flag;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
+import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
+import org.infinispan.test.MultipleCacheManagersTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.Test;
+
+ at Test(groups = {"functional"}, testName = "marshall.InvocationContextInterceptorErrorTest")
+public class InvocationContextResumeTest extends MultipleCacheManagersTest {
+   private static final Log log = LogFactory.getLog(InvocationContextResumeTest.class);
+
+   @Override
+   protected void createCacheManagers() throws Throwable {
+      Configuration cfg = TestCacheManagerFactory.getDefaultConfiguration(true);
+      cfg.setSyncCommitPhase(true);
+      cfg.setSyncRollbackPhase(true);
+      createClusteredCaches(1, "timestamps", cfg);
+   }
+
+   public void testMishavingListenerResumesContext() {
+      Cache cache = cache(0, "timestamps");
+      cache.addListener(new CacheListener());
+      try {
+         cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).put("k", "v");
+      } catch (CacheException ce) {
+         assert ce.getCause() instanceof NullPointerException;
+      }
+   }
+
+   @Listener
+   public static class CacheListener {
+      @CacheEntryModified
+      public void entryModified(CacheEntryModifiedEvent event) {
+         if (!event.isPre()) {
+            log.debug("Entry modified: {0}, let's throw an NPE!!", event);
+            throw new NullPointerException();
+         }
+      }
+   }
+}



More information about the infinispan-commits mailing list