1 package org.jboss.cache.interceptors; 2 3 import org.jboss.cache.InvocationContext; 4 import org.jboss.cache.TransactionEntry; 5 import org.jboss.cache.marshall.MethodCall; 6 import org.jboss.cache.marshall.MethodDeclarations; 7 import org.jboss.cache.notifications.Notifier; 8 9 import java.util.List ; 10 11 17 public class NotificationInterceptor extends BaseTransactionalContextInterceptor 18 { 19 public Object invoke(MethodCall call) throws Throwable 20 { 21 Object retval = super.invoke(call); 23 24 InvocationContext ctx = cache.getInvocationContext(); 25 Notifier n = cache.getNotifier(); 26 if (ctx.getGlobalTransaction() != null) 28 { 29 if (MethodDeclarations.isTransactionLifecycleMethod(call.getMethodId())) 30 { 31 if (call.getMethodId() == MethodDeclarations.commitMethod_id) 33 { 34 List <MethodCall> events = ctx.getCacheListenerEvents(); 36 TransactionEntry entry = txTable.get(ctx.getGlobalTransaction()); 37 if (entry != null) 38 { 39 entry.addCacheListenerEvents(events); 40 41 if (log.isTraceEnabled()) 42 log.trace("Invoking notifications for this transaction. Notification set: " + entry.getCacheListenerEvents()); 43 n.invokeQueuedNotifications(entry.getCacheListenerEvents()); 44 } 45 else 46 { 47 log.trace("Committing but cache entry is null."); 48 } 49 } 50 } 51 else 52 { 53 List <MethodCall> events = ctx.getCacheListenerEvents(); 55 TransactionEntry entry = txTable.get(ctx.getGlobalTransaction()); 56 if (log.isTraceEnabled()) log.trace("Adding " + events + " to transaction entry's notification list"); 57 entry.addCacheListenerEvents(events); 58 ctx.clearCacheListenerEvents(); 59 } 60 } 61 else 62 { 63 n.invokeQueuedNotifications(); 65 } 66 67 return retval; 68 } 69 } 70 | Popular Tags |