Class DefaultTimeService
java.lang.Object
org.infinispan.commons.time.DefaultTimeService
- All Implemented Interfaces:
TimeService
- Direct Known Subclasses:
EmbeddedTimeService
The default implementation of
TimeService. It does not perform any optimization and relies on System.currentTimeMillis() and System.nanoTime().- Since:
- 5.3
- Author:
- Pedro Ruivo
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongexpectedEndTime(long duration, TimeUnit inputTimeUnit) instant()booleanisTimeExpired(long endTimeNanos) longremainingTime(long endTimeNanos, TimeUnit outputTimeUnit) longtime()longtimeDuration(long startTimeNanos, long endTimeNanos, TimeUnit outputTimeUnit) longtimeDuration(long startTimeNanos, TimeUnit outputTimeUnit) It is equivalent totimeDuration(startTime, time(), outputTimeUnit).long
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
DefaultTimeService
public DefaultTimeService()
-
-
Method Details
-
wallClockTime
public long wallClockTime()- Specified by:
wallClockTimein interfaceTimeService- Returns:
- the current clock time in milliseconds. Note that it depends of the system time.
-
time
public long time()- Specified by:
timein interfaceTimeService- Returns:
- the current cpu time in nanoseconds. Note that some platforms do not provide nanosecond precision.
-
instant
- Specified by:
instantin interfaceTimeService- Returns:
- the current
Instant. Similarly toTimeService.time(), note that some platforms do not provide nanosecond precision.
-
timeDuration
Description copied from interface:TimeServiceIt is equivalent totimeDuration(startTime, time(), outputTimeUnit).- Specified by:
timeDurationin interfaceTimeService- Parameters:
startTimeNanos- start cpu time in nanoseconds, usually returned byTimeService.time().outputTimeUnit- theTimeUnitof the returned value.- Returns:
- the duration between the current cpu time and startTime. It returns zero if startTime is less than zero or if startTime is greater than the current cpu time.
-
timeDuration
- Specified by:
timeDurationin interfaceTimeService- Parameters:
startTimeNanos- start cpu time in nanoseconds, usually returned byTimeService.time().endTimeNanos- end cpu time in nanoseconds, usually returned byTimeService.time().outputTimeUnit- theTimeUnitof the returned value.- Returns:
- the duration between the endTime and startTime. It returns zero if startTime or endTime are less than zero or if startTime is greater than the endTime.
-
isTimeExpired
public boolean isTimeExpired(long endTimeNanos) - Specified by:
isTimeExpiredin interfaceTimeService- Parameters:
endTimeNanos- a cpu time in nanoseconds, usually returned byTimeService.time()- Returns:
trueif the endTime is less or equals than the current cpu time.
-
remainingTime
- Specified by:
remainingTimein interfaceTimeService- Parameters:
endTimeNanos- the end cpu time in nanoseconds.outputTimeUnit- theTimeUnitof the returned value.- Returns:
- the remaining cpu time until the endTime is reached.
-
expectedEndTime
- Specified by:
expectedEndTimein interfaceTimeService- Parameters:
duration- the duration.inputTimeUnit- theTimeUnitof the duration.- Returns:
- the expected end time in nano seconds. If duration is less or equals to zero, the current cpu time is returned (
TimeService.time()).
-