private createCacheEntryForHosts()

in common/lib/round_robin_host_selector.ts [96:136]


  private createCacheEntryForHosts(hosts: HostInfo[], props?: Map<string, any>) {
    const hostsWithCacheEntry: HostInfo[] = [];
    hosts.forEach((host) => {
      if (RoundRobinHostSelector.roundRobinCache.get(host.host)) {
        hostsWithCacheEntry.push(host);
      }
    });

    // If there is a host with an existing entry, update the cache entries for all hosts to point each to the same
    // RoundRobinClusterInfo object. If there are no cache entries, create a new RoundRobinClusterInfo.
    if (hostsWithCacheEntry.length > 0) {
      const roundRobinClusterInfo = RoundRobinHostSelector.roundRobinCache.get(hostsWithCacheEntry[0].host);
      if (
        roundRobinClusterInfo &&
        this.hasPropertyChanged(roundRobinClusterInfo.lastClusterHostWeightPairPropertyValue, WrapperProperties.ROUND_ROBIN_HOST_WEIGHT_PAIRS, props)
      ) {
        roundRobinClusterInfo.lastHost = null;
        roundRobinClusterInfo.weightCounter = 0;
        this.updateCachedHostWeightPairsPropertiesForRoundRobinClusterInfo(roundRobinClusterInfo, props);
      }

      if (
        roundRobinClusterInfo &&
        roundRobinClusterInfo.lastClusterDefaultWeightPropertyValue &&
        this.hasPropertyChanged(roundRobinClusterInfo.lastClusterDefaultWeightPropertyValue, WrapperProperties.ROUND_ROBIN_DEFAULT_WEIGHT, props)
      ) {
        roundRobinClusterInfo.defaultWeight = 1;
        this.updateCachedDefaultWeightPropertiesForRoundRobinClusterInfo(roundRobinClusterInfo, props);
      }

      hosts.forEach((host) => {
        RoundRobinHostSelector.roundRobinCache.put(host.host, roundRobinClusterInfo!, RoundRobinHostSelector.DEFAULT_ROUND_ROBIN_CACHE_EXPIRE_NANO);
      });
    } else {
      const roundRobinClusterInfo = new RoundRobinClusterInfo();
      this.updateCachePropertiesForRoundRobinClusterInfo(roundRobinClusterInfo, props);
      hosts.forEach((host) => {
        RoundRobinHostSelector.roundRobinCache.put(host.host, roundRobinClusterInfo, RoundRobinHostSelector.DEFAULT_ROUND_ROBIN_CACHE_EXPIRE_NANO);
      });
    }
  }