Class SessionCounter

  • All Implemented Interfaces:
    Serializable, AutoCloseable

    public class SessionCounter
    extends EventCounter
    implements AutoCloseable
    This class is used to count and observe the frequency, duration, and concurrency of events that have distinct start/stop times.

    SessionCounter events may overlap. In other words, a second event may start before the first one stops. For a given SessionCounter, its concurrency is the number of events that have started and not yet stopped.

    See Also:
    Serialized Form
    • Constructor Detail

      • SessionCounter

        public SessionCounter()
      • SessionCounter

        public SessionCounter​(String inLabel,
                              int inIntervalSeconds)
        Constructor for the SessionCounter object
        Parameters:
        inLabel - Descriptive label for this SessionCounter
        inIntervalSeconds - number of seconds in each interval of this SessionCounter
      • SessionCounter

        public SessionCounter​(String inLabel)
        Constructs a new SessionCounter.
        Parameters:
        inLabel - Description of the Parameter
    • Method Detail

      • getSessionCounter

        public static SessionCounter getSessionCounter​(String inLabel)
        Get an instance of a SessionCounter with a particular label from the MetricRepository, creating one if necessary.
        Parameters:
        inLabel - - descriptive label for this SessionCounter
        Returns:
        The sessionCounter value
      • getSessionCounter

        public static SessionCounter getSessionCounter​(String inLabel,
                                                       int inIntervalSeconds)
        Get an instance of a SessionCounter with a particular label from the MetricRepository. If that SessionCounter does not already exist, one is created with the given label and the designated interval size.
        Parameters:
        inLabel - - descriptive label for this SessionCounter
        inIntervalSeconds - number of seconds in each interval of this SessionCounter
        Returns:
        The sessionCounter value
      • reset

        public void reset()
        Reset this SessionCounter to its "zero" condition so that it can be reused, avoiding the overhead of constructing a new instance.
        Overrides:
        reset in class EventCounter
      • getConcurrency

        public long getConcurrency()
        Gets the current concurrency, the number of sessions that have been added (started) without having yet been removed (stopped).
        Returns:
        The concurrency value
      • getPeakConcurrency

        public long getPeakConcurrency()
        Gets the peak concurrency observed over the life of the metric. A convenience method equivalent to getPeakConcurrencyInterval().getPeakConcurrency()
        Returns:
        The peakConcurrency value
      • getPeakConcurrencyInterval

        public SessionCounterInterval getPeakConcurrencyInterval()
        Gets the interval in which the highest concurrency was noted.
        Returns:
        Interval - having the highest concurrency
      • getSessionTime

        public float getSessionTime()
        Gets the number of milliseconds of elapsed time spent within sessions observed by this SessionCounter. Incomplete sessions -- those that have been started and not stopped -- are not included.
        Returns:
        sum of session times for all completed sessions
      • getRecentSessionTime

        public long getRecentSessionTime()
        Gets the number of milliseconds that a recent completed session took. If sessions are happening concurrently, then this implementation may not be able to give a correct value; if this is the case, 0 is returned.
        Returns:
        The recentSessionTime value
      • getMaximumSessionTime

        public long getMaximumSessionTime()
        Gets the number of milliseconds that elapsed during the longest completed session. If sessions are happening concurrently, then this implementation cannot give a correct value and 0 is returned.
        Returns:
        The maximumSessionTime value
      • getMaximumSessionStartTime

        public long getMaximumSessionStartTime()
      • getSessionTimeMean

        public float getSessionTimeMean()
        Gets the mean session time in milliseconds. In other words, the average amount of time spent within a session. Sessions that have not completed are not included in the computation.
        Returns:
        The sessionTimeMean value
      • add

        public void add​(int inIgnored)
        Counts the beginning of a session.

        The implementation supports adding only one session at a time. Hence, the argument is ignored and treated as 1.

        Overrides:
        add in class EventCounter
        Parameters:
        inIgnored - - ignored for SessionCounter
      • start

        public void start()
        Functionally identical to add(), supporting the start/stop terminology which is more natural then add/remove when the emphasis is on measuring elapsed time within critical sections.
      • stop

        public void stop()
        Functionally identical to remove(). See start().
      • remove

        public void remove​(int inCount)
        Informs this EventCounter that a previously added event is "finished" and no longer among the concurrent events. The argument is ignored.
        Parameters:
        inCount - - number of events to be removed
      • remove

        public void remove()
        Removes a single event. Equivalent to remove(1).