use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project grpc-java by grpc.
the class NettyClientHandlerTest method receivedGoAwayShouldCancelBufferedStream.
@Test
public void receivedGoAwayShouldCancelBufferedStream() throws Exception {
// Force the stream to be buffered.
receiveMaxConcurrentStreams(0);
ChannelFuture future = enqueue(new CreateStreamCommand(grpcHeaders, streamTransportState));
channelRead(goAwayFrame(0));
assertTrue(future.isDone());
assertFalse(future.isSuccess());
Status status = Status.fromThrowable(future.cause());
assertEquals(Status.Code.UNAVAILABLE, status.getCode());
assertEquals("HTTP/2 error code: NO_ERROR\nReceived Goaway", status.getDescription());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project grpc-java by grpc.
the class NettyClientHandlerTest method receivedGoAwayShouldFailUnknownBufferedStreams.
@Test
public void receivedGoAwayShouldFailUnknownBufferedStreams() throws Exception {
receiveMaxConcurrentStreams(0);
ChannelFuture future = enqueue(new CreateStreamCommand(grpcHeaders, streamTransportState));
// Read a GOAWAY that indicates our stream was never processed by the server.
channelRead(goAwayFrame(0, 8, /* Cancel */
Unpooled.copiedBuffer("this is a test", UTF_8)));
assertTrue(future.isDone());
assertFalse(future.isSuccess());
Status status = Status.fromThrowable(future.cause());
assertEquals(Status.CANCELLED.getCode(), status.getCode());
assertEquals("HTTP/2 error code: CANCEL\nReceived Goaway\nthis is a test", status.getDescription());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project rest.li by linkedin.
the class RAPResponseDecoder method channelRead0.
@Override
protected void channelRead0(final ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpResponse) {
HttpResponse m = (HttpResponse) msg;
_shouldCloseConnection = !HttpUtil.isKeepAlive(m);
if (HttpUtil.is100ContinueExpected(m)) {
ctx.writeAndFlush(CONTINUE).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
}
}
});
}
if (!m.decoderResult().isSuccess()) {
ctx.fireExceptionCaught(m.decoderResult().cause());
return;
}
// remove chunked encoding.
if (HttpUtil.isTransferEncodingChunked(m)) {
HttpUtil.setTransferEncodingChunked(m, false);
}
Timeout<None> timeout = ctx.channel().attr(TIMEOUT_ATTR_KEY).getAndRemove();
if (timeout == null) {
LOG.debug("dropped a response after channel inactive or exception had happened.");
return;
}
final TimeoutBufferedWriter writer = new TimeoutBufferedWriter(ctx, _maxContentLength, BUFFER_HIGH_WATER_MARK, BUFFER_LOW_WATER_MARK, timeout);
EntityStream entityStream = EntityStreams.newEntityStream(writer);
_chunkedMessageWriter = writer;
StreamResponseBuilder builder = new StreamResponseBuilder();
builder.setStatus(m.status().code());
for (Map.Entry<String, String> e : m.headers()) {
String key = e.getKey();
String value = e.getValue();
if (key.equalsIgnoreCase(HttpConstants.RESPONSE_COOKIE_HEADER_NAME)) {
builder.addCookie(value);
} else {
builder.unsafeAddHeaderValue(key, value);
}
}
ctx.fireChannelRead(builder.build(entityStream));
} else if (msg instanceof HttpContent) {
HttpContent chunk = (HttpContent) msg;
TimeoutBufferedWriter currentWriter = _chunkedMessageWriter;
// Sanity check
if (currentWriter == null) {
throw new IllegalStateException("received " + HttpContent.class.getSimpleName() + " without " + HttpResponse.class.getSimpleName());
}
if (!chunk.decoderResult().isSuccess()) {
this.exceptionCaught(ctx, chunk.decoderResult().cause());
}
currentWriter.processHttpChunk(chunk);
if (chunk instanceof LastHttpContent) {
_chunkedMessageWriter = null;
}
} else {
// something must be wrong, but let's proceed so that
// handler after us has a chance to process it.
ctx.fireChannelRead(msg);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project rest.li by linkedin.
the class ChannelPoolLifecycle method create.
@Override
public void create(final Callback<Channel> channelCallback) {
final long start = System.currentTimeMillis();
_bootstrap.connect(_remoteAddress).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (channelFuture.isSuccess()) {
synchronized (_createTimeTracker) {
_createTimeTracker.addValue(System.currentTimeMillis() - start);
}
Channel c = channelFuture.channel();
if (_tcpNoDelay) {
c.config().setOption(ChannelOption.TCP_NODELAY, true);
}
_channelGroup.add(c);
channelCallback.onSuccess(c);
} else {
Throwable cause = channelFuture.cause();
if (cause instanceof ConnectException) {
channelCallback.onError(new RetriableRequestException(cause));
} else {
channelCallback.onError(HttpNettyStreamClient.toException(cause));
}
}
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project rest.li by linkedin.
the class Http2AlpnHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!(msg instanceof RequestWithCallback)) {
ctx.write(msg, promise);
return;
}
_alpnPromise.addListener(f -> {
ChannelFuture future = (ChannelFuture) f;
if (future.isSuccess()) {
ctx.write(msg, promise);
} else {
@SuppressWarnings("unchecked") TimeoutAsyncPoolHandle<?> handle = ((RequestWithCallback<?, ?, TimeoutAsyncPoolHandle<?>>) msg).handle();
handle.error().release();
TransportCallback<?> callback = ((RequestWithCallback) msg).callback();
callback.onResponse(TransportResponseImpl.error(future.cause()));
}
});
}
Aggregations