com.boylesoftware.cb2.util
Class EventStatistics

java.lang.Object
  extended bycom.boylesoftware.cb2.util.EventStatistics
All Implemented Interfaces:
java.io.Serializable

public class EventStatistics
extends java.lang.Object
implements java.io.Serializable

This utility class can be used for collecting statistics on some reqularly taking place event. Each event, when it happens, is registered with an instance of this class and then various parameters about this event regularity can be obtained.

There are two ways of using this class. First is for counting "point" events, and the second is for gathering statistics on events that take some time for processing and you want to have statistics on that time. In the first case you just call eventStarted method for each event. The getProcTimeXxx methods then will always be returning -1. In the second case you call eventStarted method when the event processing is just started and then you call eventFinished when the processing has just finished. In this case the getProcTimeXxx method will be returning valid computed values.

This class is thread safe. Basically all methods of this class are instance-synchronized.

Version:
$Id: EventStatistics.java,v 1.4 2003/07/20 16:04:19 levahim Exp $
Author:
Lev Himmelfarb
See Also:
Serialized Form

Constructor Summary
EventStatistics()
          Constructs an event statistics object.
EventStatistics(EventHistory[] timelines)
          Constructs an event statistics object with event history timelines.
 
Method Summary
 long eventFinished(long startedTs)
          Registers the fact that processing of the event has finished.
 long eventStarted()
          Registers the fact that the event has happened.
 long getDistAvg()
          Gets the average time in milliseconds between events.
 long getEventsPerMinuteAvg()
          Gets the average number of events per minute.
 long getNTimes()
          Gets the number of times the event has happened.
 long getProcTimeAvg()
          Gets the average amount of time in milliseconds processing of the event took.
 long getProcTimeMax()
          Gets the maximum amount of time in milliseconds processing of the event took.
 long getProcTimeMin()
          Gets the minimum amount of time in milliseconds processing of the event took.
 EventHistory[] getTimelines()
          Gets the event history timelines.
 long getTsLast()
          Gets the timestamp when the event happened last time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventStatistics

public EventStatistics()
Constructs an event statistics object.


EventStatistics

public EventStatistics(EventHistory[] timelines)
Constructs an event statistics object with event history timelines.

Parameters:
timelines - array of timelines to maintain.
Method Detail

eventStarted

public long eventStarted()
Registers the fact that the event has happened.

Returns:
timestamp when the event happened.

eventFinished

public long eventFinished(long startedTs)
Registers the fact that processing of the event has finished. Calling this method is optional and is required only if you need the procTimeXxx fields.

Parameters:
startedTs - value returned by eventStarted method when registering the event's start.
Returns:
number of milliseconds the event processing took.

getNTimes

public long getNTimes()
Gets the number of times the event has happened.

Returns:
the number of times the event has happened.

getDistAvg

public long getDistAvg()
Gets the average time in milliseconds between events.

Returns:
the average time in milliseconds between events.

getTsLast

public long getTsLast()
Gets the timestamp when the event happened last time.

Returns:
the timestamp when the event happened last time.

getProcTimeMin

public long getProcTimeMin()
Gets the minimum amount of time in milliseconds processing of the event took.

Returns:
the minimum amount of time in milliseconds processing of the event took.

getProcTimeAvg

public long getProcTimeAvg()
Gets the average amount of time in milliseconds processing of the event took.

Returns:
the average amount of time in milliseconds processing of the event took.

getProcTimeMax

public long getProcTimeMax()
Gets the maximum amount of time in milliseconds processing of the event took.

Returns:
the maximum amount of time in milliseconds processing of the event took.

getEventsPerMinuteAvg

public long getEventsPerMinuteAvg()
Gets the average number of events per minute.

Returns:
the average number of events per minute.

getTimelines

public EventHistory[] getTimelines()
Gets the event history timelines.

Returns:
array of event history timelines or null.


Copyright © 2002,2003,2004 - Boyle Software, Inc.