5

まず、この質問に関して私が今知っていることをすべて読んだ場所への参照があります:http: //docs.jboss.org/netty/3.2/api/org/jboss/netty/bootstrap/ServerBootstrap.html#bind%28 %29

ドキュメントでは明示的に指定されてServerBootstrap.bindいませんが、同期しているように見えます。これは、を返すのChannelFutureではなく、チャネルを返すためです。ServerBootstrapその場合、クラスを使用して非同期バインドを作成する方法がわかりません。私は何かが足りないのですか、それとも自分の解決策を実行する必要がありますか?

よろしくお願いします

4

2 に答える 2

4

私は次の追加で自分のブートストラップ実装をロールバックすることになりました:

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;
}
于 2012-06-23T13:10:35.463 に答える
0

Netty 3.6には、非同期バインドがあります。javadocは次のとおりです。http: //netty.io/3.6/api/org/jboss/netty/bootstrap/ServerBootstrap.html#bindAsync()

于 2013-08-11T20:09:47.813 に答える