private Future < Channel > acquireHealthyFromPoolOrNew ( final Promise < Channel > promise ) { try { final Channel ch = pollChannel ( ) ; if ( ch == null ) { // No Channel left in the pool bootstrap a new Channel Bootstrap bs = bootstrap . clone ( ) ; bs . attr ( POOL_KEY , this ) ; ChannelFuture f = connectChannel ( bs ) ; if ( f . isDone ( ) ) { notifyConnect ( f , promise ) ; } else { f . addListener ( new ChannelFutureListener ( ) { @ Override public void operationComplete ( ChannelFuture future ) throws Exception { notifyConnect ( future , promise ) ; } } ) ; } return promise ; } EventLoop loop = ch . eventLoop ( ) ; if ( loop . inEventLoop ( ) ) { doHealthCheck ( ch , promise ) ; } else { loop . execute ( new Runnable ( ) { @ Override public void run ( ) { doHealthCheck ( ch , promise ) ; } } ) ; } } catch ( Throwable cause ) { promise . tryFailure ( cause ) ; } return promise ; }
Tries to retrieve healthy channel from the pool if any or creates a new channel otherwise .