Class InaccurateSampler<T>

  • Type Parameters:
    T - The type of the values to be sampled.
    All Implemented Interfaces:
    JsonMonitorable, Sampler<T>

    public class InaccurateSampler<T>
    extends Object
    implements Sampler<T>
    A utility for sampling of recent values, using a non-blocking approach for improved performance. A capacity of K doesn't guarantee that last K values are stored, though it is highly probable, assuming that threads aren't likely to perform the sample operation at the exact same time. What this implementation does guarantee, is that the K items stored in the sample are a subset of the last K*Min(P,T) calls to the sampler, where T stands for the number of threads performing sampling, and P stands for the number of cores.
    Author:
    Eyal Schneider
    • Constructor Detail

      • InaccurateSampler

        public InaccurateSampler​(int size,
                                 SampleTextualizer<T> textualizer)
        Constructor
        Parameters:
        size - The number of sampled values to keep
        textualizer - The textualizer to use for converting sample items into text for monitoring purposes
      • InaccurateSampler

        public InaccurateSampler​(int size)
        Constructor
        Parameters:
        size - The number of sampled values to keep
    • Method Detail

      • newValue

        public boolean newValue​(T value)
        Description copied from interface: Sampler
        Notifies about a new value
        Specified by:
        newValue in interface Sampler<T>
        Parameters:
        value - The new value.
        Returns:
        true iff the new value has been recorded in the sample.
      • getSnapshot

        public Collection<T> getSnapshot()
        Specified by:
        getSnapshot in interface Sampler<T>
        Returns:
        The collection of all values currently stored in the sampler. Consistency is not guaranteed (i.e. this is not necessarily a real snapshot of the inner collection). Note that null values or unrecorded values are returned as nulls.
      • getOwnMetrics

        public net.minidev.json.JSONObject getOwnMetrics()
        Specified by:
        getOwnMetrics in interface JsonMonitorable
        Returns:
        The json string describing the entity, not including the child entities.
      • getChildren

        public Map<String,​JsonMonitorable> getChildren()
        Specified by:
        getChildren in interface JsonMonitorable
        Returns:
        The monitorable children of this entity, as [id, JsonExportable] pairs. Using this method, the framework can manage a complete tree to be monitored, where every entity has a unique path.
      • size

        public int size()
        Specified by:
        size in interface Sampler<T>
        Returns:
        The capacity of the sampler