Class ReservoirTraceStorageStrategy

  • All Implemented Interfaces:
    TraceStorageStrategy

    public class ReservoirTraceStorageStrategy
    extends Object
    implements TraceStorageStrategy
    Strategy for finding traces that need removing from a list, according to a reservoir sampling algorithm. https://en.wikipedia.org/wiki/Reservoir_sampling.
    • Constructor Detail

      • ReservoirTraceStorageStrategy

        public ReservoirTraceStorageStrategy()
      • ReservoirTraceStorageStrategy

        protected ReservoirTraceStorageStrategy​(long seed)
    • Method Detail

      • getTraceForRemoval

        public RequestTrace getTraceForRemoval​(Collection<RequestTrace> traces,
                                               int maxSize,
                                               RequestTrace traceToRemove)
        Gets the trace that needs removing. Removes the provided trace if present, or a random trace each trace having the same probability of being kept or removed.
        Specified by:
        getTraceForRemoval in interface TraceStorageStrategy
        Parameters:
        traces - the list of traces to test.
        maxSize - the maximum size of the list.
        traceToRemove - the trace to remove if present
        Returns:
        the trace that needs removing, or null if no traces need removing.