super(manager, handler, group);
}
public IoConnectFuture connect(SocketAddress address) {
logger.debug("Connecting to {}", address);
final IoConnectFuture future = new DefaultIoConnectFuture(null);
try {
final AsynchronousSocketChannel socket = AsynchronousSocketChannel.open(group);
socket.connect(address, null, new Nio2CompletionHandler<Void, Object>() {
protected void onCompleted(Void result, Object attachment) {
try {
Nio2Session session = new Nio2Session(Nio2Connector.this, handler, socket);
handler.sessionCreated(session);
sessions.put(session.getId(), session);
future.setSession(session);
session.startReading();
} catch (Throwable e) {
try {
socket.close();
} catch (IOException t) {
// Ignore
}
future.setException(e);
}
}
protected void onFailed(final Throwable exc, final Object attachment) {
future.setException(exc);
}
});
} catch (IOException exc) {
future.setException(exc);
}
return future;
}