Search in sources :

Example 6 with QueueCommandHolder

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

the class CommandsQueuePubSub 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(CommandPubSubDecoder.class).addPubSubCommand((ChannelName) channel, 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)

Example 7 with QueueCommandHolder

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

the class CommandsQueuePubSub method sendNextCommand.

public void sendNextCommand(Channel channel) {
    QueueCommand command = channel.attr(CommandsQueuePubSub.CURRENT_COMMAND).getAndSet(null);
    if (command != null) {
        queue.poll();
    } else {
        QueueCommandHolder c = queue.peek();
        if (c != null) {
            QueueCommand data = c.getCommand();
            List<CommandData<Object, Object>> pubSubOps = data.getPubSubOperations();
            if (!pubSubOps.isEmpty()) {
                queue.poll();
            }
        }
    }
    sendData(channel);
}
Also used : QueueCommandHolder(org.redisson.client.protocol.QueueCommandHolder) QueueCommand(org.redisson.client.protocol.QueueCommand) CommandData(org.redisson.client.protocol.CommandData)

Aggregations

QueueCommandHolder (org.redisson.client.protocol.QueueCommandHolder)7 QueueCommand (org.redisson.client.protocol.QueueCommand)5 CommandData (org.redisson.client.protocol.CommandData)3 WriteRedisConnectionException (org.redisson.client.WriteRedisConnectionException)2