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

org.infinispan.server.resp.commands.tx.UNWATCH Maven / Gradle / Ivy

The newest version!
package org.infinispan.server.resp.commands.tx;

import static org.infinispan.server.resp.commands.tx.WATCH.WATCHER_KEY;

import java.util.List;
import java.util.concurrent.CompletionStage;

import org.infinispan.AdvancedCache;
import org.infinispan.commons.util.concurrent.CompletableFutures;
import org.infinispan.server.resp.Consumers;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.Resp3Command;
import org.infinispan.commons.util.concurrent.AggregateCompletionStage;
import org.infinispan.commons.util.concurrent.CompletionStages;

import io.netty.channel.ChannelHandlerContext;

/**
 * `UNWATCH` command.
 * 

* Removes all the registered watchers in the current {@link ChannelHandlerContext}. * * @since 15.0 * @see Redis documentation. * @author José Bolina */ public class UNWATCH extends RespCommand implements Resp3Command { public UNWATCH() { super(1, 0, 0, 0); } @Override public CompletionStage perform(Resp3Handler handler, ChannelHandlerContext ctx, List arguments) { CompletionStage cs = deregister(ctx, handler.cache()); return handler.stageToReturn(cs, ctx, Consumers.OK_BICONSUMER); } public static CompletionStage> deregister(ChannelHandlerContext ctx, AdvancedCache cache) { List watchers = ctx.channel().attr(WATCHER_KEY).getAndSet(null); if (watchers == null) { return CompletableFutures.completedNull(); } AggregateCompletionStage stage = CompletionStages.aggregateCompletionStage(); for (WATCH.TxKeysListener watcher : watchers) { stage.dependsOn(cache.removeListenerAsync(watcher)); } return stage.freeze().thenApply(ignore -> watchers); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy