org.jrabbit.standard.profiler.util
Class Counter

java.lang.Object
  extended by org.jrabbit.standard.profiler.util.Message
      extended by org.jrabbit.standard.profiler.util.Counter
All Implemented Interfaces:
Referenced

public class Counter
extends Message

A Counter extends Message to provide functionality for counting the number of times a certain process occurs over a desired interval of time. The most obvious use for this object is to allow a ProfilerEntity to count, say, the number of completed frames per second. It's a simplistic bit of functionality but useful nevertheless.

Author:
Chris Molini

Field Summary
protected  int counter
          This value keeps track of how many times the counter has been advanced per interval.
protected  long interval
          This is the duration (in nanoseconds) that the program should consider the interval to count over.
protected  long intervalStart
          This is the time (in nanoseconds from program startup) that the current interval being recorded began.
 
Fields inherited from class org.jrabbit.standard.profiler.util.Message
listener, message, reference
 
Constructor Summary
Counter(java.lang.String reference)
          Creates a Counter that is identified by the supplied indicator.
Counter(java.lang.String reference, float interval)
          Creates a Counter that is identified by the supplied reference and that records events over the indicated interval.
 
Method Summary
 void advance()
          Updates the counter, telling it to increment its count by one.
 long interval()
          Learns the interval over which the Counter is currently counting.
 void setInterval(float seconds)
          Redefines the period over which the Counter should count.
 void setInterval(long nanoseconds)
          Redefines the period over which the Counter should count.
 
Methods inherited from class org.jrabbit.standard.profiler.util.Message
alertListener, listener, message, reference, setListener, setMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

counter

protected int counter
This value keeps track of how many times the counter has been advanced per interval.


intervalStart

protected long intervalStart
This is the time (in nanoseconds from program startup) that the current interval being recorded began.


interval

protected long interval
This is the duration (in nanoseconds) that the program should consider the interval to count over.

Constructor Detail

Counter

public Counter(java.lang.String reference)
Creates a Counter that is identified by the supplied indicator. NOTE: The created Counter measures events over a period of 1 second.

Parameters:
reference - The identifier of this Counter.

Counter

public Counter(java.lang.String reference,
               float interval)
Creates a Counter that is identified by the supplied reference and that records events over the indicated interval.

Parameters:
reference - The identifier of this Counter.
interval - The number of seconds that this Counter counts over.
Method Detail

interval

public long interval()
Learns the interval over which the Counter is currently counting.

Returns:
The number of nanoseconds that is considered one discrete interval.

setInterval

public void setInterval(float seconds)
Redefines the period over which the Counter should count. NOTE: This resets all values used to regulate event counting.

Parameters:
seconds - The number of seconds that constitute the target interval.

setInterval

public void setInterval(long nanoseconds)
Redefines the period over which the Counter should count. NOTE: This resets all values used to regulate event counting.

Parameters:
nanoseconds - The number of nanoseconds that constitute the target interval.

advance

public void advance()
Updates the counter, telling it to increment its count by one. If the target interval has elapsed, the counter value is reset and the message is updated accordingly.