Class TimingSessionContainer

  • Direct Known Subclasses:
    MonitoredCallable, MonitoredRunnable, Stopwatch

    public abstract class TimingSessionContainer
    extends Object
    An object that maintains multiple timing sessions for different counter types, and provides methods to retrieve elapsed times is different formats.
    Since:
    2.5.0
    Author:
    oswaldo.bapvic.jr
    See Also:
    TimingSession
    • Method Detail

      • reset

        public void reset()
        Cleans all timing sessions in this object.
      • getTypes

        public List<Counter.Type> getTypes()
        Returns the counter types associated with this object.
        Returns:
        a list of counter types associated with this object
        See Also:
        Counter.Type
      • getAllCountersByType

        public Map<Counter.Type,​List<Counter>> getAllCountersByType()
        Returns a map of counters grouped by type, where each entry in the counters list represents a timing session.
        Returns:
        a map of populated counters grouped by type
        Since:
        2.2.1
        See Also:
        Counter
      • getCounters

        public List<Counter> getCounters​(Counter.Type type)
        Returns a list of available counters for a specific type in this object, or an empty list if no counter is found -- for example, if no timing session was started, or after calling reset().
        Parameters:
        type - the counter type to be fetched
        Returns:
        a list of counters associated with the given type, or an empty list
        Throws:
        IllegalArgumentException - if the specified type was not assigned to this object during instantiation
        Since:
        2.2.0
        See Also:
        Counter
      • elapsedTime

        public Duration elapsedTime()
        Returns the total elapsed time for a single counter type, provided that this object is keeping a single type.
        Returns:
        the elapsed time for a single counter type in this object
        Throws:
        IllegalStateException - if the object is keeping more than one counter type
        Since:
        2.2.4
      • elapsedTime

        public double elapsedTime​(TimeUnit timeUnit)
        Returns the total elapsed time in the specified time unit for a single counter type, provided that this object is keeping a single type.
        Parameters:
        timeUnit - the time unit to which the elapsed time will be converted
        Returns:
        the elapsed time for a single counter type in this object, converted to the given time unit with the default conversion mode
        Throws:
        IllegalStateException - if the object is keeping more than one counter type
        Since:
        2.2.4
      • elapsedTime

        public double elapsedTime​(TimeUnit timeUnit,
                                  ConversionMode conversionMode)
        Returns the total elapsed time in the specified time unit for a single counter type, provided that this object is keeping a single type.
        Parameters:
        timeUnit - the time unit to which the elapsed time will be converted
        conversionMode - the ConversionMode to be applied
        Returns:
        the elapsed time for a single counter type in this object, converted to the given time unit with the given conversion mode
        Throws:
        IllegalStateException - if the object is keeping more than one counter type
        Since:
        2.2.4
      • elapsedTime

        public Duration elapsedTime​(Counter.Type type)
        Returns the total elapsed time for a specific counter type.
        Parameters:
        type - the counter type to be fetched
        Returns:
        the elapsed time for the specified counter
        Throws:
        IllegalArgumentException - if the specified type was not assigned to this object during instantiation
        Since:
        2.1.0
      • elapsedTime

        public double elapsedTime​(Counter.Type type,
                                  TimeUnit timeUnit)
        Returns the total elapsed time for a specific counter type, in the specified time unit.
        Parameters:
        type - the counter type to be fetched
        timeUnit - the time unit to which the elapsed time will be converted
        Returns:
        the elapsed time for the specified counter, converted to the given time unit with the default conversion mode.
        Throws:
        IllegalArgumentException - if the specified type was not assigned to this object during instantiation
        Since:
        2.1.0
      • elapsedTime

        public double elapsedTime​(Counter.Type type,
                                  TimeUnit timeUnit,
                                  ConversionMode conversionMode)
        Returns the total elapsed time for a specific counter type, in the specified time unit, with a custom ConversionMode applied.
        Parameters:
        type - the counter type to be fetched
        timeUnit - the time unit to which the elapsed time will be converted
        conversionMode - the ConversionMode to be applied
        Returns:
        the elapsed time for the specified counter, converted to the given time unit with the given conversion mode.
        Throws:
        IllegalArgumentException - if the specified type was not assigned to this object during instantiation
        Since:
        2.1.0
      • printSummary

        public void printSummary​(PrintStream printStream)
        Prints summarized elapsed times in the specified print stream.
        Parameters:
        printStream - the print stream to which data will be sent
        Throws:
        NullPointerException - if the PrintStream is null
        Since:
        2.2.1
      • printDetails

        public void printDetails​(PrintStream printStream)
        Prints detailed information about timing sessions in the specified print stream.
        Parameters:
        printStream - the print stream to which information will be sent
        Throws:
        NullPointerException - if the PrintStream is null
        Since:
        2.2.1
      • lastSession

        public TimingSession lastSession()
        Returns the current/last timing session recorded in this object.
        Returns:
        the current/last timing session available in this object
        Throws:
        IllegalStateException - if the object does not contain any recorded session
        Since:
        2.4.0