use of io.netty.util.concurrent.EventExecutor in project netty by netty.
the class AbstractHttp2StreamChannel method doWrite.
@Override
protected final void doWrite(ChannelOutboundBuffer in) throws Exception {
if (closed) {
throw CLOSED_CHANNEL_EXCEPTION;
}
EventExecutor preferredExecutor = preferredEventExecutor();
// https://github.com/netty/netty/issues/4941
if (preferredExecutor.inEventLoop()) {
for (; ; ) {
Object msg = in.current();
if (msg == null) {
break;
}
try {
doWrite(ReferenceCountUtil.retain(msg));
} catch (Throwable t) {
// It would be nice to fail the future, but we can't do that if not on the event
// loop. So we instead opt for a solution that is consistent.
pipeline().fireExceptionCaught(t);
}
in.remove();
}
doWriteComplete();
} else {
// Use a copy because the original msgs will be recycled by AbstractChannel.
final Object[] msgsCopy = new Object[in.size()];
for (int i = 0; i < msgsCopy.length; i++) {
msgsCopy[i] = ReferenceCountUtil.retain(in.current());
in.remove();
}
preferredExecutor.execute(new Runnable() {
@Override
public void run() {
for (Object msg : msgsCopy) {
try {
doWrite(msg);
} catch (Throwable t) {
pipeline().fireExceptionCaught(t);
}
}
doWriteComplete();
}
});
}
}
use of io.netty.util.concurrent.EventExecutor in project netty by netty.
the class Http2MultiplexCodec method flushFromStreamChannel.
void flushFromStreamChannel() {
EventExecutor executor = ctx.executor();
if (executor.inEventLoop()) {
flush(ctx);
} else {
Runnable task = flushTask;
if (task == null) {
task = flushTask = new Runnable() {
@Override
public void run() {
flush(ctx);
}
};
}
executor.execute(task);
}
}
Aggregations