ConnectionInfo getConnectionInfo()

in alloydb-jdbc-connector/src/main/java/com/google/cloud/alloydb/Refresher.java [113:146]


  ConnectionInfo getConnectionInfo(long timeoutMs) {
    ListenableFuture<ConnectionInfo> f;
    synchronized (connectionInfoGuard) {
      if (closed) {
        throw new IllegalStateException("Connection closed");
      }
      f = current;
    }

    try {
      return f.get(timeoutMs, TimeUnit.MILLISECONDS);
    } catch (TimeoutException e) {
      synchronized (connectionInfoGuard) {
        if (currentRefreshFailure != null) {
          throw new RuntimeException(
              String.format(
                      "Unable to get valid instance data within %d ms."
                          + " Last refresh attempt failed:",
                      timeoutMs)
                  + currentRefreshFailure.getMessage(),
              currentRefreshFailure);
        }
      }
      throw new RuntimeException(
          String.format(
              "Unable to get valid instance data within %d ms. No refresh has completed.",
              timeoutMs),
          e);
    } catch (ExecutionException | InterruptedException ex) {
      Throwable cause = ex.getCause();
      Throwables.throwIfUnchecked(cause);
      throw new RuntimeException(cause);
    }
  }