Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public abstract class S3V4RestSignerClient
@SuppressWarnings("immutables:incompat")
private static volatile RESTClient httpClient;

@SuppressWarnings("immutables:incompat")
private static volatile Cache<String, AuthSession> authSessionCache;

public abstract Map<String, String> properties();

@Value.Default
Expand Down Expand Up @@ -135,24 +138,33 @@ ScheduledExecutorService tokenRefreshExecutor() {
return tokenRefreshExecutor;
}

@Value.Lazy
Cache<String, AuthSession> authSessionCache() {
long expirationIntervalMs =
PropertyUtil.propertyAsLong(
properties(),
CatalogProperties.AUTH_SESSION_TIMEOUT_MS,
CatalogProperties.AUTH_SESSION_TIMEOUT_MS_DEFAULT);

return Caffeine.newBuilder()
.expireAfterAccess(Duration.ofMillis(expirationIntervalMs))
.removalListener(
(RemovalListener<String, AuthSession>)
(id, auth, cause) -> {
if (null != auth) {
auth.stopRefreshing();
}
})
.build();
private Cache<String, AuthSession> authSessionCache() {
if (null == authSessionCache) {
synchronized (S3V4RestSignerClient.class) {
if (null == authSessionCache) {
long expirationIntervalMs =
PropertyUtil.propertyAsLong(
properties(),
CatalogProperties.AUTH_SESSION_TIMEOUT_MS,
CatalogProperties.AUTH_SESSION_TIMEOUT_MS_DEFAULT);

authSessionCache =
Caffeine.newBuilder()
.expireAfterAccess(Duration.ofMillis(expirationIntervalMs))
.removalListener(
(RemovalListener<String, AuthSession>)
(id, auth, cause) -> {
if (null != auth) {
LOG.trace("Stopping refresh for AuthSession");
auth.stopRefreshing();
}
})
.build();
}
}
}

return authSessionCache;
}

private RESTClient httpClient() {
Expand Down