@Override public void dispose() { doTimeoutAwareAction(_pool::dispose); }
handle.addTimeoutTask(() -> { LOG.debug("Reset stream upon timeout, stream={}", streamId); resetStream(ctx, streamId, Http2Error.CANCEL.code(), ctx.newPromise()); handle.release();
private void doReset() { // Resets and closes the stream _lifecycleManager.resetStream(_ctx, _streamId, Http2Error.CANCEL.code(), _ctx.newPromise()); _ctx.flush(); // Releases the handle to put the channel back to the pool _timeoutPoolHandle.release(); }
@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 { // Releases the async pool handle @SuppressWarnings("unchecked") TimeoutAsyncPoolHandle<?> handle = ((RequestWithCallback<?, ?, TimeoutAsyncPoolHandle<?>>) msg).handle(); handle.dispose(); // Invokes user specified callback with error TransportCallback<?> callback = ((RequestWithCallback) msg).callback(); callback.onResponse(TransportResponseImpl.error(future.cause())); } }); }
TimeoutBufferedWriter(final ChannelHandlerContext ctx, int streamId, long maxContentLength, TimeoutAsyncPoolHandle<?> timeoutPoolHandle) { _ctx = ctx; _streamId = streamId; _maxContentLength = maxContentLength; _timeoutPoolHandle = timeoutPoolHandle; _failureBeforeInit = null; _lastChunkReceived = false; _totalBytesWritten = 0; _buffer = new LinkedList<>(); // schedule a timeout to set the stream and inform use _timeoutPoolHandle.addTimeoutTask(() -> _ctx.executor().execute(() -> { final String message = String.format( "Timeout while receiving the response entity, stream=%d, remote=%s", streamId, ctx.channel().remoteAddress()); doResetAndNotify(new TimeoutException(message)); })); }
TimeoutAsyncPoolHandle<Channel> handle = new TimeoutAsyncPoolHandle<>( _pool, _scheduler, _requestTimeout, TimeUnit.MILLISECONDS, channel);
_timeoutPoolHandle.release();
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof RequestWithCallback)) { ctx.write(msg, promise); return; } _upgradePromise.addListener(f -> { ChannelFuture future = (ChannelFuture)f; if (future.isSuccess()) { ctx.write(msg, promise); } else { // Releases the async pool handle @SuppressWarnings("unchecked") TimeoutAsyncPoolHandle<?> handle = ((RequestWithCallback<?, ?, TimeoutAsyncPoolHandle<?>>) msg).handle(); handle.dispose(); // Invokes user specified callback with error TransportCallback<?> callback = ((RequestWithCallback) msg).callback(); callback.onResponse(TransportResponseImpl.error(future.cause())); } }); }
timeoutHandle.release();
@Override public void release() { doTimeoutAwareAction(_pool::put); }