private int getReplicaCountInState(ReplicaState state) {
    // Scan the whole map only when it's OFFLINE state. Other gauges should be able to read cached result from
    // replicaCountByState map.
    if (state == ReplicaState.OFFLINE) {
      Map<ReplicaState, Integer> replicaStateAndCount = new HashMap<>();
      EnumSet.complementOf(EnumSet.of(ReplicaState.DROPPED))
          .forEach(replicaState -> replicaStateAndCount.put(replicaState, 0));
      for (ReplicaState replicaState : localPartitionAndState.values()) {
        replicaStateAndCount.put(replicaState, replicaStateAndCount.get(replicaState) + 1);
      }
      // reference switch should be atomic
      replicaCountByState = replicaStateAndCount;
    }
    return replicaCountByState.get(state);
  }
Get the number of replicas in given state.
@param state the {@link ReplicaState} associated with local replica.
@return number of replicas in given state
ambry-clustermap/src/main/java/com/github/ambry/clustermap/HelixParticipantMetrics.java