public void handle(final AsyncResult<NetSocket> asyncSocket) {
if( !asyncSocket.succeeded() ) {
handleConnectFailure(socketFromClient, String.format("Could not connect to '%s'", url));
} else {
final NetSocket socketToServer = asyncSocket.result();
successfulConnectionAttempts.incrementAndGet();
socketsConnecting.remove(socketFromClient);
final ConnectedSocketInfo connectedInfo = new ConnectedSocketInfo(params, url, socketFromClient, socketToServer);
socketsConnected.add(connectedInfo);
Handler<Void> endHandler = new Handler<Void>() {
@Override
public void handle(Void event) {
handleShutdown(connectedInfo);
}
};
Handler<Throwable> exceptionHandler = new Handler<Throwable>() {
@Override
public void handle(Throwable event) {
handleShutdown(connectedInfo);
}
};
socketFromClient.readStream().endHandler(endHandler);
socketFromClient.readStream().exceptionHandler(exceptionHandler);
socketToServer.endHandler(endHandler);
socketToServer.exceptionHandler(exceptionHandler);
socketToServer.write(received);
Pump.createPump(socketToServer, socketFromClient.writeStream()).start();
Pump.createPump(socketFromClient.readStream(), socketToServer).start();
}
}
});