Example usage for io.netty.channel.pool FixedChannelPool FixedChannelPool

List of usage examples for io.netty.channel.pool FixedChannelPool FixedChannelPool

Introduction

In this page you can find the example usage for io.netty.channel.pool FixedChannelPool FixedChannelPool.

Prototype

public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections) 

Source Link

Document

Creates a new instance using the ChannelHealthChecker#ACTIVE .

Usage

From source file:org.eclipse.californium.elements.tcp.TcpClientConnector.java

License:Open Source License

@Override
public synchronized void start() throws IOException {
    if (rawDataChannel == null) {
        throw new IllegalStateException("Cannot start without message handler.");
    }//from w  w  w  .  j ava  2  s .c  om

    if (workerGroup != null) {
        throw new IllegalStateException("Connector already started");
    }

    workerGroup = new NioEventLoopGroup(numberOfThreads);
    poolMap = new AbstractChannelPoolMap<SocketAddress, ChannelPool>() {

        @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.
            if (USE_FIXED_CONNECTION_POOL) {
                return new FixedChannelPool(bootstrap, new MyChannelPoolHandler(key), 1);
            } else {
                return new SimpleChannelPool(bootstrap, new MyChannelPoolHandler(key));
            }
        }
    };
}