Package org.cache2k.core.timing
Class Timing<K,V>
- java.lang.Object
-
- org.cache2k.core.timing.Timing<K,V>
-
- All Implemented Interfaces:
NeedsClose
- Direct Known Subclasses:
StaticTiming,TimeAgnosticTiming
public abstract class Timing<K,V> extends Object implements NeedsClose
Encapsulates logic for expiry times calculation and timer handling.- Author:
- Jens Wilke
-
-
Constructor Summary
Constructors Constructor Description Timing()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract longcacheExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)Delegated to the resilience policyabstract longcalculateNextRefreshTime(Entry<K,V> e, V value, long loadTime)Calculates the expiry time for a value that was just loaded or inserted into the cache.voidcancelAll()Cancels all pending timer events.voidcancelExpiryTimer(Entry<K,V> e)Cancel the timer on the entry, if a timer was set.voidclose(InternalCacheCloseContext closeContext)longgetExpiryAfterWriteTicks()longlimitExpiryTime(long now, long expiryTime)static <K,V>
Timing<K,V>of(InternalCacheBuildContext<K,V> ctx)voidscheduleFinalTimerForSharpExpiry(Entry<K,V> e)Schedule second timer event for the expiry tie if sharp expiry is switched on.voidsetTarget(TimerEventListener<K,V> c)Set the target for timer events.booleanstartRefreshProbationTimer(Entry<K,V> e, long nextRefreshTime)Start probation timer.longstopStartTimer(long expiryTime, Entry<K,V> e)Convert expiry value to the entry field value, essentially maps 0 toEntry.EXPIREDsince 0 is a virgin entry.abstract longsuppressExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)Delegated to the resilience policy
-
-
-
Method Detail
-
of
public static <K,V> Timing<K,V> of(InternalCacheBuildContext<K,V> ctx)
-
setTarget
public void setTarget(TimerEventListener<K,V> c)
Set the target for timer events. Called during cache build before any timer tasks are created. For each cache instance there is a timing instance and both reference each other. We create timing first, then the cache.
-
cancelAll
public void cancelAll()
Cancels all pending timer events.
-
close
public void close(InternalCacheCloseContext closeContext)
- Specified by:
closein interfaceNeedsClose
-
calculateNextRefreshTime
public abstract long calculateNextRefreshTime(Entry<K,V> e, V value, long loadTime)
Calculates the expiry time for a value that was just loaded or inserted into the cache.- Parameters:
e- The entry, filled with the previous value if there is a value present already.value- The new value or an exception wrapped inExceptionWrapperloadTime- the time immediately before the load started- Returns:
- Point in time when the entry should expire. Meaning identical to
ExpiryPolicy.calculateExpiryTime(Object, Object, long, CacheEntry)
-
suppressExceptionUntil
public abstract long suppressExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)
Delegated to the resilience policy- See Also:
ResiliencePolicy.suppressExceptionUntil(K, org.cache2k.io.LoadExceptionInfo<K, V>, org.cache2k.CacheEntry<K, V>)
-
cacheExceptionUntil
public abstract long cacheExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)
Delegated to the resilience policy- See Also:
ResiliencePolicy.retryLoadAfter(K, org.cache2k.io.LoadExceptionInfo<K, V>)
-
stopStartTimer
public long stopStartTimer(long expiryTime, Entry<K,V> e)Convert expiry value to the entry field value, essentially maps 0 toEntry.EXPIREDsince 0 is a virgin entry. Restart the timer if needed.- Parameters:
expiryTime- calculated expiry time- Returns:
- sanitized nextRefreshTime for storage in the entry.
- Throws:
IllegalArgumentException- if time is not supported
-
startRefreshProbationTimer
public boolean startRefreshProbationTimer(Entry<K,V> e, long nextRefreshTime)
Start probation timer.
-
cancelExpiryTimer
public void cancelExpiryTimer(Entry<K,V> e)
Cancel the timer on the entry, if a timer was set.
-
scheduleFinalTimerForSharpExpiry
public void scheduleFinalTimerForSharpExpiry(Entry<K,V> e)
Schedule second timer event for the expiry tie if sharp expiry is switched on.
-
getExpiryAfterWriteTicks
public long getExpiryAfterWriteTicks()
-
limitExpiryTime
public long limitExpiryTime(long now, long expiryTime)
-
-