io.netty.channel.pool.FixedChannelPool Java Examples
The following examples show how to use
io.netty.channel.pool.FixedChannelPool.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtdClientPool.java From ftdc with Apache License 2.0 | 6 votes |
/** * 释放连接 * @param channel * @return */ public Future<Void> release(Channel channel) { Verify.verifyNotNull(channel, "channel不允许为NULL"); InetSocketAddress remoteAddress = (InetSocketAddress)channel.remoteAddress(); if(logger.isDebugEnabled()) { logger.debug("{} channel released", remoteAddress); } FixedChannelPool fixedChannelPool = pollMap.get(remoteAddress); Future<Void> releaseFuture = fixedChannelPool.release(channel); if(!releaseFuture.isSuccess()) { Throwable cause = releaseFuture.cause(); if(cause != null) { logger.error("rlease local channel {}, remote channel {}, happens error {}", channel.localAddress(), channel.remoteAddress(), ExceptionUtils.getStackTrace(releaseFuture.cause())); } } return releaseFuture; }
Example #2
Source File: FtdClientPool.java From ftdc with Apache License 2.0 | 5 votes |
/** * 循环取出可用连接一个使用 * @return * @throws VerifyException */ public Future<Channel> acquire(List<ConnectAddrProperty> sas) { Verify.verify(pollMap != null && !sas.isEmpty(), "ftdc connection pool init failure or sas is null"); SocketAddressChooser newChooser = DefaultSocketAddressChooserFactory.INSTANCE.newChooser(sas.size()); SocketAddressChooser oldChooser = CHOOSER_MAP.putIfAbsent(sas.hashCode(), newChooser); if(oldChooser == null) { oldChooser = newChooser; } InetSocketAddress socketAddress = (InetSocketAddress)oldChooser.next(sas); if(logger.isDebugEnabled()) { logger.debug("use socket address {}", socketAddress); } FixedChannelPool fixedChannelPool = pollMap.get(socketAddress); return fixedChannelPool.acquire(); }
Example #3
Source File: BackClientPool.java From api-gateway-core with Apache License 2.0 | 5 votes |
private BackClientPool() { bootstrap .group(group) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 500) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, true); poolMap = new AbstractChannelPoolMap<RequestHolder, SimpleChannelPool>() { @Override protected SimpleChannelPool newPool(RequestHolder requestHolder) { return new FixedChannelPool(bootstrap.remoteAddress(requestHolder.getSocketAddress()), new BackPoolHandler(requestHolder), 50); } }; }
Example #4
Source File: DefaultClientPool.java From protools with Apache License 2.0 | 5 votes |
private void init(String url, int maxCount) throws URISyntaxException, SSLException { URI uri = new URI(url); if (uri.getScheme() == null || uri.getHost() == null) { throw new IllegalArgumentException("uri不合法"); } scheme = uri.getScheme(); host = uri.getHost(); port = uri.getPort(); if (port == -1) { if (HttpScheme.HTTP.equalsIgnoreCase(scheme)) { port = 80; } else if (HttpScheme.HTTPS.equalsIgnoreCase(scheme)) { port = 443; } } if (!HttpScheme.HTTP.equalsIgnoreCase(scheme) && !HttpScheme.HTTPS.equalsIgnoreCase(scheme)) { if (log.isErrorEnabled()) { log.error("仅有HTTP(S)是支持的。"); } return; } final boolean ssl = HttpScheme.HTTPS.equalsIgnoreCase(scheme); this.setSSlContext(ssl); final Bootstrap b = new Bootstrap(); b.group(GROUP) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, true) .remoteAddress(InetSocketAddress.createUnresolved(host, port)) ; channelPool = new FixedChannelPool(b, new HttpClientChannelPoolHandler(sslContext), maxCount); }
Example #5
Source File: FastdfsPool.java From fastdfs-client with Apache License 2.0 | 5 votes |
FastdfsPool(Bootstrap bootstrap, long readTimeout, long idleTimeout, int maxConnPerHost, int maxPendingRequests) { this.channelPool = new FixedChannelPool( bootstrap, new FastdfsPoolHandler(readTimeout, idleTimeout), maxConnPerHost, maxPendingRequests ); }
Example #6
Source File: FtdClientPool.java From ftdc with Apache License 2.0 | 4 votes |
@Override protected FixedChannelPool newPool(InetSocketAddress key) { return new FixedChannelPool(initBootStrap().remoteAddress(key), new InitChannelPoolHandler(), new DefaultChannelHealthChecker(), AcquireTimeoutAction.NEW, 500, maxConnections, maxPending); }
Example #7
Source File: FastdfsPool.java From azeroth with Apache License 2.0 | 4 votes |
FastdfsPool(Bootstrap bootstrap, long readTimeout, long idleTimeout, int maxConnPerHost) { this.channelPool = new FixedChannelPool(bootstrap, new FastdfsPoolHandler(readTimeout, idleTimeout), maxConnPerHost); }