First, here's a reference to where I read all of what I know now regarding this question: http://docs.jboss.org/netty/3.2/api/org/jboss/netty/bootstrap/ServerBootstrap.html#bind%28%29
Although not explicitly specified by the documentation, it would seem that ServerBootstrap.bind
is synchronous - because it does not return a ChannelFuture
, but rather a Channel. If that is the case, then I do not see any way to make an asynchronous bind using the ServerBootstrap
class. Am I missing something or will I have to roll my own solution?
Best regards
I ended up rolling 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With