cache =
- CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000)
+ Caffeine.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000)
.build();
/**
@@ -117,7 +118,7 @@ public int hashCode() {
*
* Class invariant: Any Token has a corresponding byte array in the database.
*/
- private final Cache canonicalizationCache = CacheBuilder.newBuilder().weakValues()
+ private final Cache canonicalizationCache = Caffeine.newBuilder().weakValues()
.build();
/**
@@ -217,8 +218,8 @@ public byte[] readBytes(Token token) {
*/
private Token makeToken(long id) {
try {
- return canonicalizationCache.get(id, () -> new Token(id));
- } catch (UncheckedExecutionException | ExecutionException e) {
+ return canonicalizationCache.get(id, (key) -> new Token(id));
+ } catch (UncheckedExecutionException | CompletionException e) {
Throwable cause = e.getCause();
Throwables.throwIfUnchecked(cause);
throw new RuntimeException(cause);
diff --git a/modules/dcache-srm/src/main/java/diskCacheV111/srm/dcache/Storage.java b/modules/dcache-srm/src/main/java/diskCacheV111/srm/dcache/Storage.java
index 880d557c8f6..c22518b102c 100644
--- a/modules/dcache-srm/src/main/java/diskCacheV111/srm/dcache/Storage.java
+++ b/modules/dcache-srm/src/main/java/diskCacheV111/srm/dcache/Storage.java
@@ -81,14 +81,13 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import static org.dcache.srm.SRMInvalidPathException.checkValidPath;
import static org.dcache.util.NetworkUtils.isInetAddress;
+import com.github.benmanes.caffeine.cache.CacheLoader;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.base.CharMatcher;
-import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
@@ -161,9 +160,8 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import java.util.Optional;
import java.util.Random;
import java.util.Set;
-import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletionException;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong;
@@ -201,7 +199,6 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import org.dcache.srm.CopyCallbacks;
import org.dcache.srm.FileMetaData;
import org.dcache.srm.RemoveFileCallback;
-import org.dcache.srm.SRMAbortedException;
import org.dcache.srm.SRMAuthorizationException;
import org.dcache.srm.SRMDuplicationException;
import org.dcache.srm.SRMExceedAllocationException;
@@ -256,7 +253,7 @@ public final class Storage
private static final Set FTP_URL_SCHEMATA = Set.of("ftp", "gsiftp", "gkftp");
private static final LoadingCache GET_HOST_BY_ADDR_CACHE =
- CacheBuilder.newBuilder()
+ Caffeine.newBuilder()
.expireAfterWrite(10, MINUTES)
.recordStats()
.build(new GetHostByAddressCacheLoader());
@@ -940,7 +937,7 @@ private String selectHostName(LoginBrokerInfo door, InetAddressScope scope,
resolvedHost = GET_HOST_BY_ADDR_CACHE.get(address);
}
return resolvedHost;
- } catch (ExecutionException e) {
+ } catch (CompletionException e) {
Throwable cause = e.getCause();
throw new SRMInternalErrorException("Failed to resolve door: " + cause, cause);
}
@@ -1032,7 +1029,7 @@ public ListenableFuture prepareToPut(
"Space associated with the space token " + spaceToken
+ " is not enough to hold SURL."));
}
- } catch (ExecutionException e) {
+ } catch (CompletionException e) {
return immediateFailedFuture(new SRMException(
"Failure while querying space reservation: " + e.getCause()
.getMessage()));
@@ -2231,7 +2228,7 @@ public String[] srmGetSpaceTokens(SRMUser user, String description)
_log.trace("srmGetSpaceTokens returns: {}", Arrays.toString(tokens));
}
return Arrays.stream(tokens).mapToObj(Long::toString).toArray(String[]::new);
- } catch (ExecutionException e) {
+ } catch (CompletionException e) {
Throwable cause = e.getCause();
Throwables.throwIfInstanceOf(cause, SRMException.class);
Throwables.throwIfUnchecked(cause);
@@ -2340,7 +2337,7 @@ private static DcacheUser asDcacheUser(SRMUser user) throws SRMAuthorizationExce
return dcacheUser;
}
- private static class GetHostByAddressCacheLoader extends CacheLoader {
+ private static class GetHostByAddressCacheLoader implements CacheLoader {
@Override
public String load(InetAddress address) throws Exception {
diff --git a/modules/dcache-webdav/src/main/java/org/dcache/webdav/DcacheResourceFactory.java b/modules/dcache-webdav/src/main/java/org/dcache/webdav/DcacheResourceFactory.java
index cea7987c0ae..549b82da7be 100644
--- a/modules/dcache-webdav/src/main/java/org/dcache/webdav/DcacheResourceFactory.java
+++ b/modules/dcache-webdav/src/main/java/org/dcache/webdav/DcacheResourceFactory.java
@@ -27,11 +27,11 @@
import static org.dcache.util.TransferRetryPolicy.tryOnce;
import static org.dcache.webdav.InsufficientStorageException.checkStorageSufficient;
+import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.base.Throwables;
-import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
@@ -106,6 +106,7 @@
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;
+import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -1614,7 +1615,7 @@ FileLocality calculateLocality(FileAttributes attributes, String clientIP) {
private Optional lookupSpaceById(String id) {
try {
return _spaceLookupCache.get(id);
- } catch (ExecutionException e) {
+ } catch (CompletionException e) {
Throwable t = e.getCause();
Throwables.throwIfUnchecked(t);
LOGGER.warn("Failed to fetch space statistics for {}: {}", id, t.toString());
@@ -1625,7 +1626,7 @@ private Optional lookupSpaceById(String id) {
private Optional lookupWriteToken(FsPath path) {
try {
return _writeTokenCache.get(path);
- } catch (ExecutionException e) {
+ } catch (CompletionException e) {
Throwable t = e.getCause();
Throwables.throwIfUnchecked(t);
LOGGER.warn("Failed to query for WriteToken tag on {}: {}", path, t.toString());
diff --git a/modules/dcache-webdav/src/main/java/org/dcache/webdav/transfer/CredentialServiceClient.java b/modules/dcache-webdav/src/main/java/org/dcache/webdav/transfer/CredentialServiceClient.java
index 31891fb70d0..c75294d24b9 100644
--- a/modules/dcache-webdav/src/main/java/org/dcache/webdav/transfer/CredentialServiceClient.java
+++ b/modules/dcache-webdav/src/main/java/org/dcache/webdav/transfer/CredentialServiceClient.java
@@ -20,8 +20,8 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.SECONDS;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.collect.ImmutableMap;
import diskCacheV111.srm.CredentialServiceAnnouncement;
import diskCacheV111.srm.CredentialServiceRequest;
@@ -86,7 +86,7 @@ public class CredentialServiceClient
private CellStub topic;
- private Cache cache = CacheBuilder.newBuilder()
+ private Cache cache = Caffeine.newBuilder()
.expireAfterWrite(70, SECONDS).build();
@Required
diff --git a/modules/dcache/pom.xml b/modules/dcache/pom.xml
index 19ce59ebd70..272433288d5 100644
--- a/modules/dcache/pom.xml
+++ b/modules/dcache/pom.xml
@@ -46,6 +46,10 @@
com.google.guava
guava