diff --git a/source/net/filebot/Cache.java b/source/net/filebot/Cache.java index 11576af9..4c5f3603 100644 --- a/source/net/filebot/Cache.java +++ b/source/net/filebot/Cache.java @@ -12,7 +12,7 @@ import java.util.Arrays; import java.util.function.Predicate; import net.filebot.CachedResource2.Fetch; -import net.filebot.CachedResource2.Source; +import net.filebot.CachedResource2.Resource; import net.filebot.CachedResource2.Transform; import net.filebot.web.FloodLimit; import net.sf.ehcache.Element; @@ -28,7 +28,7 @@ public class Cache { return CacheManager.getInstance().getCache(name.toLowerCase(), type); } - public CachedResource2 resource(String key, Source source, Fetch fetch, Transform parse, Transform cast, Duration expirationTime) { + public CachedResource2 resource(String key, Resource source, Fetch fetch, Transform parse, Transform cast, Duration expirationTime) { return new CachedResource2(key, source, fetch, parse, cast, expirationTime, this); } @@ -36,11 +36,11 @@ public class Cache { return new CachedResource2(url, URL::new, withPermit(fetchIfModified(), r -> limit.acquirePermit() != null), getText(UTF_8), String.class::cast, expirationTime, this); } - public CachedResource2 xml(String key, Source source, Duration expirationTime) { + public CachedResource2 xml(String key, Resource source, Duration expirationTime) { return new CachedResource2(key, source, fetchIfModified(), validateXml(getText(UTF_8)), getXml(String.class::cast), expirationTime, this); } - public CachedResource2 json(String key, Source source, Duration expirationTime) { + public CachedResource2 json(String key, Resource source, Duration expirationTime) { return new CachedResource2(key, source, fetchIfModified(), validateJson(getText(UTF_8)), getJson(String.class::cast), expirationTime, this); } diff --git a/source/net/filebot/CachedResource2.java b/source/net/filebot/CachedResource2.java index 727b0877..85703f9a 100644 --- a/source/net/filebot/CachedResource2.java +++ b/source/net/filebot/CachedResource2.java @@ -22,7 +22,7 @@ public class CachedResource2 { private K key; - private Source source; + private Resource source; private Fetch fetch; private Transform parse; private Transform cast; @@ -30,15 +30,15 @@ public class CachedResource2 { private Duration expirationTime; private int retryCountLimit; - private long retryWaitTime; + private Duration retryWaitTime; private final Cache cache; - public CachedResource2(K key, Source source, Fetch fetch, Transform parse, Transform cast, Duration expirationTime, Cache cache) { + public CachedResource2(K key, Resource source, Fetch fetch, Transform parse, Transform cast, Duration expirationTime, Cache cache) { this(key, source, fetch, parse, cast, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_DELAY, expirationTime, cache); } - public CachedResource2(K key, Source source, Fetch fetch, Transform parse, Transform cast, int retryCountLimit, Duration retryWaitTime, Duration expirationTime, Cache cache) { + public CachedResource2(K key, Resource source, Fetch fetch, Transform parse, Transform cast, int retryCountLimit, Duration retryWaitTime, Duration expirationTime, Cache cache) { this.key = key; this.source = source; this.fetch = fetch; @@ -46,7 +46,7 @@ public class CachedResource2 { this.cast = cast; this.expirationTime = expirationTime; this.retryCountLimit = retryCountLimit; - this.retryWaitTime = retryWaitTime.toMillis(); + this.retryWaitTime = retryWaitTime; this.cache = cache; } @@ -80,7 +80,7 @@ public class CachedResource2 { return cast.transform(value); } - protected T retry(Callable callable, int retryCount, long retryWaitTime) throws Exception { + protected T retry(Callable callable, int retryCount, Duration retryWaitTime) throws Exception { try { return callable.call(); } catch (FileNotFoundException e) { @@ -91,13 +91,13 @@ public class CachedResource2 { if (retryCount > 0) { throw e; } - Thread.sleep(retryWaitTime); - return retry(callable, retryCount - 1, retryWaitTime * 2); + Thread.sleep(retryWaitTime.toMillis()); + return retry(callable, retryCount - 1, retryWaitTime.multipliedBy(2)); } } @FunctionalInterface - public interface Source { + public interface Resource { URL source(K key) throws Exception; }