public HttpReceive request(HttpSend httpSend, long timeout, TimeUnit timeUnit) { final HttpReceive httpReceive = new HttpReceive(); Future<Channel> fch = channelPool.acquire(); Channel channel = null; try { channel = fch.get(timeout, timeUnit); ChannelPipeline p = channel.pipeline(); p.addLast(new HttpClientHandler(httpSend, httpReceive)); final FullHttpRequest fullHttpRequest = convertRequest(httpSend); p.writeAndFlush(fullHttpRequest); channel.closeFuture().await(timeout, timeUnit); if (!httpReceive.getIsDone()) { httpReceive.setHaveError(true); httpReceive.setErrMsg("请求已经超时"); } } catch (Exception e) { if (log.isWarnEnabled()) { log.warn(e.getMessage(), e); } httpReceive.setHaveError(true) .setErrMsg(e.getMessage()) .setThrowable(e) .setIsDone(true); } finally { if (channel != null) { channelPool.release(channel); } } return httpReceive; }
private void release0(Channel channel, Promise<Void> promise) { if (protocolImpl == null) { // If protocolImpl is null that means the first connection failed to establish. Release it back to the // underlying connection pool. delegatePool.release(channel, promise); } else { protocolImpl.release(channel, promise); } }
private void release0(Channel channel, Promise<Void> promise) { if (protocolImpl == null) { // If protocolImpl is null that means the first connection failed to establish. Release it back to the // underlying connection pool. simpleChannelPool.release(channel, promise); } else { protocolImpl.release(channel, promise); } }
@Override public Future<Void> release(Channel channel) { return pool.release(channel); }
private void releaseParentChannel0(Channel parentChannel, MultiplexedChannelRecord record) { if (parentChannel != null) { try { parentChannel.close(); } finally { connectionPool.release(parentChannel); } } connections.remove(record); }
private void releaseParentChannel(Channel parentChannel) { MultiplexedChannelRecord channelRecord = parentChannel.attr(CHANNEL_POOL_RECORD).get(); connections.remove(channelRecord); parentChannel.close(); connectionPool.release(parentChannel); }
private void releaseParentChannel(Channel parentChannel) { MultiplexedChannelRecord channelRecord = parentChannel.attr(CHANNEL_POOL_RECORD).get(); connections.remove(channelRecord); parentChannel.close(); connectionPool.release(parentChannel); }
/** * Close the channel and release it back into the pool. * * @param ctx Context for channel */ private static void closeAndRelease(ChannelHandlerContext ctx) { RequestContext requestContext = ctx.channel().attr(REQUEST_CONTEXT_KEY).get(); ctx.channel().close(); requestContext.channelPool().release(ctx.channel()); }
@Override public Future<Void> release(Channel channel) { removePerRequestHandlers(channel); return delegate.release(channel); }
/** * Close the channel and release it back into the pool. * * @param ctx Context for channel */ private static void closeAndRelease(ChannelHandlerContext ctx) { RequestContext requestContext = ctx.channel().attr(REQUEST_CONTEXT_KEY).get(); ctx.channel().close(); requestContext.channelPool().release(ctx.channel()); }
@Override public Future<Void> release(Channel channel, Promise<Void> promise) { removePerRequestHandlers(channel); return delegate.release(channel, promise); }
@Override public Future<Void> release(Channel channel) { removePerRequestHandlers(channel); return delegate.release(channel); }
protected void doDispose(ChannelPipeline channelPipeline, boolean forceClose) { channelPipeline.remove(CLIENT_CODEC_HANDLER_NAME); channelPipeline.remove(READ_TIMEOUT_HANDLER_NAME); channelPipeline.remove(REDIRECT_HANDLER_NAME); if (channelPipeline.get(DECOMPRESS_HANDLER_NAME) != null) { channelPipeline.remove(DECOMPRESS_HANDLER_NAME); } Channel channel = channelPipeline.channel(); if (forceClose && channel.isOpen()) { channel.close(); } channelPool.release(channel); }
@Override public Future<Void> release(Channel channel, Promise<Void> promise) { removePerRequestHandlers(channel); return delegate.release(channel, promise); }
/** * Close and release the channel back to the pool. * * @param channel The channel. */ private void closeAndRelease(Channel channel) { log.trace("closing and releasing channel {}", channel.id().asLongText()); channel.close().addListener(ignored -> context.channelPool().release(channel)); }
@Override public Future<Void> release(Channel channel) { if (shouldRelease(channel)) { return delegate.release(channel); } else { return new SucceededFuture<>(channel.eventLoop(), null); } }
/** * Close and release the channel back to the pool. * * @param channel The channel. */ private void closeAndRelease(Channel channel) { log.trace("closing and releasing channel {}", channel.id().asLongText()); channel.close().addListener(ignored -> context.channelPool().release(channel)); }
@Override public Future<Void> release(Channel channel, Promise<Void> promise) { if (shouldRelease(channel)) { return delegate.release(channel, promise); } else { return promise.setSuccess(null); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) { if (cancelled(ctx, e)) { RequestContext requestContext = ctx.channel().attr(REQUEST_CONTEXT_KEY).get(); requestContext.handler().onError(e); ctx.fireExceptionCaught(new IOException("Request cancelled")); ctx.close(); requestContext.channelPool().release(ctx.channel()); } else { ctx.fireExceptionCaught(e); } }
@Override public Future<Void> release(Channel channel, Promise<Void> promise) { if (shouldRelease(channel)) { return delegate.release(channel, promise); } else { return promise.setSuccess(null); } }