when netty connects to my server?

130 Views Asked by At

I am using the Channle pool API code written here:

ChannelPool section http://netty.io/news/2015/05/07/4-0-28-Final.html

EventLoopGroup group = new NioEventLoopGroup();
final Bootstrap cb = new Bootstrap();
InetSocketAddress addr1 = new InetSocketAddress("10.0.0.10", 8888);
InetSocketAddress addr2 = new InetSocketAddress("10.0.0.11", 8888);

cb.group(group).channel(NioSocketChannel.class);

ChannelPoolMap<InetSocketAddress, SimpleChannelPool> poolMap = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() {
    @Override
    protected SimpleChannelPool newPool(InetSocketAddress key) {
        return new SimpleChannelPool(cb.remoteAddress(key), new TestChannelPoolHandler());
    }
};

// depending on when you use addr1 or addr2 you will get different pools.
final SimpleChannelPool pool = poolMap.get(addr1);
Future<Channel> f = pool.acquire();
f.addListener(new FutureListener<Channel>() {
    @Override
    public void operationComplete(Future<Channel> f) {
        if (f.isSuccess()) {
            Channel ch = f.getNow();
            // Do somethings
            // ...
            // ...

            // Release back to pool
            pool.release(ch);
        }
    }
});

As i see the code we never called .connect method so my question is when netty trying to connecting my channel to server ?

1

There are 1 best solutions below

0
On BEST ANSWER

As you use SimpleChannelPool it will do connect when you call acquire and there is nothing left in the ChannelPool.