com.bigdata.counters
Class Instrument<T>

java.lang.Object
  extended by com.bigdata.counters.Instrument<T>
All Implemented Interfaces:
IInstrument<T>

public abstract class Instrument<T>
extends Object
implements IInstrument<T>

Abstract class for reporting instrumented values supporting some useful conversions.

Version:
$Id: Instrument.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  long lastModified
          The timestamp associated with value.
protected static org.apache.log4j.Logger log
           
protected static String NA
          N/A
protected  T value
          The current value -or- null if there is no current value.
 
Constructor Summary
Instrument()
           
 
Method Summary
 T getCurrentValue()
          Return the current value without taking another sample()
 T getValue()
          Obtain a sample.
 long lastModified()
          Obtain the timestamp for the last collected sample.
 String nanosToPerSec(long counter, long nanos)
          Converts an event count whose durations were measured in elapsed nanoseconds to an event rate per second.
protected abstract  void sample()
          Take a sample, setting the current value and timestamp using either setValue(Object) or setValue(Object, long).
 void setValue(T value)
          Set the value.
 void setValue(T value, long timestamp)
          Set the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.log4j.Logger log

NA

protected static final transient String NA
N/A

See Also:
Constant Field Values

value

protected T value
The current value -or- null if there is no current value.


lastModified

protected long lastModified
The timestamp associated with value.

Constructor Detail

Instrument

public Instrument()
Method Detail

nanosToPerSec

public final String nanosToPerSec(long counter,
                                  long nanos)
Converts an event count whose durations were measured in elapsed nanoseconds to an event rate per second.

Parameters:
counter - The event count.
nanos - The elapsed nanoseconds for the events.
Returns:
Either "N/A" if nanos is ZERO (0) or the rate per second for the event.
TODO:
move to a util class? deprecate and remove in favor of Double counters?

sample

protected abstract void sample()
Take a sample, setting the current value and timestamp using either setValue(Object) or setValue(Object, long).


setValue

public final void setValue(T value)
Set the value.

Parameters:
value - The value, which will be associated with the current time as reported by System.currentTimeMillis().

setValue

public final void setValue(T value,
                           long timestamp)
Set the value.

Specified by:
setValue in interface IInstrument<T>
Parameters:
value - The value.
timestamp - The timestamp for that value.

getValue

public final T getValue()
Description copied from interface: IInstrument
Obtain a sample.

Specified by:
getValue in interface IInstrument<T>

getCurrentValue

public T getCurrentValue()
Return the current value without taking another sample()


lastModified

public final long lastModified()
Description copied from interface: IInstrument
Obtain the timestamp for the last collected sample.

Specified by:
lastModified in interface IInstrument<T>


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.