in src/main/java/com/twitter/whiskey/net/SessionManager.java [145:186]
private void createSocket(final int connectivity) {
final Socket socket;
if (secure) {
SSLEngine engine;
try {
engine = newSslEngine();
} catch (NoSuchAlgorithmException e) {
if (openSessionMap.isEmpty()) {
failOperations(new ConnectException("SSLContext unavailable"));
}
return;
}
socket = new SSLSocket(origin, RunLoop.instance(), engine);
} else {
socket = new Socket(origin, RunLoop.instance());
}
pendingSocketMap.put(connectivity, socket);
socket.connect().addListener(new Inline.Listener<Origin>() {
@Override
public void onComplete(Origin result) {
pendingSocketMap.removeValue(socket);
createSession(socket);
}
@Override
public void onError(Throwable throwable) {
pendingSocketMap.removeValue(socket);
// If connectivity has changed operations may still succeed.
// Otherwise, if there are no more pending sockets assume we
// can't connect for now and fail operations.
if (SessionManager.this.connectivity == connectivity &&
(!pendingSocketMap.containsKey(connectivity) || pendingSocketMap.get(connectivity).isEmpty()) &&
openSessionMap.isEmpty()) {
failOperations(throwable);
}
}
});
}