public ReaderFailoverResult call()

in wrapper/src/main/java/software/amazon/jdbc/plugin/failover/ClusterAwareReaderFailoverHandler.java [382:449]


    public ReaderFailoverResult call() {
      LOGGER.fine(
          () -> Messages.get(
              "ClusterAwareReaderFailoverHandler.attemptingReaderConnection",
              new Object[] {this.newHost.getUrl(), PropertyUtils.maskProperties(initialConnectionProps)}));

      try {
        final Properties copy = new Properties();
        copy.putAll(initialConnectionProps);

        final Connection conn = pluginService.forceConnect(this.newHost, copy);
        pluginService.setAvailability(this.newHost.asAliases(), HostAvailability.AVAILABLE);

        if (this.isStrictReaderRequired) {
          // need to ensure that new connection is a connection to a reader node
          try {
            HostRole role = pluginService.getHostRole(conn);
            if (!HostRole.READER.equals(role)) {
              LOGGER.fine(
                  Messages.get(
                      "ClusterAwareReaderFailoverHandler.readerRequired",
                      new Object[]{ this.newHost.getUrl(), role }));

              try {
                conn.close();
              } catch (final SQLException innerException) {
                // ignore
              }

              return FAILED_READER_FAILOVER_RESULT;
            }
          } catch (SQLException e) {
            LOGGER.fine(Messages.get("ClusterAwareReaderFailoverHandler.errorGettingHostRole", new Object[]{e}));

            try {
              conn.close();
            } catch (final SQLException innerException) {
              // ignore
            }

            return FAILED_READER_FAILOVER_RESULT;
          }
        }

        LOGGER.fine(
            () -> Messages.get(
                "ClusterAwareReaderFailoverHandler.successfulReaderConnection",
                new Object[] {this.newHost.getUrl()}));
        LOGGER.fine("New reader failover connection object: " + conn);
        return new ReaderFailoverResult(conn, this.newHost, true);
      } catch (final SQLException e) {
        pluginService.setAvailability(newHost.asAliases(), HostAvailability.NOT_AVAILABLE);
        LOGGER.fine(
            () -> Messages.get(
                "ClusterAwareReaderFailoverHandler.failedReaderConnection",
                new Object[] {this.newHost.getUrl()}));
        // Propagate exceptions that are not caused by network errors.
        if (!pluginService.isNetworkException(e)) {
          return new ReaderFailoverResult(
              null,
              null,
              false,
              e);
        }

        return FAILED_READER_FAILOVER_RESULT;
      }
    }