@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { logger.debug("exceptionCaught for request with url " + _httpRequest.uri()); /* * Call the registered callback */ logger.info("exceptionCaught reason = " + cause + ". Was for for userId " + _userId + ", behaviour id = " + _callbackObject.getBehaviorId()); if (logger.isDebugEnabled()) { cause.printStackTrace(); } /* * Stop listening for the close callback */ _channel.closeFuture().removeListener(_closeListener); if (_channel.isOpen()) { _channel.close(); } Future<Void> releaseFuture = _pool.release(_channel); releaseFuture.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { _callbackObject.httpRequestFailed(cause, _httpRequest.method() == HttpMethod.GET); } }); }
@Override public void operationComplete(ChannelFuture future) throws Exception { Channel ch = future.channel(); logger.info("operationComplete channel closed for userId = " + _userId + ". Retrying." + " localAddress = " + ch.localAddress() + ", remoteAddress = " + ch.remoteAddress() ); _pool.release(ch); Future<Channel> f = _pool.acquire(); long now = 0; if (channelStatsCollectorLogger.isDebugEnabled()) { now = System.currentTimeMillis(); _channelStatsCollector.incrementNumChannelsRequested(); _channelStatsCollector.incrementNumChannelsAcquiredClosed(); } f.addListener(new ChannelAllocatedFutureListener(_httpTransport, _httpMethod, _simpleUri, _urlBindVariables, _headers, _content, _formParameters, _fileUploads, _dropResponse, _callback, _pool, now, _userId)); }
private AsyncTcpResponse executeByPool(TcpRequest request) throws InterruptedException, ExecutionException, IOException { InetSocketAddress address = new InetSocketAddress(request.getUri().getHost(), request.getUri().getPort()); FixedChannelPool pool = poolManager.getChannelPool(address); Future<Channel> future = pool.acquire().sync(); if (!future.isSuccess()) { log.debug(future.cause()); throw new ConnectTimeoutException(String.valueOf(future.cause())); } else { Channel channel = future.get(); ChannelFuture channelFuture; try { channelFuture = channel.writeAndFlush(request.getData()); } catch (Throwable e) { pool.release(channel); throw new IOException(e); } return new AsyncTcpResponse(channelFuture, request.getUri(), () -> { pool.release(channel); return true; }); } }
); ch.close(); _pool.release(ch); Future<Channel> f = _pool.acquire(); long now = _allocateStartTimeMillis;