Class DefaultTimeService

  • All Implemented Interfaces:
    TimeService
    Direct Known Subclasses:
    EmbeddedTimeService

    public class DefaultTimeService
    extends java.lang.Object
    implements TimeService
    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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long expectedEndTime​(long duration, java.util.concurrent.TimeUnit inputTimeUnit)  
      java.time.Instant instant()  
      boolean isTimeExpired​(long endTimeNanos)  
      long remainingTime​(long endTimeNanos, java.util.concurrent.TimeUnit outputTimeUnit)  
      long time()  
      long timeDuration​(long startTimeNanos, long endTimeNanos, java.util.concurrent.TimeUnit outputTimeUnit)  
      long timeDuration​(long startTimeNanos, java.util.concurrent.TimeUnit outputTimeUnit)
      It is equivalent to timeDuration(startTime, time(), outputTimeUnit).
      long wallClockTime()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultTimeService

        public DefaultTimeService()
    • Method Detail

      • wallClockTime

        public long wallClockTime()
        Specified by:
        wallClockTime in interface TimeService
        Returns:
        the current clock time in milliseconds. Note that it depends of the system time.
      • time

        public long time()
        Specified by:
        time in interface TimeService
        Returns:
        the current cpu time in nanoseconds. Note that some platforms do not provide nanosecond precision.
      • instant

        public java.time.Instant instant()
        Specified by:
        instant in interface TimeService
        Returns:
        the current Instant. Similarly to TimeService.time(), note that some platforms do not provide nanosecond precision.
      • timeDuration

        public long timeDuration​(long startTimeNanos,
                                 java.util.concurrent.TimeUnit outputTimeUnit)
        Description copied from interface: TimeService
        It is equivalent to timeDuration(startTime, time(), outputTimeUnit).
        Specified by:
        timeDuration in interface TimeService
        Parameters:
        startTimeNanos - start cpu time in nanoseconds, usually returned by TimeService.time().
        outputTimeUnit - the TimeUnit of 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

        public long timeDuration​(long startTimeNanos,
                                 long endTimeNanos,
                                 java.util.concurrent.TimeUnit outputTimeUnit)
        Specified by:
        timeDuration in interface TimeService
        Parameters:
        startTimeNanos - start cpu time in nanoseconds, usually returned by TimeService.time().
        endTimeNanos - end cpu time in nanoseconds, usually returned by TimeService.time().
        outputTimeUnit - the TimeUnit of 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:
        isTimeExpired in interface TimeService
        Parameters:
        endTimeNanos - a cpu time in nanoseconds, usually returned by TimeService.time()
        Returns:
        true if the endTime is less or equals than the current cpu time.
      • remainingTime

        public long remainingTime​(long endTimeNanos,
                                  java.util.concurrent.TimeUnit outputTimeUnit)
        Specified by:
        remainingTime in interface TimeService
        Parameters:
        endTimeNanos - the end cpu time in nanoseconds.
        outputTimeUnit - the TimeUnit of the returned value.
        Returns:
        the remaining cpu time until the endTime is reached.
      • expectedEndTime

        public long expectedEndTime​(long duration,
                                    java.util.concurrent.TimeUnit inputTimeUnit)
        Specified by:
        expectedEndTime in interface TimeService
        Parameters:
        duration - the duration.
        inputTimeUnit - the TimeUnit of 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()).