Search in sources :

Example 1 with QueueCommand

use of org.redisson.client.protocol.QueueCommand in project redisson by redisson.

the class CommandDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    QueueCommand data = ctx.channel().attr(CommandsQueue.CURRENT_COMMAND).get();
    if (log.isTraceEnabled()) {
        log.trace("channel: {} message: {}", ctx.channel(), in.toString(0, in.writerIndex(), CharsetUtil.UTF_8));
    }
    if (state() == null) {
        boolean makeCheckpoint = data != null;
        if (data != null) {
            if (data instanceof CommandsData) {
                makeCheckpoint = false;
            } else {
                CommandData<Object, Object> cmd = (CommandData<Object, Object>) data;
                if (cmd.getCommand().getReplayMultiDecoder() != null && (NestedMultiDecoder.class.isAssignableFrom(cmd.getCommand().getReplayMultiDecoder().getClass()) || SlotsDecoder.class.isAssignableFrom(cmd.getCommand().getReplayMultiDecoder().getClass()) || ListMultiDecoder.class.isAssignableFrom(cmd.getCommand().getReplayMultiDecoder().getClass()))) {
                    makeCheckpoint = false;
                }
            }
        }
        state(new State(makeCheckpoint));
    }
    state().setDecoderState(null);
    if (data == null) {
        decode(in, null, null, ctx.channel());
    } else if (data instanceof CommandData) {
        CommandData<Object, Object> cmd = (CommandData<Object, Object>) data;
        try {
            if (state().getLevels().size() > 0) {
                decodeFromCheckpoint(ctx, in, data, cmd);
            } else {
                decode(in, cmd, null, ctx.channel());
            }
        } catch (Exception e) {
            cmd.tryFailure(e);
        }
    } else if (data instanceof CommandsData) {
        CommandsData commands = (CommandsData) data;
        try {
            decodeCommandBatch(ctx, in, data, commands);
        } catch (Exception e) {
            commands.getPromise().tryFailure(e);
        }
        return;
    }
    ctx.pipeline().get(CommandsQueue.class).sendNextCommand(ctx.channel());
    state(null);
}
Also used : QueueCommand(org.redisson.client.protocol.QueueCommand) ListMultiDecoder(org.redisson.client.protocol.decoder.ListMultiDecoder) CommandsData(org.redisson.client.protocol.CommandsData) CommandData(org.redisson.client.protocol.CommandData) RedisException(org.redisson.client.RedisException) RedisMovedException(org.redisson.client.RedisMovedException) RedisAskException(org.redisson.client.RedisAskException) RedisOutOfMemoryException(org.redisson.client.RedisOutOfMemoryException) RedisLoadingException(org.redisson.client.RedisLoadingException) RedisTryAgainException(org.redisson.client.RedisTryAgainException) IOException(java.io.IOException) RedisTimeoutException(org.redisson.client.RedisTimeoutException)

Example 2 with QueueCommand

use of org.redisson.client.protocol.QueueCommand in project redisson by redisson.

the class CommandsQueue method write.

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof QueueCommand) {
        QueueCommand data = (QueueCommand) msg;
        QueueCommandHolder holder = queue.peek();
        if (holder != null && holder.getCommand() == data) {
            super.write(ctx, msg, promise);
        } else {
            queue.add(new QueueCommandHolder(data, promise));
            sendData(ctx.channel());
        }
    } else {
        super.write(ctx, msg, promise);
    }
}
Also used : QueueCommandHolder(org.redisson.client.protocol.QueueCommandHolder) QueueCommand(org.redisson.client.protocol.QueueCommand)

Example 3 with QueueCommand

use of org.redisson.client.protocol.QueueCommand in project redisson by redisson.

the class CommandsQueue method sendData.

private void sendData(Channel ch) {
    QueueCommandHolder command = queue.peek();
    if (command != null && command.trySend()) {
        QueueCommand data = command.getCommand();
        List<CommandData<Object, Object>> pubSubOps = data.getPubSubOperations();
        if (!pubSubOps.isEmpty()) {
            for (CommandData<Object, Object> cd : pubSubOps) {
                for (Object channel : cd.getParams()) {
                    ch.pipeline().get(CommandDecoder.class).addPubSubCommand(channel.toString(), cd);
                }
            }
        } else {
            ch.attr(CURRENT_COMMAND).set(data);
        }
        command.getChannelPromise().addListener(listener);
        ch.writeAndFlush(data, command.getChannelPromise());
    }
}
Also used : QueueCommandHolder(org.redisson.client.protocol.QueueCommandHolder) QueueCommand(org.redisson.client.protocol.QueueCommand) CommandData(org.redisson.client.protocol.CommandData)

Aggregations

QueueCommand (org.redisson.client.protocol.QueueCommand)3 CommandData (org.redisson.client.protocol.CommandData)2 QueueCommandHolder (org.redisson.client.protocol.QueueCommandHolder)2 IOException (java.io.IOException)1 RedisAskException (org.redisson.client.RedisAskException)1 RedisException (org.redisson.client.RedisException)1 RedisLoadingException (org.redisson.client.RedisLoadingException)1 RedisMovedException (org.redisson.client.RedisMovedException)1 RedisOutOfMemoryException (org.redisson.client.RedisOutOfMemoryException)1 RedisTimeoutException (org.redisson.client.RedisTimeoutException)1 RedisTryAgainException (org.redisson.client.RedisTryAgainException)1 CommandsData (org.redisson.client.protocol.CommandsData)1 ListMultiDecoder (org.redisson.client.protocol.decoder.ListMultiDecoder)1