use of org.redisson.PubSubPatternStatusListener in project redisson by redisson.
the class PublishSubscribeService method psubscribe.
public CompletableFuture<Collection<PubSubConnectionEntry>> psubscribe(ChannelName channelName, Codec codec, RedisPubSubListener<?>... listeners) {
if (isMultiEntity(channelName)) {
Collection<MasterSlaveEntry> entrySet = connectionManager.getEntrySet();
AtomicInteger statusCounter = new AtomicInteger(entrySet.size());
RedisPubSubListener[] ls = Arrays.stream(listeners).map(l -> {
if (l instanceof PubSubPatternStatusListener) {
return new PubSubPatternStatusListener((PubSubPatternStatusListener) l) {
@Override
public boolean onStatus(PubSubType type, CharSequence channel) {
if (statusCounter.decrementAndGet() == 0) {
return super.onStatus(type, channel);
}
return true;
}
};
}
return l;
}).toArray(RedisPubSubListener[]::new);
List<CompletableFuture<PubSubConnectionEntry>> futures = new ArrayList<>();
for (MasterSlaveEntry entry : entrySet) {
CompletableFuture<PubSubConnectionEntry> future = subscribe(PubSubType.PSUBSCRIBE, codec, channelName, entry, ls);
futures.add(future);
}
CompletableFuture<Void> future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
return future.thenApply(r -> {
return futures.stream().map(v -> v.getNow(null)).collect(Collectors.toList());
});
}
CompletableFuture<PubSubConnectionEntry> f = subscribe(PubSubType.PSUBSCRIBE, codec, channelName, getEntry(channelName), listeners);
return f.thenApply(res -> Collections.singletonList(res));
}
use of org.redisson.PubSubPatternStatusListener in project redisson by redisson.
the class RedissonPatternTopicReactive method addListener.
@Override
public Publisher<Integer> addListener(PatternStatusListener listener) {
RPromise<Integer> promise = commandExecutor.getConnectionManager().newPromise();
addListener(new PubSubPatternStatusListener(listener, name), promise);
return new NettyFuturePublisher<Integer>(promise);
}
Aggregations