Skip to content
Prev Previous commit
Next Next commit
progress
  • Loading branch information
nehrao1 committed Dec 26, 2024
commit b2b9b8f0e8989e81cffb2f628cd1bc8b9b5c9454
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public final class GatewayConnectionConfig {
private int maxConnectionPoolSize;
private Duration idleConnectionTimeout;
private ProxyOptions proxy;
private boolean thinclientEnabled;

/**
* Constructor.
Expand All @@ -33,7 +32,6 @@ public GatewayConnectionConfig() {
this.idleConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
this.maxConnectionPoolSize = Configs.getDefaultHttpPoolSize();
this.networkRequestTimeout = DEFAULT_NETWORK_REQUEST_TIMEOUT;
this.thinclientEnabled = false;
}

/**
Expand All @@ -45,13 +43,6 @@ public static GatewayConnectionConfig getDefaultConfig() {
return new GatewayConnectionConfig();
}

public boolean getThinClientEnabled() { return this.thinclientEnabled; }

public GatewayConnectionConfig setThinClientEnabled(final boolean enabled) {
this.thinclientEnabled = enabled;
return this;
}

/**
* Gets the network request timeout interval (time to wait for response from network peer).
* The default is 60 seconds.
Expand Down Expand Up @@ -156,7 +147,6 @@ public String toString() {
", networkRequestTimeout=" + networkRequestTimeout +
", proxyType=" + proxyType +
", inetSocketProxyAddress=" + proxyAddress +
", thinclientEnabled=" + thinclientEnabled +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public class Configs {

private static final String UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS = "COSMOS.UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS";
private static final String GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS = "COSMOS.GLOBAL_ENDPOINT_MANAGER_MAX_INIT_TIME_IN_SECONDS";
private static final String THINCLIENT_ENDPOINT = "COSMOS.THINCLIENT_ENDPOINT"; // Environment variable for now
// Environment variable for now
private static final String THINCLIENT_ENDPOINT = "COSMOS.THINCLIENT_ENDPOINT";
private static final String DEFAULT_THINCLIENT_ENDPOINT = "COSMOS.DEFAULT_THINCLIENT_ENDPOINT";
private static final String THINCLIENT_ENABLED = "COSMOS.THINCLIENT_ENABLED";

private static final String MAX_HTTP_BODY_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_BODY_LENGTH_IN_BYTES";
private static final String MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES";
Expand Down Expand Up @@ -366,8 +369,11 @@ public int getGlobalEndpointManagerMaxInitializationTimeInSeconds() {

// Temporary. Thinclient endpoint discovery to be done through GetDatabaseAccount API
public URI getThinclientEndpoint() {
String uriString = System.getProperty("COSMOS.THINCLIENT_ENDPOINT");
return URI.create(Objects.requireNonNullElse(uriString, "testThinClientEndpoint"));
return getJVMConfigAsURI(THINCLIENT_ENDPOINT, DEFAULT_THINCLIENT_ENDPOINT);
}

public boolean getThinclientEnabled() {
return getJVMConfigAsBoolean(THINCLIENT_ENABLED, false);
}

public int getUnavailableLocationsExpirationTimeInSeconds() {
Expand Down Expand Up @@ -558,6 +564,11 @@ private static boolean getJVMConfigAsBoolean(String propName, boolean defaultVal
return getBooleanValue(propValue, defaultValue);
}

private static URI getJVMConfigAsURI(String propName, String defaultValue) {
String propValue = System.getProperty(propName); // "COSMOS.THINCLIENT_ENDPOINT"
return getUriValue(propValue, defaultValue); // "testThinClientEndpoint"
}

private static int getIntValue(String val, int defaultValue) {
if (StringUtils.isEmpty(val)) {
return defaultValue;
Expand All @@ -574,6 +585,14 @@ private static boolean getBooleanValue(String val, boolean defaultValue) {
}
}

private static URI getUriValue(String val, String defaultValue) {
if (StringUtils.isEmpty(val)) {
return URI.create(defaultValue);
} else {
return URI.create(val);
}
}

public static boolean isReplicaAddressValidationEnabled() {
return getJVMConfigAsBoolean(
REPLICA_ADDRESS_VALIDATION_ENABLED,
Expand Down