Package org.xbib.metrics.common
Class Sampler
- java.lang.Object
-
- org.xbib.metrics.common.Sampler
-
- All Implemented Interfaces:
org.xbib.metrics.api.Metered,org.xbib.metrics.api.Metric,org.xbib.metrics.api.Sampling
public class Sampler extends java.lang.Object implements org.xbib.metrics.api.Metered, org.xbib.metrics.api.SamplingA sampler metric which aggregates timing durations and provides duration statistics, plus throughput statistics viaMeter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSampler.ContextA timing context.
-
Constructor Summary
Constructors Constructor Description Sampler(java.util.concurrent.ScheduledExecutorService executorService)Sampler(org.xbib.metrics.api.Reservoir reservoir, java.util.concurrent.ScheduledExecutorService executorService)Creates a newSamplerthat uses the givenReservoir.Sampler(org.xbib.metrics.api.Reservoir reservoir, org.xbib.metrics.api.Clock clock, java.util.concurrent.ScheduledExecutorService executorService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetCount()doublegetFifteenMinuteRate()doublegetFiveMinuteRate()doublegetMeanRate()doublegetOneMinuteRate()org.xbib.metrics.api.SnapshotgetSnapshot()Sampler.Contexttime()Returns a newSampler.Context.voidtime(java.lang.Runnable event)Times and records the duration of an event.<T> Ttime(java.util.concurrent.Callable<T> event)Records the duration of event.voidupdate(long duration, java.util.concurrent.TimeUnit unit)Adds a recorded duration.
-
-
-
Constructor Detail
-
Sampler
public Sampler(java.util.concurrent.ScheduledExecutorService executorService)
- Parameters:
executorService- the executor service
-
Sampler
public Sampler(org.xbib.metrics.api.Reservoir reservoir, java.util.concurrent.ScheduledExecutorService executorService)Creates a newSamplerthat uses the givenReservoir.- Parameters:
reservoir- theReservoirimplementation the sampler should useexecutorService- the executor service
-
Sampler
public Sampler(org.xbib.metrics.api.Reservoir reservoir, org.xbib.metrics.api.Clock clock, java.util.concurrent.ScheduledExecutorService executorService)- Parameters:
reservoir- theReservoirimplementation the sampler should useclock- theClockimplementation the sampler should useexecutorService- the executor service
-
-
Method Detail
-
update
public void update(long duration, java.util.concurrent.TimeUnit unit)Adds a recorded duration.- Parameters:
duration- the length of the durationunit- the scale unit ofduration
-
time
public <T> T time(java.util.concurrent.Callable<T> event) throws java.lang.ExceptionRecords the duration of event.- Type Parameters:
T- the type of the value returned byevent- Parameters:
event- aCallablewhoseCallable.call()method implements a process whose duration should be timed- Returns:
- the value returned by
event - Throws:
java.lang.Exception- ifeventthrows anException
-
time
public void time(java.lang.Runnable event)
Times and records the duration of an event.- Parameters:
event- aRunnablewhoseRunnable.run()method implements a process whose duration should be timed
-
time
public Sampler.Context time()
Returns a newSampler.Context.- Returns:
- a new
Sampler.Context - See Also:
Sampler.Context
-
getCount
public long getCount()
- Specified by:
getCountin interfaceorg.xbib.metrics.api.Metered
-
getFifteenMinuteRate
public double getFifteenMinuteRate()
- Specified by:
getFifteenMinuteRatein interfaceorg.xbib.metrics.api.Metered
-
getFiveMinuteRate
public double getFiveMinuteRate()
- Specified by:
getFiveMinuteRatein interfaceorg.xbib.metrics.api.Metered
-
getMeanRate
public double getMeanRate()
- Specified by:
getMeanRatein interfaceorg.xbib.metrics.api.Metered
-
getOneMinuteRate
public double getOneMinuteRate()
- Specified by:
getOneMinuteRatein interfaceorg.xbib.metrics.api.Metered
-
getSnapshot
public org.xbib.metrics.api.Snapshot getSnapshot()
- Specified by:
getSnapshotin interfaceorg.xbib.metrics.api.Sampling
-
-