Netty ServerBootstrap - asynchronous binding?

Firstly, here is a link to where I read everything I know now on this subject: http://docs.jboss.org/netty/3.2/api/org/jboss/netty/bootstrap/ServerBootstrap.html# bind% 28% 29

Although this is not explicitly stated in the documentation, it seems to ServerBootstrap.bindbe synchronous because it does not return ChannelFuture, but rather a channel. If so, then I see no way to do asynchronous binding using the class ServerBootstrap. Am I missing something or will I have to roll my decision?

Regards

+5
source share
2 answers

I finished my own bootstrap implementation with the following addition:

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;
}
+4
source

All Articles