Package com.berryworks.jquantify
Class SessionCounter
- java.lang.Object
-
- com.berryworks.jquantify.Metric
-
- com.berryworks.jquantify.EventCounter
-
- com.berryworks.jquantify.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.SessionCounterevents may overlap. In other words, a second event may start before the first one stops. For a givenSessionCounter, its concurrency is the number of events that have started and not yet stopped.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.berryworks.jquantify.EventCounter
mCurrentInterval, mNow, mPeakEvents, mPriorInterval
-
Fields inherited from class com.berryworks.jquantify.Metric
intervalSeconds, startTime, totalIntervals
-
-
Constructor Summary
Constructors Constructor Description SessionCounter()SessionCounter(String inLabel)Constructs a new SessionCounter.SessionCounter(String inLabel, int inIntervalSeconds)Constructor for the SessionCounter object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int inIgnored)Counts the beginning of a session.SessionCounterautoCloseableStart()voidclose()protected voidcreateIntervals()longgetConcurrency()Gets the current concurrency, the number of sessions that have been added (started) without having yet been removed (stopped).longgetMaximumSessionStartTime()longgetMaximumSessionTime()Gets the number of milliseconds that elapsed during the longest completed session.longgetPeakConcurrency()Gets the peak concurrency observed over the life of the metric.SessionCounterIntervalgetPeakConcurrencyInterval()Gets the interval in which the highest concurrency was noted.longgetRecentSessionTime()Gets the number of milliseconds that a recent completed session took.static SessionCountergetSessionCounter(String inLabel)Get an instance of a SessionCounter with a particular label from the MetricRepository, creating one if necessary.static SessionCountergetSessionCounter(String inLabel, int inIntervalSeconds)Get an instance of a SessionCounter with a particular label from the MetricRepository.floatgetSessionTime()Gets the number of milliseconds of elapsed time spent within sessions observed by thisSessionCounter.floatgetSessionTimeMean()Gets the mean session time in milliseconds.protected voidnormalizeCurrent_ScenarioA()protected voidnormalizeCurrent_ScenarioB()protected voidnormalizePrior_ScenarioA()protected voidnormalizePrior_ScenarioB(long nEmptyIntervals)voidremove()Removes a single event.voidremove(int inCount)Informs this EventCounter that a previously added event is "finished" and no longer among the concurrent events.voidreset()Reset thisSessionCounterto its "zero" condition so that it can be reused, avoiding the overhead of constructing a new instance.voidstart()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.voidstop()Functionally identical to remove().-
Methods inherited from class com.berryworks.jquantify.EventCounter
getCount, getCumulativeEvents, getCumulativeFreq, getCurrentFreq, getCurrentInterval, getEventCounter, getPeakEvents, getPeakEventsInterval, normalize
-
Methods inherited from class com.berryworks.jquantify.Metric
add, getAge, getAgeMillis, getIntervalSeconds, getLabel, getTotalIntervals, setLabel, uptime
-
-
-
-
Constructor Detail
-
SessionCounter
public SessionCounter()
-
SessionCounter
public SessionCounter(String inLabel, int inIntervalSeconds)
Constructor for the SessionCounter object- Parameters:
inLabel- Descriptive label for this SessionCounterinIntervalSeconds- 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 SessionCounterinIntervalSeconds- number of seconds in each interval of this SessionCounter- Returns:
- The sessionCounter value
-
reset
public void reset()
Reset thisSessionCounterto its "zero" condition so that it can be reused, avoiding the overhead of constructing a new instance.- Overrides:
resetin classEventCounter
-
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 togetPeakConcurrencyInterval().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 thisSessionCounter. 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:
addin classEventCounter- 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.
-
autoCloseableStart
public SessionCounter autoCloseableStart()
-
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).
-
createIntervals
protected void createIntervals()
- Overrides:
createIntervalsin classEventCounter
-
normalizeCurrent_ScenarioA
protected void normalizeCurrent_ScenarioA()
- Overrides:
normalizeCurrent_ScenarioAin classEventCounter
-
normalizePrior_ScenarioA
protected void normalizePrior_ScenarioA()
- Overrides:
normalizePrior_ScenarioAin classEventCounter
-
normalizeCurrent_ScenarioB
protected void normalizeCurrent_ScenarioB()
- Overrides:
normalizeCurrent_ScenarioBin classEventCounter
-
normalizePrior_ScenarioB
protected void normalizePrior_ScenarioB(long nEmptyIntervals)
- Overrides:
normalizePrior_ScenarioBin classEventCounter
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-