|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.boylesoftware.cb2.util.EventHistory
Counts events and maintains a statistics for a certain period of time.
Canbe used together with StatsGraph
for creating nice
event statistics images.
Note, that all get methods are not synchronized. Usually you call
a few get methods from a single synchronized
on the
EventHistory
instance block. The first call should be
getSamples
, because it updates timestamps:
long totalSpan = eventHistory.getTotalSpan(); // don't need to be synchronized, since it never changes long [] samples; int lastSampleIndex; int nSamples; long lastSampleTs; long maxSample; synchronized(eventHistory) { samples = eventHistory.getSamples(); lastSampleIndex = eventHistory.getLastSampleIndex(); nSamples = eventHistory.getNSamples(); lastSampleTs = eventHistory.getLastSampleTs(); maxSample = eventHistory.getMaxSample(); }
StatsGraph
,
Serialized FormField Summary | |
protected int |
curSampleInd
Index of the currently being built sample. |
protected long |
maxSample
Maximum sample value. |
protected int |
nSamples
Number of samples in the timeline including the
current one (so it never can be zero). |
protected long[] |
samples
Containes samples. |
protected long |
sampleSpan
Number of milliseconds for a single sample data. |
protected long |
totalSpan
Number of milliseconds representing the whole timeline. |
protected long |
tsLastSampleStart
Timestamp when collecting data for the current sample was started. |
Constructor Summary | |
EventHistory(long totalSpan,
int timelineSamples)
Constructs and initializes a new event history object. |
Method Summary | |
long |
eventStarted()
Registers an event happened now. |
void |
eventStarted(long ts)
Registers an event happened at the specified time. |
int |
getLastSampleIndex()
Gets index of the last sample in the array of samples. |
long |
getLastSampleTs()
Gets timestamp for the last sample. |
long |
getMaxSample()
Gets the maximum sample value. |
int |
getNSamples()
Gets the number of samples in the array of samples. |
long[] |
getSamples()
Gets the samples. |
long |
getSampleSpan()
Gets number of milliseconds of one sample. |
long |
getTotalSpan()
Gets number of milliseconds in the whole timeline. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final long[] samples
protected final long totalSpan
protected final long sampleSpan
protected int curSampleInd
protected int nSamples
timeline
including the
current one (so it never can be zero).
protected long tsLastSampleStart
protected long maxSample
Constructor Detail |
public EventHistory(long totalSpan, int timelineSamples)
totalSpan
- number of milliseconds in the timeline, meaing that
the event history object will keep statistics for events for the
last specified number of milliseconds.timelineSamples
- number of samples to keep, so this parameters
defines the resolution of the timeline. For example if the timeline
is 1 hour (totalSpan = 3600000
) and the
timelineSamples
is set to 60
then we will
have a sample for every minute. When you use EventHistory
with StatsGraph
class for generating event timeline
images, for optimal mode it's better to set timelineSamples
to be the same as the width of the picture. This way you will have
a sample per each pixel on the horizontal axis of the generated image.Method Detail |
public long eventStarted()
public void eventStarted(long ts)
ts
- timestamp when the event happened.public long[] getSamples()
public int getNSamples()
public int getLastSampleIndex()
public long getTotalSpan()
synchronized
block.
public long getSampleSpan()
synchronized
block.
public long getLastSampleTs()
public long getMaxSample()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |