netty4 channelPool

47 views
Skip to first unread message

James Kim

unread,
Jun 13, 2017, 8:20:03 PM6/13/17
to Netty discussions
i saw a netty4 channelPool

my question is that

final SimpleChannelPool pool = poolMap.get(addr1);

if i want to make a different pool in addr1 or addr2

is that proper way to make a problem?


if(addr1){
final SimpleChannelPool pool1 = poolMap.get(addr1);
}
else if (addr2){
final SimpleChannelPool pool2= poolMap.get(addr2);
}

or

final SimpleChannelPool pool;
if(addr1){
 pool = poolMap.get(addr1);
}
else if (addr2){
 pool = poolMap.get(addr2);
}

and  how can i count channelPool?

i am new to netty4 and give me a hint~


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);
       
}
   
}
});

Norman Maurer

unread,
Jun 14, 2017, 1:57:26 AM6/14/17
to ne...@googlegroups.com, James Kim
If i understood you correctly its not really a question about netty but java in general. Both work but I would go with the second one
--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/0c8d221a-7338-4cc8-8fa5-c1af49dc89a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages