Class 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.Sampling
    A sampler metric which aggregates timing durations and provides duration statistics, plus throughput statistics via Meter.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Sampler.Context
      A timing context.
    • Constructor Summary

      Constructors 
      Constructor Description
      Sampler​(java.util.concurrent.ScheduledExecutorService executorService)
      Creates a new Sampler using an ExponentiallyDecayingReservoir and the default Clock.
      Sampler​(org.xbib.metrics.api.Reservoir reservoir, java.util.concurrent.ScheduledExecutorService executorService)
      Creates a new Sampler that uses the given Reservoir.
      Sampler​(org.xbib.metrics.api.Reservoir reservoir, org.xbib.metrics.api.Clock clock, java.util.concurrent.ScheduledExecutorService executorService)
      Creates a new Sampler that uses the given Reservoir and Clock.
    • Constructor Detail

      • Sampler

        public Sampler​(java.util.concurrent.ScheduledExecutorService executorService)
        Creates a new Sampler using an ExponentiallyDecayingReservoir and the default Clock.
        Parameters:
        executorService - the executor service
      • Sampler

        public Sampler​(org.xbib.metrics.api.Reservoir reservoir,
                       java.util.concurrent.ScheduledExecutorService executorService)
        Creates a new Sampler that uses the given Reservoir.
        Parameters:
        reservoir - the Reservoir implementation the sampler should use
        executorService - the executor service
      • Sampler

        public Sampler​(org.xbib.metrics.api.Reservoir reservoir,
                       org.xbib.metrics.api.Clock clock,
                       java.util.concurrent.ScheduledExecutorService executorService)
        Creates a new Sampler that uses the given Reservoir and Clock.
        Parameters:
        reservoir - the Reservoir implementation the sampler should use
        clock - the Clock implementation the sampler should use
        executorService - 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 duration
        unit - the scale unit of duration
      • time

        public <T> T time​(java.util.concurrent.Callable<T> event)
                   throws java.lang.Exception
        Records the duration of event.
        Type Parameters:
        T - the type of the value returned by event
        Parameters:
        event - a Callable whose Callable.call() method implements a process whose duration should be timed
        Returns:
        the value returned by event
        Throws:
        java.lang.Exception - if event throws an Exception
      • time

        public void time​(java.lang.Runnable event)
        Times and records the duration of an event.
        Parameters:
        event - a Runnable whose Runnable.run() method implements a process whose duration should be timed
      • getCount

        public long getCount()
        Specified by:
        getCount in interface org.xbib.metrics.api.Metered
      • getFifteenMinuteRate

        public double getFifteenMinuteRate()
        Specified by:
        getFifteenMinuteRate in interface org.xbib.metrics.api.Metered
      • getFiveMinuteRate

        public double getFiveMinuteRate()
        Specified by:
        getFiveMinuteRate in interface org.xbib.metrics.api.Metered
      • getMeanRate

        public double getMeanRate()
        Specified by:
        getMeanRate in interface org.xbib.metrics.api.Metered
      • getOneMinuteRate

        public double getOneMinuteRate()
        Specified by:
        getOneMinuteRate in interface org.xbib.metrics.api.Metered
      • getSnapshot

        public org.xbib.metrics.api.Snapshot getSnapshot()
        Specified by:
        getSnapshot in interface org.xbib.metrics.api.Sampling