NettyClientConfig.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:util4j 作者:
/**
 * 因为每次连接执行都会init都会被remove,所以每次调用booter都会用新的handler来进行连接配置
 * @param address
 * @param init
 * @return
 */
protected ChannelFuture doBooterConnect(InetSocketAddress address,final ChannelHandler init)
{
    ChannelFuture cf;
    synchronized (booter) {
        if(booter.config().group()==null)
        {
            booterInit();
        }
        final CountDownLatch latch=new CountDownLatch(1);
        ChannelHandler handler=initHandlerAdapter(init);
        booter.handler(handler);
        cf=booter.connect(address);
        cf.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                log.trace("connect operationComplete:isDone="+future.isDone()+",isSuccess="+future.isSuccess());
                if(future.isDone() && future.isSuccess())
                {
                    latch.countDown();
                }
            }
        });
        try {
            latch.await(getConnectTimeOutMills(),TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
    }
    return cf;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号