Package org.cache2k.operation
Interface TimeReference
-
public interface TimeReference
Time reference for a cache. By default the current time is retrieved withSystem.currentTimeMillis()
. Another time reference can be specified if the application uses a different time source or when a simulated clock should be used.An instance may implement
AutoCloseable
if resources need to be cleaned up.- Author:
- Jens Wilke
-
-
Field Summary
Fields Modifier and Type Field Description static TimeReference
DEFAULT
Default implementation usingSystem.currentTimeMillis()
as time reference.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description long
millis()
Returns the milliseconds since epoch.void
sleep(long millis)
Wait for the specified amount of time in milliseconds.default long
toMillis(long millis)
Convert a value returned bymillis()
to milliseconds since epoch.
-
-
-
Field Detail
-
DEFAULT
static final TimeReference DEFAULT
Default implementation usingSystem.currentTimeMillis()
as time reference.
-
-
Method Detail
-
millis
long millis()
Returns the milliseconds since epoch. In the simulated clock a call to this method would make time pass in small increments.It is possible to use other time scales and references (e.g. nano seconds). In this case the method
toMillis(long)
needs to be implemented. All times in the cache API, e.g.MutableCacheEntry.getExpiryTime()
or inAdvancedCacheLoader.load(Object, long, CacheEntry)
are based on the time defined here.
-
sleep
void sleep(long millis) throws InterruptedException
Wait for the specified amount of time in milliseconds.The value of 0 means that the thread should pause and other processing should be done. In a simulated clock this would wait for concurrent processing and, if no processing is happening, advance the time to the next event.
- Throws:
InterruptedException
-
toMillis
default long toMillis(long millis)
Convert a value returned bymillis()
to milliseconds since epoch. This can be overridden in case another time scale and or reference is used. Conversion is needed for correctly scheduling timer task that regularly process the expiry tasks.
-
-