[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Wed Jan 3 12:11:58 EST 2007
User: msurtani
Date: 07/01/03 12:11:58
Added: src/org/jboss/cache/interceptors
NotificationInterceptor.java
Log:
notification interceptor
Revision Changes Path
1.1 date: 2007/01/03 17:11:58; author: msurtani; state: Exp;JBossCache/src/org/jboss/cache/interceptors/NotificationInterceptor.java
Index: NotificationInterceptor.java
===================================================================
package org.jboss.cache.interceptors;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.TransactionEntry;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.notifications.Notifier;
import java.util.List;
/**
* The interceptor in charge of firing off notifications to cache listeners
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class NotificationInterceptor extends BaseTransactionalContextInterceptor
{
public Object invoke(MethodCall call) throws Throwable
{
// should only kick in as a call returns.
Object retval = super.invoke(call);
InvocationContext ctx = cache.getInvocationContext();
Notifier n = cache.getNotifier();
// now, if we are in a transactional context, copy all local-context invocations to the transaction entry.
if (ctx.getGlobalTransaction() != null)
{
if (MethodDeclarations.isTransactionLifecycleMethod(call.getMethodId()))
{
// only invoke on commit.
if (call.getMethodId() == MethodDeclarations.commitMethod_id)
{
// invoke notifications
List<MethodCall> events = ctx.getCacheListenerEvents();
TransactionEntry entry = txTable.get(ctx.getGlobalTransaction());
entry.addCacheListenerEvents(events);
n.invokeQueuedNotifications(entry.getCacheListenerEvents());
}
}
else
{
// a "normal" method in the transaction. Add notifications to transaction entry.
List<MethodCall> events = ctx.getCacheListenerEvents();
TransactionEntry entry = txTable.get(ctx.getGlobalTransaction());
entry.addCacheListenerEvents(events);
ctx.clearCacheListenerEvents();
}
}
else
{
// fire all queued up notifications now.
n.invokeQueuedNotifications();
}
return retval;
}
}
More information about the jboss-cvs-commits
mailing list