Skip to content

Commit

Permalink
loadbalancer-experimental-provider: use System.getProperty directly (#…
Browse files Browse the repository at this point in the history
…2922)

Motivation:

We unnecessarily pass in and set a Properties in the
DefaultLoadBalancerProviderConfig constructor that is only used
in the constructor. This doesn't buy anything but noise.

Modifications:

Just use the System.getProperty and related methods.
  • Loading branch information
bryce-anderson authored May 13, 2024
1 parent 6f12039 commit a75d9fa
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@

import java.time.Duration;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import static java.time.Duration.ZERO;
import static java.time.Duration.ofMillis;
import static java.time.Duration.ofSeconds;
import static java.util.Objects.requireNonNull;

final class DefaultLoadBalancerProviderConfig {

Expand Down Expand Up @@ -69,8 +67,6 @@ private enum LBPolicy {

static final DefaultLoadBalancerProviderConfig INSTANCE = new DefaultLoadBalancerProviderConfig();

private final Properties properties;

private final String rawClientsEnabledFor;
private final Set<String> clientsEnabledFor;
private final int failedConnectionsThreshold;
Expand All @@ -93,11 +89,6 @@ private enum LBPolicy {
private final Duration ejectionTimeJitter;

private DefaultLoadBalancerProviderConfig() {
this(System.getProperties());
}

private DefaultLoadBalancerProviderConfig(Properties properties) {
this.properties = requireNonNull(properties, "properties");
rawClientsEnabledFor = getString(PROP_CLIENTS_ENABLED_FOR, "").trim();
clientsEnabledFor = getClientsEnabledFor(rawClientsEnabledFor);
failedConnectionsThreshold = getInt(PROP_FAILED_CONNECTIONS_THRESHOLD, 5 /*ST default*/);
Expand Down Expand Up @@ -191,12 +182,12 @@ public String toString() {
'}';
}

private String getString(String name, String defaultValue) {
return properties.getProperty(PROPERTY_PREFIX + name, defaultValue);
private static String getString(String name, String defaultValue) {
return System.getProperty(PROPERTY_PREFIX + name, defaultValue);
}

private long getLong(String name, long defaultValue) {
String propertyValue = properties.getProperty(PROPERTY_PREFIX + name);
private static long getLong(String name, long defaultValue) {
String propertyValue = System.getProperty(PROPERTY_PREFIX + name);
if (propertyValue == null) {
return defaultValue;
}
Expand All @@ -209,7 +200,7 @@ private long getLong(String name, long defaultValue) {
}
}

private int getInt(String name, int defaultValue) {
private static int getInt(String name, int defaultValue) {
long value = getLong(name, defaultValue);
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Integer overflow for value " + name + ": " + value);
Expand Down

0 comments on commit a75d9fa

Please sign in to comment.