Skip to content

Commit 327d81e

Browse files
author
Dave Syer
committed
Replace Guava with Caffeine in Spring jar
Signed-off-by: Dave Syer <dsyer@vmware.com>
1 parent 6eb8df2 commit 327d81e

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

spring/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<groupId>org.springframework.boot</groupId>
4040
<artifactId>spring-boot-actuator</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>com.github.ben-manes.caffeine</groupId>
44+
<artifactId>caffeine</artifactId>
45+
</dependency>
4246

4347
<dependency>
4448
<groupId>junit</groupId>

spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,35 @@
1212
*/
1313
package io.kubernetes.client.spring.extended.network.endpoints;
1414

15-
import com.google.common.cache.Cache;
16-
import com.google.common.cache.CacheBuilder;
1715
import io.kubernetes.client.apimachinery.NamespaceName;
1816
import io.kubernetes.client.openapi.ApiClient;
17+
import io.kubernetes.client.openapi.ApiException;
1918
import io.kubernetes.client.openapi.apis.CoreV1Api;
2019
import io.kubernetes.client.openapi.models.V1Endpoints;
2120
import java.time.Duration;
22-
import java.util.concurrent.ExecutionException;
21+
22+
import com.github.benmanes.caffeine.cache.Cache;
23+
import com.github.benmanes.caffeine.cache.Caffeine;
24+
2325
import org.springframework.beans.factory.annotation.Autowired;
2426

2527
public class PollingEndpointsGetter implements EndpointsGetter {
2628

27-
private static final Cache<NamespaceName, V1Endpoints> lastObservedEndpoints =
28-
CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).build();
29+
private static final Cache<NamespaceName, V1Endpoints> lastObservedEndpoints = Caffeine.newBuilder()
30+
.expireAfterWrite(Duration.ofMinutes(5)).build();
2931

30-
@Autowired private ApiClient apiClient;
32+
@Autowired
33+
private ApiClient apiClient;
3134

3235
@Override
3336
public V1Endpoints get(String namespace, String name) {
3437
CoreV1Api coreV1Api = new CoreV1Api(apiClient);
35-
try {
36-
return lastObservedEndpoints.get(
37-
new NamespaceName(namespace, name),
38-
() -> {
39-
return coreV1Api.readNamespacedEndpoints(name, namespace, null, null, null);
40-
});
41-
} catch (ExecutionException e) {
42-
throw new RuntimeException(e);
43-
}
38+
return lastObservedEndpoints.get(new NamespaceName(namespace, name), k -> {
39+
try {
40+
return coreV1Api.readNamespacedEndpoints(name, namespace, null, null, null);
41+
} catch (ApiException e) {
42+
throw new IllegalStateException(e);
43+
}
44+
});
4445
}
4546
}

0 commit comments

Comments
 (0)