Keel 2.1RC2

org.apache.excalibur.instrument.manager
Class CounterInstrumentSample

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.instrument.manager.AbstractInstrumentSample
          extended byorg.apache.excalibur.instrument.manager.CounterInstrumentSample
All Implemented Interfaces:
CounterInstrumentListener, InstrumentListener, InstrumentSample, LogEnabled

class CounterInstrumentSample
extends AbstractInstrumentSample
implements CounterInstrumentListener

A InstrumentSample which stores the number of times that increment has been called during the sample period.

Since:
4.1
Version:
CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:25 $
Author:

Field Summary
protected  int m_count
          The count.
protected  long m_time
          The UNIX time of the beginning of the sample.
 
Fields inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
 
Constructor Summary
(package private) CounterInstrumentSample(InstrumentProxy instrumentProxy, java.lang.String name, long interval, int size, java.lang.String description, long lease)
          Creates a new CounterInstrumentSample
 
Method Summary
 void addInstrumentSampleListener(InstrumentSampleListener listener)
          Registers a InstrumentSampleListener with a InstrumentSample given a name.
protected  void advanceToNextSample()
          The current sample has already been stored.
 void expire()
          Tells the sample that its lease has expired.
 long extendLease(long lease)
          Extends the lease to be lease milliseconds from the current time.
 java.lang.String getDescription()
          Returns the description of the sample.
 InstrumentSampleDescriptorLocal getDescriptor()
          Returns a Descriptor for the InstrumentSample.
 InstrumentProxy getInstrumentProxy()
          Returns the InstrumentProxy which owns the InstrumentSample.
 int getInstrumentType()
          Returns the Type of the Instrument which can use the sample.
 long getInterval()
          Returns the sample interval.
 long getLeaseExpirationTime()
          Returns the time that the current lease expires.
 java.lang.String getName()
          Returns the name of the sample.
 int getSize()
          Returns the number of samples in the sample history.
 InstrumentSampleSnapshot getSnapshot()
          Obtains a static snapshot of the InstrumentSample.
 int getStateVersion()
          Returns the stateVersion of the sample.
 long getTime()
          Obtain the UNIX time of the beginning of the sample.
 int getType()
          Returns the type of the Instrument Sample.
 int getValue()
          Obtain the value of the sample.
 int getValueInner()
          Obtain the value of the sample.
private  void increment(int count, long time)
          Increments the count.
 void increment(java.lang.String instrumentName, int count, long time)
          Called by a CounterInstrument whenever its value is incremented.
 boolean isConfigured()
          Returns true if the Instrument was configured in the instrumentables section of the configuration.
 void loadState(Configuration state)
          Loads the state into the InstrumentSample.
protected  void loadState(int value, Configuration state)
          Used to load the state, called from AbstractInstrumentSample.loadState();
protected  void postSaveNeedsReset()
          Called after a state is loaded if the sample period is not the same as the last period saved.
 void removeInstrumentSampleListener(InstrumentSampleListener listener)
          Unregisters a InstrumentSampleListener from a InstrumentSample given a name.
 Configuration saveState()
          Saves the current state into a Configuration.
protected  void saveState(DefaultConfiguration state)
          Allow subclasses to add information into the saved state.
(package private)  void setConfigured()
          Sets the configured flag.
protected  void stateChanged()
          Called whenever the state of the sample is changed.
 java.lang.String toString()
          Returns a string representation of the sample.
protected  boolean update(long time)
          Brings the InstrumentSample's time up to date so that a new value can be added.
protected  void updateListeners(int value, long time)
          Notifies any listeners of a change.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 

Field Detail

m_count

protected int m_count
The count.


m_time

protected long m_time
The UNIX time of the beginning of the sample.

Constructor Detail

CounterInstrumentSample

CounterInstrumentSample(InstrumentProxy instrumentProxy,
                        java.lang.String name,
                        long interval,
                        int size,
                        java.lang.String description,
                        long lease)
Creates a new CounterInstrumentSample

Parameters:
instrumentProxy - The InstrumentProxy which owns the InstrumentSample.
name - The name of the new InstrumentSample.
interval - The sample interval of the new InstrumentSample.
size - The number of samples to store as history. Assumes that size is at least 1.
description - The description of the new InstrumentSample.
lease - The length of the lease in milliseconds.
Method Detail

getType

public int getType()
Returns the type of the Instrument Sample.

Specified by:
getType in interface InstrumentSample
Returns:
The type of the Instrument Sample.

getInstrumentType

public final int getInstrumentType()
Returns the Type of the Instrument which can use the sample. This should be the same for all instances of a class.

This InstrumentSample returns InstrumentManager.PROFILE_POINT_TYPE_COUNTER

Specified by:
getInstrumentType in interface InstrumentSample
Returns:
The Type of the Instrument which can use the sample.

getValueInner

public int getValueInner()
Obtain the value of the sample. All samples are integers, so the profiled objects must measure quantity (numbers of items), rate (items/period), time in milliseconds, etc.

Specified by:
getValueInner in class AbstractInstrumentSample
Returns:
The sample value.

advanceToNextSample

protected void advanceToNextSample()
The current sample has already been stored. Reset the current sample and move on to the next.

Should only be called when synchronized.

Specified by:
advanceToNextSample in class AbstractInstrumentSample

loadState

protected void loadState(int value,
                         Configuration state)
                  throws ConfigurationException
Used to load the state, called from AbstractInstrumentSample.loadState();

Should only be called when synchronized.

Specified by:
loadState in class AbstractInstrumentSample
Parameters:
value - Current value loaded from the state.
state - Configuration object to load state from.
Throws:
ConfigurationException - If there were any problems loading the state.

postSaveNeedsReset

