Skip to content

Commit

Permalink
eliminate usages of guava except loadbalancer, update guava version
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gordineer committed Nov 14, 2023
1 parent a634f1d commit 80e836d
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 122 deletions.
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ rx_java_version=1.0.9
rx_netty_version=0.4.9
servo_version=0.10.1
hystrix_version=1.4.3
guava_version=19.0
archaius_version=0.7.6
eureka_version=1.7.2
jersey_version=1.19.1
Expand Down
1 change: 0 additions & 1 deletion ribbon-archaius/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dependencies {
api "org.slf4j:slf4j-api:${slf4j_version}"
api 'com.google.code.findbugs:annotations:2.0.0'
api "com.google.guava:guava:${guava_version}"
api 'commons-configuration:commons-configuration:1.8'
api 'commons-lang:commons-lang:2.6'
api "com.netflix.archaius:archaius-core:${archaius_version}"
Expand Down
1 change: 0 additions & 1 deletion ribbon-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dependencies {
api "org.slf4j:slf4j-api:${slf4j_version}"
api 'com.google.code.findbugs:annotations:2.0.0'
api "com.google.guava:guava:${guava_version}"
api 'commons-lang:commons-lang:2.6'

testImplementation 'junit:junit:4.11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*/
package com.netflix.client;

import com.google.common.collect.Lists;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;

import java.net.ConnectException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -36,12 +37,12 @@
public class DefaultLoadBalancerRetryHandler implements RetryHandler {

@SuppressWarnings("unchecked")
private List<Class<? extends Throwable>> retriable =
Lists.<Class<? extends Throwable>>newArrayList(ConnectException.class, SocketTimeoutException.class);
private List<Class<? extends Throwable>> retriable =
new ArrayList<>(Arrays.asList(ConnectException.class, SocketTimeoutException.class));

@SuppressWarnings("unchecked")
private List<Class<? extends Throwable>> circuitRelated =
Lists.<Class<? extends Throwable>>newArrayList(SocketException.class, SocketTimeoutException.class);
new ArrayList<>(Arrays.asList(SocketException.class, SocketTimeoutException.class));

protected final int retrySameServer;
protected final int retryNextServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.netflix.client;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Objects;
import java.net.SocketException;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;

/**
* Implementation of RetryHandler created for each request which allows for request
Expand All @@ -22,15 +21,15 @@ public class RequestSpecificRetryHandler implements RetryHandler {
private final boolean okToRetryOnConnectErrors;
private final boolean okToRetryOnAllErrors;

protected List<Class<? extends Throwable>> connectionRelated =
Lists.<Class<? extends Throwable>>newArrayList(SocketException.class);
protected List<Class<? extends Throwable>> connectionRelated =
Collections.singletonList(SocketException.class);

public RequestSpecificRetryHandler(boolean okToRetryOnConnectErrors, boolean okToRetryOnAllErrors) {
this(okToRetryOnConnectErrors, okToRetryOnAllErrors, RetryHandler.DEFAULT, null);
}

public RequestSpecificRetryHandler(boolean okToRetryOnConnectErrors, boolean okToRetryOnAllErrors, RetryHandler baseRetryHandler, @Nullable IClientConfig requestConfig) {
Preconditions.checkNotNull(baseRetryHandler);
Objects.requireNonNull(baseRetryHandler);
this.okToRetryOnConnectErrors = okToRetryOnConnectErrors;
this.okToRetryOnAllErrors = okToRetryOnAllErrors;
this.fallback = baseRetryHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
package com.netflix.client.config;

import com.google.common.reflect.TypeToken;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
Expand All @@ -28,8 +26,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static com.google.common.base.Preconditions.checkArgument;

public abstract class CommonClientConfigKey<T> implements IClientConfigKey<T> {

public static final String DEFAULT_NAME_SPACE = "ribbon";
Expand Down Expand Up @@ -248,20 +244,20 @@ public Class type() {

private final String configKey;
private final Class<T> type;
private T defaultValue;
private final T defaultValue;

@SuppressWarnings("unchecked")
protected CommonClientConfigKey(String configKey) {
this(configKey, null);
}

@SuppressWarnings("unchecked")
protected CommonClientConfigKey(String configKey, T defaultValue) {
this.configKey = configKey;
Type superclass = getClass().getGenericSuperclass();
checkArgument(superclass instanceof ParameterizedType,
"%s isn't parameterized", superclass);
Type runtimeType = ((ParameterizedType) superclass).getActualTypeArguments()[0];
type = (Class<T>) TypeToken.of(runtimeType).getRawType();
if (!(superclass instanceof ParameterizedType)) {
throw new IllegalArgumentException(superclass + " isn't parameterized");
}
this.type = (Class<T>) ((ParameterizedType) superclass).getActualTypeArguments()[0];
this.defaultValue = defaultValue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.netflix.client.config;

import com.google.common.base.Preconditions;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -159,7 +159,7 @@ interface ReloadableProperty<T> extends Property<T> {
}

private synchronized <T> Property<T> getOrCreateProperty(final IClientConfigKey<T> key, final Supplier<Optional<T>> valueSupplier, final Supplier<T> defaultSupplier) {
Preconditions.checkNotNull(valueSupplier, "defaultValueSupplier cannot be null");
Objects.requireNonNull(valueSupplier, "defaultValueSupplier cannot be null");

return (Property<T>)dynamicProperties.computeIfAbsent(key, ignore -> new ReloadableProperty<T>() {
private volatile Optional<T> current = Optional.empty();
Expand Down Expand Up @@ -355,7 +355,7 @@ protected final <T> void setDefault(IClientConfigKey<T> key) {
* Store the default value for key while giving precedence to default values in the property resolver
*/
protected final <T> void setDefault(IClientConfigKey<T> key, T value) {
Preconditions.checkArgument(key != null, "key cannot be null");
Objects.requireNonNull(key, "key cannot be null");

value = resolveFromPropertyResolver(key).orElse(value);
internalProperties.put(key, Optional.ofNullable(value));
Expand All @@ -367,7 +367,7 @@ protected final <T> void setDefault(IClientConfigKey<T> key, T value) {

@Override
public <T> IClientConfig set(IClientConfigKey<T> key, T value) {
Preconditions.checkArgument(key != null, "key cannot be null");
Objects.requireNonNull(key, "key cannot be null");

value = resolveValueToType(key, value);
if (isDynamic) {
Expand All @@ -384,7 +384,7 @@ public <T> IClientConfig set(IClientConfigKey<T> key, T value) {
@Override
@Deprecated
public void setProperty(IClientConfigKey key, Object value) {
Preconditions.checkArgument(value != null, "Value may not be null");
Objects.requireNonNull(value, "Value may not be null");
set(key, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

/**
* Secure socket factory that is used the NIWS code if a non-standard key store or trust store
* is specified.
Expand Down Expand Up @@ -100,8 +97,11 @@ private static KeyStore createKeyStore(final URL storeFile, final String passwor
if(storeFile == null){
return null;
}

Preconditions.checkArgument(StringUtils.isNotEmpty(password), "Null keystore should have empty password, defined keystore must have password");

if (StringUtils.isEmpty(password)) {
throw new IllegalArgumentException(
"Null keystore should have empty password, defined keystore must have password");
}

KeyStore keyStore = null;

Expand Down Expand Up @@ -139,13 +139,17 @@ public String toString() {

builder.append("ClientSslSocketFactory [trustStoreUrl=").append(trustStoreUrl);
if (trustStoreUrl != null) {
builder.append(", trustStorePassword=");
builder.append(Strings.repeat("*", this.getTrustStorePasswordLength()));
builder.append(", trustStorePassword=");
for (int i = 0; i < this.getTrustStorePasswordLength(); i++) {
builder.append("*");
}
}
builder.append(", keyStoreUrl=").append(keyStoreUrl);
if (keyStoreUrl != null) {
builder.append(", keystorePassword = ");
builder.append(Strings.repeat("*", this.getKeyStorePasswordLength()));
for (int i = 0; i < this.getKeyStorePasswordLength(); i++) {
builder.append("*");
}
}
builder.append(']');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import static org.junit.Assert.*;


import org.junit.Test;

import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.HashSet;

public class CommonClientConfigKeyTest {

@Test
public void testCommonKeys() {
IClientConfigKey[] keys = CommonClientConfigKey.values();
assertTrue(keys.length > 30);
assertEquals(Sets.newHashSet(keys), CommonClientConfigKey.keys());
assertEquals(new HashSet<>(Arrays.asList(keys)), CommonClientConfigKey.keys());
assertTrue(CommonClientConfigKey.keys().contains(CommonClientConfigKey.ConnectTimeout));
}
}
1 change: 0 additions & 1 deletion ribbon-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
api 'org.codehaus.jackson:jackson-mapper-asl:1.9.11'
api 'com.thoughtworks.xstream:xstream:1.4.5'
api "com.sun.jersey:jersey-server:${jersey_version}"
api "com.google.guava:guava:${guava_version}"
api "com.netflix.archaius:archaius-core:${archaius_version}"
testImplementation 'junit:junit:4.11'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.Consumes;
Expand All @@ -34,7 +35,6 @@

import org.codehaus.jackson.map.ObjectMapper;

import com.google.common.collect.Lists;
import com.thoughtworks.xstream.XStream;

@Path("/testAsync")
Expand Down Expand Up @@ -89,9 +89,9 @@ public boolean equals(Object obj) {
private static ObjectMapper mapper = new ObjectMapper();
public static final Person defaultPerson = new Person("ribbon", 1);

public static final List<Person> persons = Lists.newArrayList();
public static final List<Person> persons = new ArrayList<>();

public static final List<String> streamContent = Lists.newArrayList();
public static final List<String> streamContent = new ArrayList<>();

static {
for (int i = 0; i < 1000; i++) {
Expand Down
1 change: 0 additions & 1 deletion ribbon-httpclient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies {
api "com.sun.jersey.contribs:jersey-apache-client4:${jersey_version}"
api "org.slf4j:slf4j-api:${slf4j_version}"
api "com.netflix.servo:servo-core:${servo_version}"
api "com.google.guava:guava:${guava_version}"
api 'com.netflix.netflix-commons:netflix-commons-util:0.1.1'
testImplementation 'junit:junit:4.11'
testImplementation "org.slf4j:slf4j-log4j12:${slf4j_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.AbstractMap.SimpleEntry;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

public class CaseInsensitiveMultiMap implements HttpHeaders {
Expand All @@ -26,7 +25,7 @@ public String getFirstValue(String headerName) {
@Override
public List<String> getAllValues(String headerName) {
Collection<Entry<String, String>> entries = map.get(headerName.toLowerCase());
List<String> values = Lists.newArrayList();
List<String> values = new ArrayList<>();
if (entries != null) {
for (Entry<String, String> entry: entries) {
values.add(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.netflix.niws.client.http;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken;
import com.netflix.client.ClientException;
Expand All @@ -28,15 +27,12 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;

import java.util.Map.Entry;
import javax.ws.rs.core.MultivaluedMap;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.*;

/**
* A NIWS Client Response
Expand Down Expand Up @@ -74,7 +70,7 @@ public List<String> getAllValues(String headerName) {
@Override
public List<Entry<String, String>> getAllHeaders() {
MultivaluedMap<String, String> map = bcr.getHeaders();
List<Entry<String, String>> result = Lists.newArrayList();
List<Entry<String, String>> result = new ArrayList<>();
for (Map.Entry<String, List<String>> header: map.entrySet()) {
String name = header.getKey();
for (String value: header.getValue()) {
Expand Down
2 changes: 1 addition & 1 deletion ribbon-loadbalancer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ dependencies {
api "io.reactivex:rxjava:${rx_java_version}"
api "org.slf4j:slf4j-api:${slf4j_version}"
api "com.netflix.servo:servo-core:${servo_version}"
api "com.google.guava:guava:${guava_version}"
api 'com.netflix.netflix-commons:netflix-commons-util:0.1.1'
api "com.google.guava:guava:32.1.3-jre"

testImplementation project(":ribbon-archaius")
testImplementation 'junit:junit:4.11'
Expand Down
Loading

0 comments on commit 80e836d

Please sign in to comment.