@Override protected ChannelPool newPool(RequestKey key) { Bootstrap newBootstrap = bootstrap.clone(group); newBootstrap.remoteAddress(key.getRemoteAddress()); AbstractChannelPoolHandler channelPoolHandler = newPoolHandler(key); return new FixedChannelPool( newBootstrap, channelPoolHandler, ChannelHealthChecker.ACTIVE, FixedChannelPool.AcquireTimeoutAction.FAIL, connectionPoolConfiguration.getAcquireTimeout().map(Duration::toMillis).orElse(-1L), maxConnections, connectionPoolConfiguration.getMaxPendingAcquires() ); } };
@Override public Future<Channel> acquire(final Promise<Channel> promise) { try { if (executor.inEventLoop()) { acquire0(promise); } else { executor.execute(new Runnable() { @Override public void run() { acquire0(promise); } }); } } catch (Throwable cause) { promise.setFailure(cause); } return promise; }
private void decrementAndRunTaskQueue() { // We should never have a negative value. int currentCount = acquiredChannelCount.decrementAndGet(); assert currentCount >= 0; // Run the pending acquire tasks before notify the original promise so if the user would // try to acquire again from the ChannelFutureListener and the pendingAcquireCount is >= // maxPendingAcquires we may be able to run some pending tasks first and so allow to add // more. runTaskQueue(); }
@Override public void close() { if (executor.inEventLoop()) { close0(); } else { executor.submit(new Runnable() { @Override public void run() { close0(); } }).awaitUninterruptibly(); } }
@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)); }
Future<Channel> f = pool.acquire();
@Override public void close() { if (executor.inEventLoop()) { close0(); } else { executor.submit(new Runnable() { @Override public void run() { close0(); } }).awaitUninterruptibly(); } }
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; }); } }
@Override protected FixedChannelPool newPool(InetSocketAddress key) { FixedChannelPool fixedClientChannelPool = new FixedChannelPool( bootstrap.remoteAddress(key), new DefaultChannelPoolHandler() { @Override public void channelCreated(Channel ch) throws Exception { super.channelCreated(ch); final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(defaultEventExecutorGroup, new IdleStateHandler(nettyClientConfig.getChannelMaxReadIdleSeconds(), nettyClientConfig.getChannelMaxWriteIdleSeconds(), nettyClientConfig.getChannelMaxAllIdleSeconds())); pipeline.addLast(defaultEventExecutorGroup, new RpcClientHandler()); } }, ChannelHealthChecker.ACTIVE, AcquireTimeoutAction.FAIL, nettyClientConfig.getMaxAcquireConnMills(), nettyClientConfig.getPerHostMaxConn(), nettyClientConfig.getPendingConnSize(), false ); return fixedClientChannelPool; } };
private void decrementAndRunTaskQueue() { // We should never have a negative value. int currentCount = acquiredChannelCount.decrementAndGet(); assert currentCount >= 0; // Run the pending acquire tasks before notify the original promise so if the user would // try to acquire again from the ChannelFutureListener and the pendingAcquireCount is >= // maxPendingAcquires we may be able to run some pending tasks first and so allow to add // more. runTaskQueue(); }
@Override public Future<Channel> acquire(final Promise<Channel> promise) { try { if (executor.inEventLoop()) { acquire0(promise); } else { executor.execute(new Runnable() { @Override public void run() { acquire0(promise); } }); } } catch (Throwable cause) { promise.setFailure(cause); } return promise; }
@Override public void close() { if (executor.inEventLoop()) { close0(); } else { executor.submit(new Runnable() { @Override public void run() { close0(); } }).awaitUninterruptibly(); } }
); ch.close(); _pool.release(ch); Future<Channel> f = _pool.acquire(); long now = _allocateStartTimeMillis; if (channelStatsCollectorLogger.isDebugEnabled()) { _channelStatsCollector.incrementNumChannelsAcquiredFailed(); Future<Channel> f = _pool.acquire(); f.addListener(new ChannelAllocatedFutureListener(_httpTransport, _httpMethod, _simpleUri, _urlBindVariables, _headers, _content, _formParameters, _fileUploads, _dropResponse,
@Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = logicSchema.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); return new FixedChannelPool( bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName, logicSchema.getName()), maxConnections); } };
private void decrementAndRunTaskQueue() { // We should never have a negative value. int currentCount = acquiredChannelCount.decrementAndGet(); assert currentCount >= 0; // Run the pending acquire tasks before notify the original promise so if the user would // try to acquire again from the ChannelFutureListener and the pendingAcquireCount is >= // maxPendingAcquires we may be able to run some pending tasks first and so allow to add // more. runTaskQueue(); }
@Override public Future<Channel> acquire(final Promise<Channel> promise) { try { if (executor.inEventLoop()) { acquire0(promise); } else { executor.execute(new Runnable() { @Override public void run() { acquire0(promise); } }); } } catch (Throwable cause) { promise.setFailure(cause); } return promise; }
@Override public void close() { if (executor.inEventLoop()) { close0(); } else { executor.submit(new Runnable() { @Override public void run() { close0(); } }).awaitUninterruptibly(); } }
@Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = logicSchema.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); return new FixedChannelPool( bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName, logicSchema.getName()), maxConnections); } };
private void decrementAndRunTaskQueue() { --acquiredChannelCount; // We should never have a negative value. assert acquiredChannelCount >= 0; // Run the pending acquire tasks before notify the original promise so if the user would // try to acquire again from the ChannelFutureListener and the pendingAcquireCount is >= // maxPendingAcquires we may be able to run some pending tasks first and so allow to add // more. runTaskQueue(); }
@Override public Future<Channel> acquire(final Promise<Channel> promise) { try { if (executor.inEventLoop()) { acquire0(promise); } else { executor.execute(new Runnable() { @Override public void run() { acquire0(promise); } }); } } catch (Throwable cause) { promise.setFailure(cause); } return promise; }