use of io.netty.channel.pool.FixedChannelPool in project protools by SeanDragon.
the class DefaultClientPool method init.
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);
}
Aggregations