ehcache

net.sf.ehcache.util.counter.sampled
Class SampledCounterImpl

java.lang.Object
  extended by net.sf.ehcache.util.counter.CounterImpl
      extended by net.sf.ehcache.util.counter.sampled.SampledCounterImpl
All Implemented Interfaces:
Serializable, Counter, SampledCounter
Direct Known Subclasses:
SampledRateCounterImpl

public class SampledCounterImpl
extends CounterImpl
implements SampledCounter

An implementation of SampledCounter

Since:
1.7
Author:
Abhishek Sanoujam
See Also:
Serialized Form

Field Summary
protected  CircularLossyQueue<TimeStampedCounterValue> history
          The history of this counter
protected  boolean resetOnSample
          Should the counter reset on each sample?
 
Constructor Summary
SampledCounterImpl(long intervalInSeconds, int historySize, boolean resetOnSample, long initValue, boolean sampleNow)
          Constructor accepting raw config values.
SampledCounterImpl(SampledCounterConfig config)
          todo GL how many threads is this creating? Constructor accepting a SampledCounterConfig
 
Method Summary
 TimeStampedCounterValue[] getAllSampleValues()
          Returns all samples in history
 long getAndReset()
          Returns the current value of the counter and resets it to 0
 long getIntervalMillis()
          Returns the sampling thread interval in millis
 TimeStampedCounterValue getMostRecentSample()
          Returns the most recent sampled value
 TimerTask getTimerTask()
          Returns the timer task for this sampled counter
 void shutdown()
          Shutdown this counter
 
Methods inherited from class net.sf.ehcache.util.counter.CounterImpl
decrement, decrement, getAndSet, getValue, increment, increment, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.ehcache.util.counter.Counter
decrement, decrement, getAndSet, getValue, increment, increment, setValue
 

Field Detail

history

protected final CircularLossyQueue<TimeStampedCounterValue> history
The history of this counter


resetOnSample

protected final boolean resetOnSample
Should the counter reset on each sample?

Constructor Detail

SampledCounterImpl

public SampledCounterImpl(SampledCounterConfig config)
todo GL how many threads is this creating? Constructor accepting a SampledCounterConfig

Parameters:
config -

SampledCounterImpl

public SampledCounterImpl(long intervalInSeconds,
                          int historySize,
                          boolean resetOnSample,
                          long initValue,
                          boolean sampleNow)
Constructor accepting raw config values.

Parameters:
intervalInSeconds - sampling interval in seconds
historySize - size of history sample
resetOnSample - true to reset value on sample
initValue - initial value
sampleNow - true to record smaple immediately
Method Detail

getMostRecentSample

public TimeStampedCounterValue getMostRecentSample()
Returns the most recent sampled value

Specified by:
getMostRecentSample in interface SampledCounter
Returns:
Value of the most recent sampled value

getAllSampleValues

public TimeStampedCounterValue[] getAllSampleValues()
Returns all samples in history

Specified by:
getAllSampleValues in interface SampledCounter
Returns:
An array containing the TimeStampedCounterValue's

shutdown

public void shutdown()
Shutdown this counter

Specified by:
shutdown in interface SampledCounter

getTimerTask

public TimerTask getTimerTask()
Returns the timer task for this sampled counter

Returns:
the timer task for this sampled counter

getIntervalMillis

public long getIntervalMillis()
Returns the sampling thread interval in millis

Returns:
the sampling thread interval in millis

getAndReset

public long getAndReset()
Returns the current value of the counter and resets it to 0

Specified by:
getAndReset in interface SampledCounter
Returns:
current value of the counter

ehcache

Copyright 2001-2017, Terracotta, Inc.