org.javasimon.callback.quantiles
Class QuantilesCallback

java.lang.Object
  extended by org.javasimon.callback.CallbackSkeleton
      extended by org.javasimon.callback.quantiles.QuantilesCallback
All Implemented Interfaces:
Callback
Direct Known Subclasses:
AutoQuantilesCallback, FixedQuantilesCallback, PropertiesQuantilesCallback

public abstract class QuantilesCallback
extends CallbackSkeleton

Callback which stores data in buckets to compute quantiles. The #createBuckets(org.javasimon.Stopwatch) should be implemented to configure the width and resolution of buckets. Then {@link Buckets} are stored among Simon attributes. There are 2 implementations:

Since:
3.2
Author:
gquintana
See Also:
Buckets

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javasimon.callback.Callback
Callback.Event
 
Field Summary
static String ATTR_NAME_BUCKETS
          Simon attribute name of the buckets stored in Simons after warmup time.
private  BucketsType bucketsType
          Type of the buckets: linear or exponential
private  LogTemplate<Split> enabledStopwatchLogTemplate
          SLF4J log template shared by all stopwatches.
private  boolean logEnabled
          Global flag indicating whether last splits should be logged once in a while.
 
Constructor Summary
protected QuantilesCallback()
          Default constructor.
protected QuantilesCallback(BucketsType bucketsType)
          Constructor with buckets type
 
Method Summary
protected abstract  Buckets createBuckets(Stopwatch stopwatch)
          Create Buckets for given stopwatch.
protected  Buckets createBuckets(Stopwatch stopwatch, long min, long max, int bucketNb)
          Factory method to create a Buckets object using given configuration
protected  LogTemplate<Split> createLogTemplate(Stopwatch stopwatch)
          Create log template for given stopwatch.
static Buckets getBuckets(Stopwatch stopwatch)
          Get the buckets attribute.
 BucketsType getBucketsType()
          Get buckets type
protected  Buckets getOrCreateBuckets(Stopwatch stopwatch)
          Get the buckets attribute or create it if it does not exist.
 boolean isLogEnabled()
           
 void onSimonReset(Simon simon)
          When the Stopwatch is reseted, so are the buckets.
 void onStopwatchAdd(Stopwatch stopwatch, long value, StopwatchSample sample)
          When a split is added, if buckets have been initialized, the value is added to appropriate bucket.
 void onStopwatchAdd(Stopwatch stopwatch, Split split, StopwatchSample sample)
          When a split is added, if buckets have been initialized, the value is added to appropriate bucket.
