Skip to content

Commit

Permalink
remove guava
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gordineer committed Nov 23, 2023
1 parent a634f1d commit 822e481
Show file tree
Hide file tree
Showing 64 changed files with 325 additions and 366 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
16 changes: 16 additions & 0 deletions ribbon-core/src/main/java/com/netflix/client/util/ThreadUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.netflix.client.util;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class ThreadUtils {

public static ThreadFactory threadFactory(String name) {
return r -> {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setName(name);
thread.setDaemon(true);
return thread;
};
}
}
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));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.netflix.niws.loadbalancer;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import static com.netflix.client.util.ThreadUtils.threadFactory;

import com.netflix.config.DynamicIntProperty;
import com.netflix.discovery.CacheRefreshedEvent;
import com.netflix.discovery.EurekaClient;
Expand Down Expand Up @@ -45,16 +46,12 @@ private static class LazyHolder {
private LazyHolder() {
int corePoolSize = getCorePoolSize();
defaultServerListUpdateExecutor = new ThreadPoolExecutor(
corePoolSize,
corePoolSize * 5,
0,
TimeUnit.NANOSECONDS,
new ArrayBlockingQueue<Runnable>(queueSizeProp.get()),
new ThreadFactoryBuilder()
.setNameFormat("EurekaNotificationServerListUpdater-%d")
.setDaemon(true)
.build()
);
corePoolSize,
corePoolSize * 5,
0,
TimeUnit.NANOSECONDS,
new ArrayBlockingQueue<Runnable>(queueSizeProp.get()),
threadFactory("EurekaNotificationServerListUpdater-%d"));

poolSizeProp.addCallback(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.netflix.niws.loadbalancer;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import static com.netflix.client.util.ThreadUtils.threadFactory;

import com.netflix.discovery.CacheRefreshedEvent;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaEventListener;
import com.netflix.loadbalancer.ServerListUpdater;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import javax.inject.Provider;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
Expand Down Expand Up @@ -42,11 +44,7 @@ public void setUp() {
0,
TimeUnit.NANOSECONDS,
new ArrayBlockingQueue<Runnable>(1000),
new ThreadFactoryBuilder()
.setNameFormat("EurekaNotificationServerListUpdater-%d")
.setDaemon(true)
.build()
);
threadFactory("EurekaNotificationServerListUpdater-%d"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.netflix.niws.loadbalancer;

import com.google.common.collect.Lists;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig;
Expand All @@ -23,6 +22,9 @@
import com.netflix.loadbalancer.ServerListUpdater;
import com.netflix.loadbalancer.ZoneAffinityServerListFilter;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.apache.commons.configuration.Configuration;
import org.junit.Before;
import org.junit.Ignore;
Expand Down Expand Up @@ -90,7 +92,7 @@ public void testBuildWithDiscoveryEnabledNIWSServerList() {
.withServerListFilter(filter)
.buildDynamicServerListLoadBalancer();
assertNotNull(lb);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
assertEquals(Collections.singletonList(expected), lb.getAllServers());
assertSame(filter, lb.getFilter());
assertSame(list, lb.getServerListImpl());
Server server = lb.chooseServer();
Expand All @@ -111,7 +113,7 @@ public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() {
.withServerListUpdater(updater)
.buildDynamicServerListLoadBalancerWithUpdater();
assertNotNull(lb);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
assertEquals(Collections.singletonList(expected), lb.getAllServers());
assertSame(filter, lb.getFilter());
assertSame(list, lb.getServerListImpl());
assertSame(updater, lb.getServerListUpdater());
Expand Down Expand Up @@ -139,12 +141,12 @@ public void testBuildWithArchaiusProperties() {
assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
assertTrue(dynamicLB.getPing() instanceof DummyPing);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
assertEquals(Collections.singletonList(expected), lb.getAllServers());
}

@Test
public void testBuildStaticServerListLoadBalancer() {
List<Server> list = Lists.newArrayList(expected, expected);
List<Server> list = new ArrayList<>(Arrays.asList(expected, expected));
IRule rule = new AvailabilityFilteringRule();
IClientConfig clientConfig = IClientConfig.Builder.newBuilder()
.withDefaultValues()
Expand Down
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'
}

0 comments on commit 822e481

Please sign in to comment.