public class TickingTimeSource extends java.lang.Object implements TimeSource, Service
TimeSource
that increases the time in background using a timer. This time usually gives better performances
to Ehcache than the default SystemTimeSource
. However, it will create a background thread that will continuously
wake up to update the time.
It works be increasing the time at a given granularity. So if you set the granularity at 10ms, a timer is called every 10ms and will increase the current time of 10ms. This will cause the current time to diverge a bit from the system time after a while. So you specify a system update period where the current time will be reset to the system time.
Constructor and Description |
---|
TickingTimeSource(long granularity,
long systemUpdatePeriod)
Constructor to create a ticking time source.
|
Modifier and Type | Method and Description |
---|---|
long |
getTimeMillis()
The current "time" in milliseconds
|
void |
start(ServiceProvider<Service> serviceProvider)
Start this service using the provided configuration and
ServiceProvider . |
void |
stop()
Stops this service.
|
public TickingTimeSource(long granularity, long systemUpdatePeriod)
granularity
- how long in milliseconds between each timer call to increment the current timesystemUpdatePeriod
- how long between resets of the current time to system timepublic long getTimeMillis()
TimeSource
getTimeMillis
in interface TimeSource
public void start(ServiceProvider<Service> serviceProvider)
Service
ServiceProvider
.
The service provider allows a service to retrieve and use other services.
A Service
retrieved at this stage may not yet be started. The recommended usage pattern therefore, is to keep a
reference to the dependent Service
but use it only when specific methods are invoked on subtypes.