Search in sources :

Example 1 with FixedChannelPool

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);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) FixedChannelPool(io.netty.channel.pool.FixedChannelPool) Bootstrap(io.netty.bootstrap.Bootstrap) HttpClientChannelPoolHandler(pro.tools.http.netty.handler.HttpClientChannelPoolHandler) URI(java.net.URI)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)1 FixedChannelPool (io.netty.channel.pool.FixedChannelPool)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 URI (java.net.URI)1 HttpClientChannelPoolHandler (pro.tools.http.netty.handler.HttpClientChannelPoolHandler)1