All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.interceptors.impl.NotificationInterceptor Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.interceptors.impl;

import org.infinispan.commands.VisitableCommand;
import org.infinispan.commands.tx.CommitCommand;
import org.infinispan.commands.tx.PrepareCommand;
import org.infinispan.commands.tx.RollbackCommand;
import org.infinispan.context.InvocationContext;
import org.infinispan.context.impl.TxInvocationContext;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.interceptors.DDAsyncInterceptor;
import org.infinispan.interceptors.InvocationSuccessAction;
import org.infinispan.notifications.cachelistener.CacheNotifier;

/**
 * The interceptor in charge of firing off notifications to cache listeners
 *
 * @author Manik Surtani
 * @since 9.0
 */
public class NotificationInterceptor extends DDAsyncInterceptor {
   private CacheNotifier notifier;
   private final InvocationSuccessAction commitSuccessAction = new InvocationSuccessAction() {
      @Override
      public void accept(InvocationContext rCtx, VisitableCommand rCommand, Object rv)
            throws Throwable {
         notifier.notifyTransactionCompleted(((TxInvocationContext) rCtx).getGlobalTransaction(), true, rCtx);
      }
   };
   private final InvocationSuccessAction rollbackSuccessAction = new InvocationSuccessAction() {
      @Override
      public void accept(InvocationContext rCtx, VisitableCommand rCommand, Object rv)
            throws Throwable {
         notifier.notifyTransactionCompleted(((TxInvocationContext) rCtx).getGlobalTransaction(), false, rCtx);
      }
   };

   @Inject
   public void injectDependencies(CacheNotifier notifier) {
      this.notifier = notifier;
   }

   @Override
   public Object visitPrepareCommand(TxInvocationContext ctx, PrepareCommand command) throws Throwable {
      if (!command.isOnePhaseCommit()) return invokeNext(ctx, command);

      return invokeNextThenAccept(ctx, command, commitSuccessAction);
   }

   @Override
   public Object visitCommitCommand(TxInvocationContext ctx, CommitCommand command) throws Throwable {
      return invokeNextThenAccept(ctx, command, commitSuccessAction);
   }

   @Override
   public Object visitRollbackCommand(TxInvocationContext ctx, RollbackCommand command) throws Throwable {
      return invokeNextThenAccept(ctx, command, rollbackSuccessAction);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy