Skip to content

Commit

Permalink
revert 3f354a2
Browse files Browse the repository at this point in the history
  • Loading branch information
SzyWilliam committed Jul 18, 2023
1 parent f978c8f commit a18abf5
Showing 1 changed file with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

package org.apache.ratis.metrics;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting;
import org.apache.ratis.util.ReflectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Predicate;


public final class MetricRegistriesLoader {
private static final Logger LOG = LoggerFactory.getLogger(MetricRegistries.class);
Expand Down Expand Up @@ -72,37 +70,18 @@ static MetricRegistries load(List<MetricRegistries> availableImplementations) {
throw new RuntimeException(e);
}
} else {
return pickUserDefinedMetricRegistries(availableImplementations);
}
}

static MetricRegistries pickUserDefinedMetricRegistries(List<MetricRegistries> availableImplementations) {
MetricRegistries userDefined = null;
if (availableImplementations.size() == 2) {
final Predicate<MetricRegistries> nonDefault = m -> !m.getClass().getCanonicalName().equals(DEFAULT_CLASS);
Optional<MetricRegistries> potential =
availableImplementations.stream().
filter(nonDefault).findAny();
if (potential.isPresent()) {
userDefined = potential.get();
LOG.info("Found user-defined MetricRegistries Implementation: " + userDefined.getClass().getCanonicalName());
}
}
if (userDefined != null) {
return userDefined;
}

// Tell the user they're doing something wrong, and choose the first impl.
StringBuilder sb = new StringBuilder();
for (MetricRegistries factory : availableImplementations) {
if (sb.length() > 0) {
sb.append(", ");
// Tell the user they're doing something wrong, and choose the first impl.
StringBuilder sb = new StringBuilder();
for (MetricRegistries factory : availableImplementations) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(factory.getClass());
}
sb.append(factory.getClass());
LOG.warn("Found multiple MetricRegistries implementations: " + sb
+ ". Using first found implementation: " + availableImplementations.get(0));
return availableImplementations.get(0);
}
LOG.warn("Found multiple MetricRegistries implementations: " + sb
+ ". Using first found implementation: " + availableImplementations.get(0));
return availableImplementations.get(0);
}

private static List<MetricRegistries> getDefinedImplementations() {
Expand Down

0 comments on commit a18abf5

Please sign in to comment.