protected void postSaveNeedsReset()
Called after a state is loaded if the sample period is not the same as the last period saved.

Specified by:
postSaveNeedsReset in class AbstractInstrumentSample

increment

public void increment(java.lang.String instrumentName,
                      int count,
                      long time)
Called by a CounterInstrument whenever its value is incremented.

Specified by:
increment in interface CounterInstrumentListener
Parameters:
instrumentName - The name of Instrument which was incremented.
count - A positive integer to increment the counter by.
time - The time that the Instrument was incremented.

increment

private void increment(int count,
                       long time)
Increments the count.

Parameters:
time - Time that the count is incremented.
count - A positive integer to increment the counter by.

getInstrumentProxy

public InstrumentProxy getInstrumentProxy()
Returns the InstrumentProxy which owns the InstrumentSample.

Specified by:
getInstrumentProxy in interface InstrumentSample
Returns:
The InstrumentProxy which owns the InstrumentSample.

isConfigured

public boolean isConfigured()
Returns true if the Instrument was configured in the instrumentables section of the configuration.

Specified by:
isConfigured in interface InstrumentSample
Returns:
True if configured.

getName

public final java.lang.String getName()
Returns the name of the sample.

Specified by:
getName in interface InstrumentSample
Returns:
The name of the sample.

getInterval

public final long getInterval()
Returns the sample interval. The period of each sample in millisends.

Specified by:
getInterval in interface InstrumentSample
Returns:
The sample interval.

getSize

public final int getSize()
Returns the number of samples in the sample history.

Specified by:
getSize in interface InstrumentSample
Returns:
The size of the sample history.

getDescription

public final java.lang.String getDescription()
Returns the description of the sample.

Specified by:
getDescription in interface InstrumentSample
Returns:
The description of the sample.

getDescriptor

public InstrumentSampleDescriptorLocal getDescriptor()
Returns a Descriptor for the InstrumentSample.

Specified by:
getDescriptor in interface InstrumentSample
Returns:
A Descriptor for the InstrumentSample.

getValue

public final int getValue()
Obtain the value of the sample. All samples are integers, so the profiled objects must measure quantity (numbers of items), rate (items/period), time in milliseconds, etc.

Specified by:
getValue in interface InstrumentSample
Returns:
The sample value.

getTime

public final long getTime()
Obtain the UNIX time of the beginning of the sample.

Specified by:
getTime in interface InstrumentSample
Returns:
The UNIX time of the beginning of the sample.

getLeaseExpirationTime

public long getLeaseExpirationTime()
Returns the time that the current lease expires. Permanent samples will return a value of 0.

Specified by:
getLeaseExpirationTime in interface InstrumentSample
Returns:
The time that the current lease expires.

extendLease

public long extendLease(long lease)
Extends the lease to be lease milliseconds from the current time. Ignored if the lease has already expired.

Specified by:
extendLease in interface InstrumentSample
Parameters:
lease - The length of the lease in milliseconds.
Returns:
The new lease expiration time. Returns 0 if the sample is permanent.

expire

public void expire()
Tells the sample that its lease has expired. No new references to the sample will be made available, but clients which already have access to the sample may continue to use it.

Specified by:
expire in interface InstrumentSample

getSnapshot

public final InstrumentSampleSnapshot getSnapshot()
Obtains a static snapshot of the InstrumentSample.

Specified by:
getSnapshot in interface InstrumentSample
Returns:
A static snapshot of the InstrumentSample.

getStateVersion

public int getStateVersion()
Returns the stateVersion of the sample. The state version will be incremented each time any of the configuration of the sample is modified. Clients can use this value to tell whether or not anything has changed without having to do an exhaustive comparison.

Specified by:
getStateVersion in interface InstrumentSample
Returns:
The state version of the sample.

addInstrumentSampleListener

public void addInstrumentSampleListener(InstrumentSampleListener listener)
Registers a InstrumentSampleListener with a InstrumentSample given a name.

Specified by:
addInstrumentSampleListener in interface InstrumentSample
Parameters:
listener - The listener which should start receiving updates from the InstrumentSample.

removeInstrumentSampleListener

public void removeInstrumentSampleListener(InstrumentSampleListener listener)
Unregisters a InstrumentSampleListener from a InstrumentSample given a name.

Specified by:
removeInstrumentSampleListener in interface InstrumentSample
Parameters:
listener - The listener which should stop receiving updates from the InstrumentSample.

updateListeners

protected void updateListeners(int value,
                               long time)
Notifies any listeners of a change.

Make sure that this is called OUTSIDE of a synchrinization block.

Parameters:
value - The new value.
time - The time that the new value was set.

saveState

public final Configuration saveState()
Saves the current state into a Configuration.

Specified by:
saveState in interface InstrumentSample
Returns:
The state as a Configuration. Returns null if the configuration would not contain any information.

loadState

public final void loadState(Configuration state)
                     throws ConfigurationException
Loads the state into the InstrumentSample.

Specified by:
loadState in interface InstrumentSample
Parameters:
state - Configuration object to load state from.
Throws:
ConfigurationException - If there were any problems loading the state.

setConfigured

void setConfigured()
Sets the configured flag.


saveState

protected void saveState(DefaultConfiguration state)
Allow subclasses to add information into the saved state.

Parameters:
state - State configuration.

update

protected boolean update(long time)
Brings the InstrumentSample's time up to date so that a new value can be added.

Should only be called when synchronized.

Parameters:
time - The time to which the InstrumentSample should be brought up to date.
Returns:
True if listeners should be notified.

stateChanged

protected void stateChanged()
Called whenever the state of the sample is changed.


toString

public java.lang.String toString()
Returns a string representation of the sample.

Returns:
A string representation of the sample.

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.