![JAR search and dependency download from the Maven repository](/logo.png)
org.infinispan.server.resp.commands.pubsub.CHANNELS Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infinispan-server-resp Show documentation
Show all versions of infinispan-server-resp Show documentation
Infinispan Resp Protocol Server
package org.infinispan.server.resp.commands.pubsub;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletionStage;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.infinispan.commons.util.GlobMatcher;
import org.infinispan.notifications.cachelistener.CacheNotifier;
import org.infinispan.security.actions.SecurityActions;
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.server.resp.serialization.Resp3Response;
import org.infinispan.server.resp.serialization.Resp3Type;
import io.netty.channel.ChannelHandlerContext;
/**
* `PUBSUB CHANNELS [pattern]
` command.
*
* List the existing subscribers matching the optional glob pattern. If no pattern is specified, all channels are listed.
* The reply in a clustered environment is local to the node handling the command.
*
*
* @since 15.0
* @see Redis documentation.
* @author José Bolina
*/
class CHANNELS extends RespCommand implements Resp3Command {
private static final Predicate PASS_ALL = ignore -> true;
CHANNELS() {
super(-2, 0, 0, 0);
}
@Override
public CompletionStage perform(Resp3Handler handler, ChannelHandlerContext ctx, List arguments) {
CacheNotifier, ?> cn = SecurityActions.getCacheComponentRegistry(handler.cache()).getCacheNotifier().running();
Predicate filter = PASS_ALL;
if (arguments.size() == 2) {
filter = globFilter(arguments.get(1));
}
// Retrieve all existing cache listeners for this node.
// We must return the active channels. One channel can have multiple listeners from different clients.
// We filter out the listeners by comparing the channel bytes.
Collection channels = cn.getListeners().stream()
.filter(l -> l instanceof RespCacheListener)
.map(l -> (RespCacheListener) l)
.map(RespCacheListener::subscribedChannel)
.filter(Objects::nonNull)
.filter(filter)
.collect(Collectors.filtering(PUBSUB.deduplicate(), Collectors.toList()));
Resp3Response.array(channels, handler.allocator(), Resp3Type.BULK_STRING);
return handler.myStage();
}
private Predicate globFilter(byte[] glob) {
return channel -> GlobMatcher.match(glob, channel);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy