use of org.redisson.client.protocol.QueueCommandHolder 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());
}
}
use of org.redisson.client.protocol.QueueCommandHolder 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 = new QueueCommandHolder(data, promise);
Queue<QueueCommandHolder> queue = ctx.channel().attr(COMMANDS_QUEUE).get();
while (true) {
if (lock.compareAndSet(false, true)) {
try {
queue.add(holder);
ctx.writeAndFlush(data, holder.getChannelPromise());
} finally {
lock.set(false);
}
break;
}
}
} else {
super.write(ctx, msg, promise);
}
}
use of org.redisson.client.protocol.QueueCommandHolder in project redisson by redisson.
the class CommandsQueue method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
Queue<QueueCommandHolder> queue = ctx.channel().attr(COMMANDS_QUEUE).get();
Iterator<QueueCommandHolder> iterator = queue.iterator();
while (iterator.hasNext()) {
QueueCommandHolder command = iterator.next();
if (command.getCommand().isBlockingCommand()) {
continue;
}
iterator.remove();
command.getChannelPromise().tryFailure(new WriteRedisConnectionException("Channel has been closed! Can't write command: " + LogHelper.toString(command.getCommand()) + " to channel: " + ctx.channel()));
}
super.channelInactive(ctx);
}
use of org.redisson.client.protocol.QueueCommandHolder in project redisson by redisson.
the class CommandsQueuePubSub 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);
}
}
use of org.redisson.client.protocol.QueueCommandHolder in project redisson by redisson.
the class CommandsQueuePubSub method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
while (true) {
QueueCommandHolder command = queue.poll();
if (command == null) {
break;
}
command.getChannelPromise().tryFailure(new WriteRedisConnectionException("Channel has been closed! Can't write command: " + LogHelper.toString(command.getCommand()) + " to channel: " + ctx.channel()));
}
super.channelInactive(ctx);
}
Aggregations