Luk*_*ber 5 jboss asynchronous bind netty
首先,这里有一个参考,我在那里阅读了我现在所知道的关于这个问题的所有内容:http: //docs.jboss.org/netty/3.2/api/org/jboss/netty/bootstrap/ServerBootstrap.html#bind%28 %29
虽然文档没有明确指定,但它似乎ServerBootstrap.bind是同步的 - 因为它不返回a ChannelFuture,而是返回Channel.如果是这种情况,那么我没有看到任何方法使用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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1115 次 |
| 最近记录: |