|
|
|
@ -18,6 +18,7 @@ package org.redisson.client.handler;
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
|
import org.redisson.client.ChannelName;
|
|
|
|
|
import org.redisson.client.RedisClientConfig;
|
|
|
|
|
import org.redisson.client.RedisPubSubConnection;
|
|
|
|
|
import org.redisson.client.codec.ByteArrayCodec;
|
|
|
|
|
import org.redisson.client.codec.StringCodec;
|
|
|
|
@ -51,11 +52,11 @@ public class CommandPubSubDecoder extends CommandDecoder {
|
|
|
|
|
private final Map<ChannelName, PubSubEntry> entries = new HashMap<>();
|
|
|
|
|
private final Map<PubSubKey, CommandData<Object, Object>> commands = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
private final boolean keepOrder;
|
|
|
|
|
|
|
|
|
|
public CommandPubSubDecoder(ExecutorService executor, boolean keepOrder) {
|
|
|
|
|
super(executor);
|
|
|
|
|
this.keepOrder = keepOrder;
|
|
|
|
|
private final RedisClientConfig config;
|
|
|
|
|
|
|
|
|
|
public CommandPubSubDecoder(RedisClientConfig config) {
|
|
|
|
|
super(config.getAddress().getScheme());
|
|
|
|
|
this.config = config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addPubSubCommand(ChannelName channel, CommandData<Object, Object> data) {
|
|
|
|
@ -96,7 +97,7 @@ public class CommandPubSubDecoder extends CommandDecoder {
|
|
|
|
|
protected void decodeResult(CommandData<Object, Object> data, List<Object> parts, Channel channel,
|
|
|
|
|
Object result) throws IOException {
|
|
|
|
|
try {
|
|
|
|
|
if (executor.isShutdown()) {
|
|
|
|
|
if (config.getExecutor().isShutdown()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
@ -123,14 +124,14 @@ public class CommandPubSubDecoder extends CommandDecoder {
|
|
|
|
|
channelName = ((PubSubPatternMessage) result).getPattern();
|
|
|
|
|
}
|
|
|
|
|
PubSubEntry entry = entries.remove(channelName);
|
|
|
|
|
if (keepOrder) {
|
|
|
|
|
if (config.isKeepAlive()) {
|
|
|
|
|
enqueueMessage(result, pubSubConnection, entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (keepOrder) {
|
|
|
|
|
if (config.isKeepAlive()) {
|
|
|
|
|
if (result instanceof PubSubPatternMessage) {
|
|
|
|
|
channelName = ((PubSubPatternMessage) result).getPattern();
|
|
|
|
|
}
|
|
|
|
@ -139,7 +140,7 @@ public class CommandPubSubDecoder extends CommandDecoder {
|
|
|
|
|
enqueueMessage(result, pubSubConnection, entry);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
executor.execute(new Runnable() {
|
|
|
|
|
config.getExecutor().execute(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (result instanceof PubSubStatusMessage) {
|
|
|
|
@ -168,7 +169,7 @@ public class CommandPubSubDecoder extends CommandDecoder {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
executor.execute(() -> {
|
|
|
|
|
config.getExecutor().execute(() -> {
|
|
|
|
|
try {
|
|
|
|
|
while (true) {
|
|
|
|
|
Message result = entry.getQueue().poll();
|
|
|
|
|