private void updateCachedHostWeightPairsPropertiesForRoundRobinClusterInfo()

in wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java [216:251]


  private void updateCachedHostWeightPairsPropertiesForRoundRobinClusterInfo(
      final @NonNull RoundRobinClusterInfo roundRobinClusterInfo,
      final @Nullable Properties props) throws SQLException {
    if (props != null) {
      final String hostWeights = ROUND_ROBIN_HOST_WEIGHT_PAIRS.getString(props);
      if (!StringUtils.isNullOrEmpty(hostWeights)) {
        final String[] hostWeightPairs = hostWeights.split(",");
        for (final String pair : hostWeightPairs) {
          final Matcher matcher = HOST_WEIGHT_PAIRS_PATTERN.matcher(pair);
          if (!matcher.matches()) {
            throw new SQLException(Messages.get("HostSelector.roundRobinInvalidHostWeightPairs"));
          }

          final String hostName = matcher.group("host").trim();
          final String hostWeight = matcher.group("weight").trim();
          if (hostName.isEmpty() || hostWeight.isEmpty()) {
            throw new SQLException(Messages.get("HostSelector.roundRobinInvalidHostWeightPairs"));
          }

          try {
            final int weight = Integer.parseInt(hostWeight);
            if (weight < DEFAULT_WEIGHT) {
              throw new SQLException(Messages.get("HostSelector.roundRobinInvalidHostWeightPairs"));
            }
            roundRobinClusterInfo.clusterWeightsMap.put(hostName, weight);
          } catch (NumberFormatException e) {
            throw new SQLException(Messages.get("HostSelector.roundRobinInvalidHostWeightPairs"));
          }
        }
        roundRobinClusterInfo.lastClusterHostWeightPairPropertyValue = ROUND_ROBIN_HOST_WEIGHT_PAIRS.getString(props);
      } else if (hostWeights != null && hostWeights.isEmpty()) {
        roundRobinClusterInfo.clusterWeightsMap.clear();
        roundRobinClusterInfo.lastClusterHostWeightPairPropertyValue = ROUND_ROBIN_HOST_WEIGHT_PAIRS.getString(props);
      }
    }
  }