【问题标题】:Netty ServerBootstrap - asynchronous binding?Netty ServerBootstrap - 异步绑定?
【发布时间】:2012-06-23 04:06:03
【问题描述】:

首先,这是我在哪里阅读了我现在所知道的关于这个问题的所有内容的参考:http://docs.jboss.org/netty/3.2/api/org/jboss/netty/bootstrap/ServerBootstrap.html#bind%28%29

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

最好的问候

【问题讨论】:

    标签: asynchronous jboss bind netty


    【解决方案1】:

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

    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;
    }
    

    【讨论】:

      【解决方案2】:

      在 Netty 3.6 中有一个异步绑定。这是 javadoc:http://netty.io/3.6/api/org/jboss/netty/bootstrap/ServerBootstrap.html#bindAsync()

      【讨论】:

        猜你喜欢
        • 2013-09-30
        • 2013-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多