List of usage examples for io.netty.channel.pool FixedChannelPool FixedChannelPool
public FixedChannelPool(Bootstrap bootstrap, ChannelPoolHandler handler, int maxConnections)
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)); } } }; }