Class Sampler<T>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Sampler.Sample<S>
      Represents the ranked items collected during a sample period
      static class  Sampler.SamplerType  
    • Constructor Summary

      Constructors 
      Constructor Description
      Sampler()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addSample​(T item, int value)  
      abstract void beginSampling​(int capacity, long durationMillis)
      Begin sampling with the configured capacity and duration
      void disable()  
      abstract java.util.List<Sampler.Sample<T>> finishSampling​(int count)
      Stop sampling and return the results
      protected abstract void insert​(T item, long value)  
      boolean isActive()  
      boolean isEnabled()
      A sampler is enabled between {@link this#beginSampling} and {@link this#finishSampling}
      static void shutdownNowAndWait​(long time, java.util.concurrent.TimeUnit units)  
      abstract java.lang.String toString​(T value)  
      void updateEndTime​(long endTimeMillis)
      Update the end time for the sampler.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Sampler

        public Sampler()
    • Method Detail

      • addSample

        public void addSample​(T item,
                              int value)
      • insert

        protected abstract void insert​(T item,
                                       long value)
      • isEnabled

        public boolean isEnabled()
        A sampler is enabled between {@link this#beginSampling} and {@link this#finishSampling}
        Returns:
        true if the sampler is enabled.
      • disable

        public void disable()
      • isActive

        public boolean isActive()
        Returns:
        true if the sampler is active. A sampler is active only if it is enabled and the current time is within the `durationMillis` when beginning sampling.
      • updateEndTime

        public void updateEndTime​(long endTimeMillis)
        Update the end time for the sampler. Implicitly, calling this method enables the sampler.
      • beginSampling

        public abstract void beginSampling​(int capacity,
                                           long durationMillis)
        Begin sampling with the configured capacity and duration
        Parameters:
        capacity - Number of sample items to keep in memory, the lower this is the less accurate results are. For best results use value close to cardinality, but understand the memory trade offs.
        durationMillis - Upperbound duration in milliseconds for sampling. The sampler stops accepting new samples after exceeding the duration even if finishSampling(int)} is not called.
      • finishSampling

        public abstract java.util.List<Sampler.Sample<T>> finishSampling​(int count)
        Stop sampling and return the results
        Parameters:
        count - The number of the samples requested to retrieve from the sampler
        Returns:
        a list of samples, the size is the minimum of the total samples and {@param count}.
      • toString

        public abstract java.lang.String toString​(T value)
      • shutdownNowAndWait

        public static void shutdownNowAndWait​(long time,
                                              java.util.concurrent.TimeUnit units)
                                       throws java.lang.InterruptedException,
                                              java.util.concurrent.TimeoutException
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.TimeoutException