@Test public void testAcquire() throws Exception { EventLoopGroup group = new LocalEventLoopGroup(); LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID); Bootstrap cb = new Bootstrap(); cb.remoteAddress(addr); cb.group(group) .channel(LocalChannel.class); ServerBootstrap sb = new ServerBootstrap(); sb.group(group) .channel(LocalServerChannel.class) .childHandler(new ChannelInitializer<LocalChannel>() { @Override public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new ChannelInboundHandlerAdapter()); } }); Channel sc = sb.bind(addr).sync().channel(); CountingChannelPoolHandler handler = new CountingChannelPoolHandler(); ChannelPool pool = new SimpleChannelPool(cb, handler); Channel channel = pool.acquire().sync().getNow(); pool.release(channel).syncUninterruptibly(); Channel channel2 = pool.acquire().sync().getNow(); assertSame(channel, channel2); assertEquals(1, handler.channelCount()); pool.release(channel2).syncUninterruptibly(); try { pool.release(channel2).syncUninterruptibly(); fail(); } catch (IllegalArgumentException e) { assertFalse(channel.isActive()); } assertEquals(1, handler.acquiredCount()); assertEquals(2, handler.releasedCount()); sc.close().sync(); group.shutdownGracefully(); }
@Override public final Future<Channel> acquire() { return acquire(bootstrap.config().group().next().<Channel>newPromise()); }
SimpleChannelPool implements ChannelPool { @Override public final Future<Channel> acquire() { return acquire(bootstrap.config().group().next().<Channel>newPromise()); } }
SimpleChannelPool implements ChannelPool { @Override public final Future<Channel> acquire() { return acquire(bootstrap.config().group().next().<Channel>newPromise()); } SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
                             boolean releaseHealthCheck);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
                             boolean releaseHealthCheck, boolean lastRecentUsed); }
SimpleChannelPool implements ChannelPool { @Override public final Future<Channel> acquire() { return acquire(bootstrap.config().group().next().<Channel>newPromise()); } SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
                             boolean releaseHealthCheck);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
                             boolean releaseHealthCheck, boolean lastRecentUsed); @Override final Future<Channel> acquire(); @Override Future<Channel> acquire(final Promise<Channel> promise); @Override final Future<Void> release(Channel channel); @Override Future<Void> release(final Channel channel, final Promise<Void> promise); @Override void close(); }
SimpleChannelPool implements ChannelPool { @Override public final Future<Channel> acquire() { return acquire(bootstrap.config().group().next().<Channel>newPromise()); } SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
                             boolean releaseHealthCheck);  SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
                             boolean releaseHealthCheck, boolean lastRecentUsed); @Override final Future<Channel> acquire(); @Override Future<Channel> acquire(final Promise<Channel> promise); @Override final Future<Void> release(Channel channel); @Override Future<Void> release(final Channel channel, final Promise<Void> promise); @Override void close();  }