Asynchronous Netty服务器引导-异步绑定?

Asynchronous Netty服务器引导-异步绑定?,asynchronous,jboss,bind,netty,Asynchronous,Jboss,Bind,Netty,首先,这里有一个参考,我在哪里读到了关于这个问题的所有我现在知道的东西: 尽管文档中没有明确指定,ServerBootstrap.bind似乎是同步的,因为它不返回ChannelFuture,而是返回一个通道。如果是这种情况,那么我看不到任何使用ServerBootstrap类进行异步绑定的方法。我是否遗漏了什么,或者我必须推出自己的解决方案 致以最诚挚的问候我最终推出了自己的引导实现,添加了以下内容: public ChannelFuture bindAsync(final SocketAdd

首先,这里有一个参考,我在哪里读到了关于这个问题的所有我现在知道的东西:

尽管文档中没有明确指定,
ServerBootstrap.bind
似乎是同步的,因为它不返回
ChannelFuture
,而是返回一个通道。如果是这种情况,那么我看不到任何使用
ServerBootstrap
类进行异步绑定的方法。我是否遗漏了什么,或者我必须推出自己的解决方案


致以最诚挚的问候

我最终推出了自己的引导实现,添加了以下内容:

public ChannelFuture bindAsync(final SocketAddress localAddress)
{
    if (localAddress == null) {
        throw new NullPointerException("localAddress");
    }
    final BlockingQueue<ChannelFuture> futureQueue =
        new LinkedBlockingQueue<ChannelFuture>();
    ChannelHandler binder = new Binder(localAddress, futureQueue);
    ChannelHandler parentHandler = getParentHandler();
    ChannelPipeline bossPipeline = pipeline();
    bossPipeline.addLast("binder", binder);
    if (parentHandler != null) {
        bossPipeline.addLast("userHandler", parentHandler);
    }
    getFactory().newChannel(bossPipeline);
    ChannelFuture future = null;
    boolean interrupted = false;
    do {
        try {
            future = futureQueue.poll(Integer.MAX_VALUE, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            interrupted = true;
        }
    } while (future == null);
    if (interrupted) {
        Thread.currentThread().interrupt();
    }
    return future;
}
公共通道Future bindAsync(最终SocketAddress本地地址)
{
if(localAddress==null){
抛出新的NullPointerException(“localAddress”);
}
最终封锁队列未来队列=
新建LinkedBlockingQueue();
ChannelHandler绑定器=新绑定器(localAddress,futureQueue);
ChannelHandler parentHandler=getParentHandler();
ChannelPipeline bossPipeline=管道();
bossPipeline.addLast(“活页夹”,活页夹);
if(parentHandler!=null){
addLast(“userHandler”,parentHandler);
}
getFactory().newChannel(bossPipeline);
ChannelFuture=null;
布尔值=假;
做{
试一试{
future=futureQueue.poll(Integer.MAX_值,TimeUnit.SECONDS);
}捕捉(中断异常e){
中断=真;
}
}while(future==null);
如果(中断){
Thread.currentThread().interrupt();
}
回归未来;
}

在Netty 3.6中有一个异步绑定。以下是javadoc: