Package com.berryworks.jquantify
Class EventCounter
- java.lang.Object
-
- com.berryworks.jquantify.Metric
-
- com.berryworks.jquantify.EventCounter
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SessionCounter
public class EventCounter extends Metric
This class is used to count and observe the frequency of events.An
EventCountertreats events as instantaneous, happening at a specific point in time and with no observable duration. For observing events that have both frequency and duration, consider aSessionCounter.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected EventCounterIntervalmCurrentIntervalprotected longmNowprotected EventCounterIntervalmPeakEventsprotected EventCounterIntervalmPriorInterval-
Fields inherited from class com.berryworks.jquantify.Metric
intervalSeconds, startTime, totalIntervals
-
-
Constructor Summary
Constructors Constructor Description EventCounter()EventCounter(String inLabel)Constructs a new EventCounter with an interval duration of 1 second.EventCounter(String inLabel, int inIntervalSeconds)Constructs an EventCounter with a specific interval duration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int inCount)Adds a number events.protected voidcreateIntervals()longgetCount()Gets the total count of events.longgetCumulativeEvents()Equivalent to getCount(), gets the total number of events added to thisEventCounter.floatgetCumulativeFreq()Gets the overall event frequency for thisEventCounterfloatgetCurrentFreq()Gets the current event frequency for thisEventCounter.IntervalgetCurrentInterval()Gets the current Interval, the one to which current events are added.static EventCountergetEventCounter(String inLabel)Get an instance of an EventCounter with a particular label from the MetricRepository, creating one if necessary.longgetPeakEvents()Gets the number of events that occurred during the interval in which the most events occurred.EventCounterIntervalgetPeakEventsInterval()Gets the interval in which the greatest number of events were added.voidnormalize()Normalizes this EventCounter if necessary.protected voidnormalizeCurrent_ScenarioA()protected voidnormalizeCurrent_ScenarioB()protected voidnormalizePrior_ScenarioA()protected voidnormalizePrior_ScenarioB(long nEmptyIntervals)voidreset()Reset thisEventCounterto its "zero" condition so that it can be reused, avoiding the overhead of constructing a new instance.-
Methods inherited from class com.berryworks.jquantify.Metric
add, getAge, getAgeMillis, getIntervalSeconds, getLabel, getTotalIntervals, setLabel, uptime
-
-
-
-
Field Detail
-
mCurrentInterval
protected EventCounterInterval mCurrentInterval
-
mPriorInterval
protected EventCounterInterval mPriorInterval
-
mPeakEvents
protected EventCounterInterval mPeakEvents
-
mNow
protected long mNow
-
-
Constructor Detail
-
EventCounter
public EventCounter()
-
EventCounter
public EventCounter(String inLabel, int inIntervalSeconds)
Constructs an EventCounter with a specific interval duration.- Parameters:
inLabel- descriptive String used in reportinginIntervalSeconds- int duration of each interval in seconds
-
EventCounter
public EventCounter(String inLabel)
Constructs a new EventCounter with an interval duration of 1 second.- Parameters:
inLabel- descriptive String used in reporting
-
-
Method Detail
-
getEventCounter
public static EventCounter getEventCounter(String inLabel)
Get an instance of an EventCounter with a particular label from the MetricRepository, creating one if necessary.- Parameters:
inLabel- Description of the Parameter- Returns:
- The eventCounter value
-
getCurrentInterval
public Interval getCurrentInterval()
Gets the current Interval, the one to which current events are added.- Returns:
- Interval - the current interval
-
getPeakEventsInterval
public EventCounterInterval getPeakEventsInterval()
Gets the interval in which the greatest number of events were added.- Returns:
- Interval - having the greatest getEvents()
-
getPeakEvents
public long getPeakEvents()
Gets the number of events that occurred during the interval in which the most events occurred. A convenience method equivalent togetPeakEventsInterval().getEvents()- Returns:
- The peakEvents value
-
getCount
public long getCount()
Description copied from class:MetricGets the total count of events.
-
getCumulativeEvents
public long getCumulativeEvents()
Equivalent to getCount(), gets the total number of events added to thisEventCounter.- Returns:
- total number of events
-
getCumulativeFreq
public float getCumulativeFreq()
Gets the overall event frequency for thisEventCounter- Returns:
- float - events per second
-
getCurrentFreq
public float getCurrentFreq()
Gets the current event frequency for thisEventCounter. The calculation includes the current incomplete interval. In order to reduce excessive fluctuations when the current interval has just begun, the immediately preceding interval, if one exists, is also included in the calculation.- Returns:
- float - events per second
-
add
public void add(int inCount)
Adds a number events.All events are considered to have happened now simultaneously.
-
normalize
public void normalize()
Normalizes this EventCounter if necessary. An EventCounter is considered to be normalized if the current time falls within the time span implied by the currentInterval. Once enough time has elapsed for the currentInterval to be outdated, then normalize() closes it and opens up a new currentInterval.
-
normalizeCurrent_ScenarioA
protected void normalizeCurrent_ScenarioA()
-
normalizePrior_ScenarioA
protected void normalizePrior_ScenarioA()
-
normalizeCurrent_ScenarioB
protected void normalizeCurrent_ScenarioB()
-
normalizePrior_ScenarioB
protected void normalizePrior_ScenarioB(long nEmptyIntervals)
-
reset
public void reset()
Reset thisEventCounterto its "zero" condition so that it can be reused, avoiding the overhead of constructing a new instance.
-
createIntervals
protected void createIntervals()
-
-