protected  void onStopwatchSplit(Stopwatch stopwatch, long value)
          Called internally when there is a new split on a Stopwatch from {@link #onStopwatchAdd(org.javasimon.Stopwatch, long, org.javasimon.StopwatchSample).
protected  void onStopwatchSplit(Stopwatch stopwatch, Split split)
          Called when there is a new split on a Stopwatch, either onStopwatchStop(org.javasimon.Split, org.javasimon.StopwatchSample) or onStopwatchAdd(org.javasimon.Stopwatch, org.javasimon.Split, org.javasimon.StopwatchSample).
 void onStopwatchStop(Split split, StopwatchSample sample)
          When a split is stopped, if buckets have been initialized, the value is added to appropriate bucket.
static BucketsSample sampleBuckets(Stopwatch stopwatch)
          Get the buckets attribute and sample them
 void setLogEnabled(boolean logEnabled)
           
 
Methods inherited from class org.javasimon.callback.CallbackSkeleton
cleanup, initialize, onCounterDecrease, onCounterIncrease, onCounterSet, onManagerClear, onManagerMessage, onManagerWarning, onSimonCreated, onSimonDestroyed, onStopwatchStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTR_NAME_BUCKETS

public static final String ATTR_NAME_BUCKETS
Simon attribute name of the buckets stored in Simons after warmup time.

See Also:
Constant Field Values

logEnabled

private boolean logEnabled
Global flag indicating whether last splits should be logged once in a while.


enabledStopwatchLogTemplate

private final LogTemplate<Split> enabledStopwatchLogTemplate
SLF4J log template shared by all stopwatches.


bucketsType

private BucketsType bucketsType
Type of the buckets: linear or exponential

Constructor Detail

QuantilesCallback

protected QuantilesCallback()
Default constructor.


QuantilesCallback

protected QuantilesCallback(BucketsType bucketsType)
Constructor with buckets type

Parameters:
bucketsType - Type of buckets
Method Detail

getBucketsType

public BucketsType getBucketsType()
Get buckets type

Returns:
Buckets type

isLogEnabled

public boolean isLogEnabled()

setLogEnabled

public void setLogEnabled(boolean logEnabled)

createLogTemplate

protected LogTemplate<Split> createLogTemplate(Stopwatch stopwatch)
Create log template for given stopwatch. This method can be overridden to tune logging strategy. By default, when enabled, quantiles are logged at most once per minute

Parameters:
stopwatch - Stopwatch
Returns:
Logger

getBuckets

public static Buckets getBuckets(Stopwatch stopwatch)
Get the buckets attribute.


createBuckets

protected final Buckets createBuckets(Stopwatch stopwatch,
                                      long min,
                                      long max,
                                      int bucketNb)
Factory method to create a Buckets object using given configuration

Parameters:
stopwatch - Target Stopwatch
min - Min bound
max - Max bound
bucketNb - Number of buckets between min and max
Returns:
Buckets

createBuckets

protected abstract Buckets createBuckets(Stopwatch stopwatch)
Create Buckets for given stopwatch. Call {@link #createBuckets(org.javasimon.Stopwatch, long, long, int) to create a new buckets object.

Parameters:
stopwatch - Stopwatch
Returns:
Buckets

getOrCreateBuckets

protected final Buckets getOrCreateBuckets(Stopwatch stopwatch)
Get the buckets attribute or create it if it does not exist.


sampleBuckets

public static BucketsSample sampleBuckets(Stopwatch stopwatch)
Get the buckets attribute and sample them


onStopwatchSplit

protected void onStopwatchSplit(Stopwatch stopwatch,
                                Split split)
Called when there is a new split on a Stopwatch, either onStopwatchStop(org.javasimon.Split, org.javasimon.StopwatchSample) or onStopwatchAdd(org.javasimon.Stopwatch, org.javasimon.Split, org.javasimon.StopwatchSample). If buckets have been initialized, the value is added to appropriate bucket.


onStopwatchSplit

protected void onStopwatchSplit(Stopwatch stopwatch,
                                long value)
Called internally when there is a new split on a Stopwatch from {@link #onStopwatchAdd(org.javasimon.Stopwatch, long, org.javasimon.StopwatchSample). If buckets have been initialized, the value is added to appropriate bucket.


onStopwatchStop

public void onStopwatchStop(Split split,
                            StopwatchSample sample)
When a split is stopped, if buckets have been initialized, the value is added to appropriate bucket.

Specified by:
onStopwatchStop in interface Callback
Overrides:
onStopwatchStop in class CallbackSkeleton
Parameters:
split - stopped Split
sample - stopwatch sampled after the stop

onStopwatchAdd

public void onStopwatchAdd(Stopwatch stopwatch,
                           Split split,
                           StopwatchSample sample)
When a split is added, if buckets have been initialized, the value is added to appropriate bucket.

Specified by:
onStopwatchAdd in interface Callback
Overrides:
onStopwatchAdd in class CallbackSkeleton
Parameters:
stopwatch - modified Stopwatch
split - added split object
sample - stopwatch sampled after the add

onStopwatchAdd

public void onStopwatchAdd(Stopwatch stopwatch,
                           long value,
                           StopwatchSample sample)
When a split is added, if buckets have been initialized, the value is added to appropriate bucket.

Specified by:
onStopwatchAdd in interface Callback
Overrides:
onStopwatchAdd in class CallbackSkeleton
Parameters:
stopwatch - modified Stopwatch
value - added split time in ns
sample - stopwatch sampled after the add

onSimonReset

public void onSimonReset(Simon simon)
When the Stopwatch is reseted, so are the buckets.

Specified by:
onSimonReset in interface Callback
Overrides:
onSimonReset in class CallbackSkeleton
Parameters:
simon - reset Simon


Copyright © 2013. All Rights Reserved.