use of org.springframework.data.redis.connection.SubscriptionListener in project redisson by redisson.
the class RedissonReactiveSubscription method pSubscribe.
@Override
public Mono<Void> pSubscribe(ByteBuffer... patterns) {
monosListener.acquire();
return Mono.defer(() -> {
List<CompletableFuture<?>> futures = new ArrayList<>();
for (ByteBuffer channel : patterns) {
ChannelName cn = toChannelName(channel);
CompletableFuture<Collection<PubSubConnectionEntry>> f = subscribeService.psubscribe(cn, ByteArrayCodec.INSTANCE, subscriptionListener);
f = f.whenComplete((res, e) -> RedissonReactiveSubscription.this.patterns.put(cn, res));
futures.add(f);
}
CompletableFuture<Void> future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
future = future.whenComplete((r, e) -> {
monosListener.release();
});
return Mono.fromFuture(future);
});
}
use of org.springframework.data.redis.connection.SubscriptionListener in project redisson by redisson.
the class RedissonReactiveSubscription method subscribe.
@Override
public Mono<Void> subscribe(ByteBuffer... channels) {
monosListener.acquire();
return Mono.defer(() -> {
List<CompletableFuture<?>> futures = new ArrayList<>();
for (ByteBuffer channel : channels) {
ChannelName cn = toChannelName(channel);
CompletableFuture<PubSubConnectionEntry> f = subscribeService.subscribe(ByteArrayCodec.INSTANCE, cn, subscriptionListener);
f = f.whenComplete((res, e) -> RedissonReactiveSubscription.this.channels.put(cn, res));
futures.add(f);
}
CompletableFuture<Void> future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
future = future.whenComplete((r, e) -> {
monosListener.release();
});
return Mono.fromFuture(future);
});
}
Aggregations