org.javasimon.callback.lastsplits
Class LastSplits

java.lang.Object
  extended by org.javasimon.callback.lastsplits.LastSplits
All Implemented Interfaces:
LogMessageSource<Split>

public class LastSplits
extends Object
implements LogMessageSource<Split>

Object stored among Stopwatch's attributes in charge of

Since:
3.2
Author:
gquintana

Nested Class Summary
private static class LastSplits.AbstractSplitFunction<T>
          Base implementation of functions
private static interface LastSplits.SplitFunction<T>
          Function
 
Field Summary
private  LogTemplate<Split> logTemplate
          Log template used to log this list of splits
private  CircularList<Split> splits
          Ring buffer containing splits
 
Constructor Summary
LastSplits(int capacity)
          Constructor with ring buffer size
 
Method Summary
 void add(Split split)
          Add split to the buffer
 void clear()
          Remove all splits from buffer
 int getCount()
          Get number of splits in the buffer
 String getLogMessage(Split lastSplit)
          Transform this list of splits into a loggable message
 LogTemplate<Split> getLogTemplate()
           
 Long getMax()
          Compute the longest duration of splits in the buffer
 Double getMean()
          Compute mean duration of splits in the buffer
 Long getMin()
          Compute the smallest duration of splits in the buffer
private  String getSplitsAsString()
          Transforms split values into a String
 Double getTrend()
          Compute a trend of duration: the average delta of splits between 2 splits spaced of at least 1 ms.
 Double getTrend(long timeDeltaThreshold)
          Compute a trend of duration: the average delta of splits between 2 split spaced of at least the given threshold.
 void log(Split lastSplit)
          Log eventually this list of splits into log template
private
<T> T
processFunction(LastSplits.SplitFunction<T> function)
          Evaluate a function over the list of splits
 void setLogTemplate(LogTemplate<Split> logTemplate)
           
 String toString()
          String containing: count, min, mean, max and trend(1ms).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

splits

private final CircularList<Split> splits
Ring buffer containing splits


logTemplate

private LogTemplate<Split> logTemplate
Log template used to log this list of splits

Constructor Detail

LastSplits

public LastSplits(int capacity)
Constructor with ring buffer size

Parameters:
capacity - Buffer size
Method Detail

add

public void add(Split split)
Add split to the buffer

Parameters:
split - Split

clear

public void clear()
Remove all splits from buffer


getLogTemplate

public LogTemplate<Split> getLogTemplate()

setLogTemplate

public void setLogTemplate(LogTemplate<Split> logTemplate)

getCount

public int getCount()
Get number of splits in the buffer

Returns:
Split number

processFunction

private <T> T processFunction(LastSplits.SplitFunction<T> function)
Evaluate a function over the list of splits

Type Parameters:
T - Function result type
Parameters:
function - Function to evaluate
Returns:
Function result, null if no splits

getMean

public Double getMean()
Compute mean duration of splits in the buffer

Returns:
Mean or average

getMin

public Long getMin()
Compute the smallest duration of splits in the buffer

Returns:
Minimum

getMax

public Long getMax()
Compute the longest duration of splits in the buffer

Returns:
Maximum

getTrend

public Double getTrend()
Compute a trend of duration: the average delta of splits between 2 splits spaced of at least 1 ms. Sum(splits(t[n])-splits(t[n-1])/SizeOf(splits)

Returns:
Trend, average delta of splits

getTrend

public Double getTrend(long timeDeltaThreshold)
Compute a trend of duration: the average delta of splits between 2 split spaced of at least the given threshold. The threshold is only here to avoid computing a delta between 2 splits occuring at the same time by 2 different threads. Sum(splits(t[n])-splits(t[n-1])/SizeOf(splits)

Parameters:
timeDeltaThreshold - Accepted splits space
Returns:
Trend, average delta of splits

getSplitsAsString

private String getSplitsAsString()
Transforms split values into a String

Returns:
Splits presented in a String

toString

public String toString()
String containing: count, min, mean, max and trend(1ms). This method can be expensive, because many computations are done.

Overrides:
toString in class Object
Returns:
String

getLogMessage

public String getLogMessage(Split lastSplit)
Transform this list of splits into a loggable message

Specified by:
getLogMessage in interface LogMessageSource<Split>
Parameters:
lastSplit - Context
Returns:
Message

log

public void log(Split lastSplit)
Log eventually this list of splits into log template



Copyright © 2013. All Rights Reserved.