@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 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; } };
@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); } };
@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); } };
channelPool = new FixedChannelPool(b, new HttpClientChannelPoolHandler(sslContext), maxCount);
@Override protected FixedChannelPool newPool(InetSocketAddress key) { return new FixedChannelPool(bootstrap.remoteAddress(key), channelPoolHandler, maxConn); } };
@Override protected ChannelPool newPool(SocketAddress key) { Bootstrap bootstrap = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class) .option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.AUTO_READ, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis).remoteAddress(key); // We multiplex over the same TCP connection, so don't acquire more than one connection per endpoint. // TODO: But perhaps we could make it a configurable property. return new FixedChannelPool(bootstrap, new MyChannelPoolHandler(key), 1); } };
(bootstrap, handler, checker) -> new FixedChannelPool(bootstrap, handler, checker,
(bootstrap, handler, checker) -> new FixedChannelPool(bootstrap, handler, checker,
@Override protected SimpleChannelPool newPool(InetSocketAddress key) { return new FixedChannelPool(bootstrap.remoteAddress(key), new ChannelPoolHandler() { @Override public void channelReleased(Channel channel) throws Exception { channel.pipeline().remove("collector"); } @Override public void channelAcquired(Channel channel) throws Exception { // We don't do anything special when acquiring channels. The channel handler cleans up // after each connection is used. } @Override public void channelCreated(Channel channel) throws Exception { if (key.getPort() == 443) { SslContext context = SslContextBuilder.forClient().protocols("TLSv1.2").build(); // Unbelievably, Java doesn't automatically check the CN to make sure we're talking // to the right host! Therefore, we provide the intended host name and port, along // with asking Java very nicely if it could check the hostname in the certificate // for us. SSLEngine engine = context.newEngine(channel.alloc(), key.getHostString(), key.getPort()); engine.getSSLParameters().setEndpointIdentificationAlgorithm("HTTPS"); channel.pipeline().addLast("ssl", new SslHandler(engine)); } channel.pipeline().addLast("http", new HttpClientCodec()); } }, 8); } };
(bootstrap, handler, checker) -> new FixedChannelPool(bootstrap, handler, checker,
FastdfsPool(Bootstrap bootstrap, long readTimeout, long idleTimeout, int maxConnPerHost) { this.channelPool = new FixedChannelPool( bootstrap, new FastdfsPoolHandler(readTimeout, idleTimeout), maxConnPerHost ); }
@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 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 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; } };
@Override protected FixedChannelPool newPool(ChannelPoolKey key) { logger.debug("newPool: Creating new FixedChannelPool for userId = " + _user.getId() + ". remoteAddress = " + key.getAddress() + ", useSSl = " + key.isUseSsl()); Bootstrap bootstrap = ClientBootstrapFactory.getInstance(); return new FixedChannelPool(bootstrap.remoteAddress(key.getAddress()), new HttpClientChannelPoolHandler(_sslContext, key.isUseSsl(), _user.getId()), ChannelHealthChecker.ACTIVE, AcquireTimeoutAction.FAIL, 5000, _maxConnPerUser, 20, true); } };