Search in sources :

Example 11 with ChannelName

use of org.redisson.client.ChannelName in project redisson by redisson.

the class RedissonReactiveSubscription method pUnsubscribe.

@Override
public Mono<Void> pUnsubscribe(ByteBuffer... patterns) {
    monosListener.acquire();
    return Mono.defer(() -> {
        List<CompletableFuture<?>> futures = new ArrayList<>(patterns.length);
        for (ByteBuffer channel : patterns) {
            ChannelName cn = toChannelName(channel);
            CompletableFuture<Codec> f = subscribeService.unsubscribe(cn, PubSubType.PUNSUBSCRIBE);
            f = f.whenComplete((res, e) -> {
                synchronized (RedissonReactiveSubscription.this.patterns) {
                    Collection<PubSubConnectionEntry> entries = RedissonReactiveSubscription.this.patterns.get(cn);
                    entries.stream().filter(en -> en.hasListeners(cn)).forEach(ee -> RedissonReactiveSubscription.this.patterns.remove(cn));
                }
            });
            futures.add(f);
        }
        CompletableFuture<Void> future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
        future = future.whenComplete((r, e) -> {
            monosListener.release();
        });
        return Mono.fromFuture(future);
    });
}
Also used : PubSubType(org.redisson.client.protocol.pubsub.PubSubType) PublishSubscribeService(org.redisson.pubsub.PublishSubscribeService) java.util(java.util) Disposable(reactor.core.Disposable) Codec(org.redisson.client.codec.Codec) PubSubConnectionEntry(org.redisson.pubsub.PubSubConnectionEntry) ConnectionManager(org.redisson.connection.ConnectionManager) ByteArrayCodec(org.redisson.client.codec.ByteArrayCodec) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Mono(reactor.core.publisher.Mono) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) StandardCharsets(java.nio.charset.StandardCharsets) RedisPubSubListener(org.redisson.client.RedisPubSubListener) SubscriptionListener(org.springframework.data.redis.connection.SubscriptionListener) BaseRedisPubSubListener(org.redisson.client.BaseRedisPubSubListener) Flux(reactor.core.publisher.Flux) ReactiveSubscription(org.springframework.data.redis.connection.ReactiveSubscription) Entry(java.util.Map.Entry) ChannelName(org.redisson.client.ChannelName) CompletableFuture(java.util.concurrent.CompletableFuture) Codec(org.redisson.client.codec.Codec) ByteArrayCodec(org.redisson.client.codec.ByteArrayCodec) ChannelName(org.redisson.client.ChannelName) ByteBuffer(java.nio.ByteBuffer)

Example 12 with ChannelName

use of org.redisson.client.ChannelName in project redisson by redisson.

the class CommandPubSubDecoder method messageDecoder.

@Override
protected MultiDecoder<Object> messageDecoder(CommandData<Object, Object> data, List<Object> parts) {
    if (parts.isEmpty() || parts.get(0) == null) {
        return null;
    }
    String command = parts.get(0).toString();
    if (MESSAGES.contains(command)) {
        ChannelName channelName = new ChannelName((byte[]) parts.get(1));
        PubSubKey key = new PubSubKey(channelName, command);
        CommandData<Object, Object> commandData = commands.get(key);
        if (commandData == null) {
            return null;
        }
        return commandData.getCommand().getReplayMultiDecoder();
    } else if ("message".equals(command)) {
        byte[] channelName = (byte[]) parts.get(1);
        PubSubEntry entry = entries.get(new ChannelName(channelName));
        if (entry == null) {
            return null;
        }
        return entry.getDecoder();
    } else if ("pmessage".equals(command)) {
        byte[] patternName = (byte[]) parts.get(1);
        PubSubEntry entry = entries.get(new ChannelName(patternName));
        if (entry == null) {
            return null;
        }
        return entry.getDecoder();
    } else if ("pong".equals(command)) {
        return new ListObjectDecoder<>(0);
    }
    return data.getCommand().getReplayMultiDecoder();
}
Also used : ChannelName(org.redisson.client.ChannelName)

Example 13 with ChannelName

use of org.redisson.client.ChannelName in project redisson by redisson.

the class PubSubPatternMessageDecoder method decode.

@Override
public PubSubPatternMessage decode(List<Object> parts, State state) {
    ChannelName patternName = new ChannelName((byte[]) parts.get(1));
    ChannelName name = new ChannelName((byte[]) parts.get(2));
    return new PubSubPatternMessage(patternName, name, parts.get(3));
}
Also used : ChannelName(org.redisson.client.ChannelName)

Example 14 with ChannelName

use of org.redisson.client.ChannelName in project redisson by redisson.

the class PubSubStatusDecoder method decode.

@Override
public PubSubStatusMessage decode(List<Object> parts, State state) {
    PubSubType type = PubSubType.valueOf(parts.get(0).toString().toUpperCase());
    ChannelName name = new ChannelName((byte[]) parts.get(1));
    return new PubSubStatusMessage(type, name);
}
Also used : ChannelName(org.redisson.client.ChannelName)

Aggregations

ChannelName (org.redisson.client.ChannelName)14 CompletableFuture (java.util.concurrent.CompletableFuture)7 BaseRedisPubSubListener (org.redisson.client.BaseRedisPubSubListener)7 PubSubConnectionEntry (org.redisson.pubsub.PubSubConnectionEntry)6 ByteBuffer (java.nio.ByteBuffer)4 StandardCharsets (java.nio.charset.StandardCharsets)4 java.util (java.util)4 Entry (java.util.Map.Entry)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Collectors (java.util.stream.Collectors)4 RedisPubSubListener (org.redisson.client.RedisPubSubListener)4 ByteArrayCodec (org.redisson.client.codec.ByteArrayCodec)4 Codec (org.redisson.client.codec.Codec)4 PubSubType (org.redisson.client.protocol.pubsub.PubSubType)4 ConnectionManager (org.redisson.connection.ConnectionManager)4 PublishSubscribeService (org.redisson.pubsub.PublishSubscribeService)4 ReactiveSubscription (org.springframework.data.redis.connection.ReactiveSubscription)4 SubscriptionListener (org.springframework.data.redis.connection.SubscriptionListener)4 Disposable (reactor.core.Disposable)4