Interface TimeService

  • All Known Implementing Classes:
    DefaultTimeService, EmbeddedTimeService

    public interface TimeService
    Encapsulates all the time related logic in this interface.
    Since:
    5.3
    Author:
    Pedro Ruivo
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      long expectedEndTime​(long duration, java.util.concurrent.TimeUnit inputTimeUnit)  
      java.time.Instant instant()  
      boolean isTimeExpired​(long endTime)  
      long remainingTime​(long endTime, java.util.concurrent.TimeUnit outputTimeUnit)  
      long time()  
      long timeDuration​(long startTime, long endTime, java.util.concurrent.TimeUnit outputTimeUnit)  
      long timeDuration​(long startTime, java.util.concurrent.TimeUnit outputTimeUnit)
      It is equivalent to timeDuration(startTime, time(), outputTimeUnit).
      long wallClockTime()  
    • Method Detail

      • wallClockTime

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

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

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

        long timeDuration​(long startTime,
                          java.util.concurrent.TimeUnit outputTimeUnit)
        It is equivalent to timeDuration(startTime, time(), outputTimeUnit).
        Parameters:
        startTime - start cpu time in nanoseconds, usually returned by 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

        long timeDuration​(long startTime,
                          long endTime,
                          java.util.concurrent.TimeUnit outputTimeUnit)
        Parameters:
        startTime - start cpu time in nanoseconds, usually returned by time().
        endTime - end cpu time in nanoseconds, usually returned by 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

        boolean isTimeExpired​(long endTime)
        Parameters:
        endTime - a cpu time in nanoseconds, usually returned by time()
        Returns:
        true if the endTime is less or equals than the current cpu time.
      • remainingTime

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

        long expectedEndTime​(long duration,
                             java.util.concurrent.TimeUnit inputTimeUnit)
        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 (time()).