in core/src/main/java/com/google/cloud/sql/core/DefaultConnectionInfoRepository.java [133:185]
public ListenableFuture<ConnectionInfo> getConnectionInfo(
CloudSqlInstanceName instanceName,
AccessTokenSupplier accessTokenSupplier,
AuthType authType,
ListeningScheduledExecutorService executor,
ListenableFuture<KeyPair> keyPair) {
ListenableFuture<Optional<AccessToken>> token = executor.submit(accessTokenSupplier::get);
// Fetch the metadata
ListenableFuture<InstanceMetadata> metadataFuture =
executor.submit(() -> fetchMetadata(instanceName, authType));
// Fetch the ephemeral certificates
ListenableFuture<Certificate> ephemeralCertificateFuture =
Futures.whenAllComplete(keyPair, token)
.call(
() ->
fetchEphemeralCertificate(
Futures.getDone(keyPair), instanceName, Futures.getDone(token), authType),
executor);
// Once the API calls are complete, construct the SSLContext for the sockets
ListenableFuture<SslData> sslContextFuture =
Futures.whenAllComplete(metadataFuture, ephemeralCertificateFuture)
.call(
() ->
createSslData(
Futures.getDone(keyPair),
Futures.getDone(metadataFuture),
Futures.getDone(ephemeralCertificateFuture),
instanceName,
authType),
executor);
// Once both the SSLContext and Metadata are complete, return the results
ListenableFuture<ConnectionInfo> done =
Futures.whenAllComplete(metadataFuture, ephemeralCertificateFuture, sslContextFuture)
.call(
() ->
createConnectionInfo(
instanceName,
authType,
Futures.getDone(token),
Futures.getDone(metadataFuture),
Futures.getDone(ephemeralCertificateFuture),
Futures.getDone(sslContextFuture)),
executor);
done.addListener(
() -> logger.debug(String.format("[%s] ALL FUTURES DONE", instanceName)), executor);
return done;
}