preConfigure(newConnection);
newConnection.setProcessor(getProcessor());
newConnection.setProcessorSelector(getProcessorSelector());
final NIOChannelDistributor nioChannelDistributor =
nioTransport.getNIOChannelDistributor();
if (nioChannelDistributor == null) {
throw new IllegalStateException(
"NIOChannelDistributor is null. Is Transport running?");
}
final CompletionHandler<Connection> completionHandlerToPass;
final FutureImpl<Connection> futureToReturn;
if (needFuture) {
futureToReturn = makeCancellableFuture(newConnection);
completionHandlerToPass = Futures.toCompletionHandler(
futureToReturn, completionHandler);
} else {
completionHandlerToPass = completionHandler;
futureToReturn = null;
}
// if connected immediately - register channel on selector with NO_INTEREST
// interest
nioChannelDistributor.registerChannelAsync(datagramChannel,
0, newConnection,
new ConnectHandler(newConnection, completionHandlerToPass));
return futureToReturn;
} catch (Exception e) {