org.javasimon.callback.lastsplits
Class LastSplitsCallback

java.lang.Object
  extended by org.javasimon.callback.CallbackSkeleton
      extended by org.javasimon.callback.lastsplits.LastSplitsCallback
All Implemented Interfaces:
Callback

public class LastSplitsCallback
extends CallbackSkeleton

Callback retaining the last N stopwatch splits. Splits can be logged when buffer revolves.

Since:
3.2
Author:
gquintana
See Also:
LastSplits

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javasimon.callback.Callback
Callback.Event
 
Field Summary
static String ATTR_NAME_LAST_SPLITS
          Simon attribute name of the LastSplit object stored in Simons.
private  int capacity
          Number of splits retained in each Simon.
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
LastSplitsCallback()
          Default constructor with a buffer capacity of 10.
LastSplitsCallback(int capacity)
          Constructor with buffer capacity.
 
Method Summary
protected  LogTemplate<Split> createLogTemplate(Stopwatch stopwatch)
          Create log template for given stopwatch.
private  LastSplits getLastSplits(Stopwatch stopwatch)
          Get the LastSplits object from Simon attributes.
 boolean isLogEnabled()
           
 void onSimonCreated(Simon simon)
          When Stopwatch is created, a Last Splits attributes is added.
 void onSimonReset(Simon simon)
          When the Stopwatch is reseted, the Last splits attribute as well.
 void onStopwatchStop(Split split, StopwatchSample sample)
          When a Splits is stopped, it is added to the stopwatch a Last Splits attribute.
 void setLogEnabled(boolean logEnabled)
           
 
Methods inherited from class org.javasimon.callback.CallbackSkeleton
cleanup, initialize, onCounterDecrease, onCounterIncrease, onCounterSet, onManagerClear, onManagerMessage, onManagerWarning, onSimonDestroyed, onStopwatchAdd, onStopwatchAdd, onStopwatchStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTR_NAME_LAST_SPLITS

public static final String ATTR_NAME_LAST_SPLITS
Simon attribute name of the LastSplit object stored in Simons.

See Also:
Constant Field Values

capacity

private final int capacity
Number of splits retained in each Simon. Default 10


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.

Constructor Detail

LastSplitsCallback

public LastSplitsCallback()
Default constructor with a buffer capacity of 10.


LastSplitsCallback

public LastSplitsCallback(int capacity)
Constructor with buffer capacity.

Parameters:
capacity - buffer capacity
Method Detail

getLastSplits

private LastSplits getLastSplits(Stopwatch stopwatch)
Get the LastSplits object from Simon attributes.

Parameters:
stopwatch - stopwatch
Returns:
LastSplits object

onSimonCreated

public void onSimonCreated(Simon simon)
When Stopwatch is created, a Last Splits attributes is added.

Specified by:
onSimonCreated in interface Callback
Overrides:
onSimonCreated in class CallbackSkeleton
Parameters:
simon - created Simon

onStopwatchStop

public void onStopwatchStop(Split split,
                            StopwatchSample sample)
When a Splits is stopped, it is added to the stopwatch a Last Splits attribute.

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

onSimonReset

public void onSimonReset(Simon simon)
When the Stopwatch is reseted, the Last splits attribute as well.

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

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 isLogEnabled() is set, last splits are logged at each buffer revolution.

Parameters:
stopwatch - Stopwatch
Returns:
Log template


Copyright © 2013. All Rights Reserved.