Class AccumulationCache

  • All Implemented Interfaces:
    Accumulator

    public class AccumulationCache
    extends Object
    implements Accumulator
    Expose a local cache of limited size along with a task to flush that cache to the backing store.
    Author:
    Tim Schmidt ([email protected]).
    • Constructor Detail

      • AccumulationCache

        public AccumulationCache​(ConcurrentMap<HistogramKey,​AgentDigest> backingStore,
                                 AgentDigestFactory agentDigestFactory,
                                 long cacheSize,
                                 String metricPrefix,
                                 @Nullable
                                 com.github.benmanes.caffeine.cache.Ticker ticker)
        Constructs a new AccumulationCache instance around backingStore and builds an in-memory index maintaining dispatch times in milliseconds for all HistogramKeys in the backingStore. Setting cacheSize to 0 disables in-memory caching so the cache only maintains the dispatch time index.
        Parameters:
        backingStore - a ConcurrentMap storing AgentDigests
        agentDigestFactory - a factory that generates AgentDigests with pre-defined compression level and TTL time
        cacheSize - maximum size of the cache
        ticker - a nanosecond-precision time source
      • AccumulationCache

        protected AccumulationCache​(ConcurrentMap<HistogramKey,​AgentDigest> backingStore,
                                    AgentDigestFactory agentDigestFactory,
                                    long cacheSize,
                                    String metricPrefix,
                                    @Nullable
                                    com.github.benmanes.caffeine.cache.Ticker ticker,
                                    @Nullable
                                    Runnable onFailure)
        Constructs a new AccumulationCache instance around backingStore and builds an in-memory index maintaining dispatch times in milliseconds for all HistogramKeys in the backingStore. Setting cacheSize to 0 disables in-memory caching, so the cache only maintains the dispatch time index.
        Parameters:
        backingStore - a ConcurrentMap storing AgentDigests
        agentDigestFactory - a factory that generates AgentDigests with pre-defined compression level and TTL time
        cacheSize - maximum size of the cache
        ticker - a nanosecond-precision time source
        onFailure - a Runnable that is invoked when backing store overflows
    • Method Detail

      • put

        public void put​(HistogramKey key,
                        @Nonnull
                        AgentDigest value)
        Update AgentDigest in the cache with another AgentDigest.
        Specified by:
        put in interface Accumulator
        Parameters:
        key - histogram key
        value - AgentDigest to be merged
      • put

        public void put​(HistogramKey key,
                        double value)
        Update AgentDigest in the cache with a double value. If such AgentDigest does not exist for the specified key, it will be created using AgentDigestFactory
        Specified by:
        put in interface Accumulator
        Parameters:
        key - histogram key
        value - value to be merged into the AgentDigest
      • put

        public void put​(HistogramKey key,
                        wavefront.report.Histogram value)
        Update AgentDigest in the cache with a Histogram value. If such AgentDigest does not exist for the specified key, it will be created using AgentDigestFactory.
        Specified by:
        put in interface Accumulator
        Parameters:
        key - histogram key
        value - a Histogram to be merged into the AgentDigest
      • getRipeDigestsIterator

        public Iterator<HistogramKey> getRipeDigestsIterator​(com.wavefront.common.TimeProvider clock)
        Returns an iterator over "ripe" digests ready to be shipped
        Specified by:
        getRipeDigestsIterator in interface Accumulator
        Parameters:
        clock - a millisecond-precision epoch time source
        Returns:
        an iterator over "ripe" digests ready to be shipped
      • compute

        public AgentDigest compute​(HistogramKey key,
                                   BiFunction<? super HistogramKey,​? super AgentDigest,​? extends AgentDigest> remappingFunction)
        Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
        Specified by:
        compute in interface Accumulator
        Parameters:
        key - key with which the specified value is to be associated
        remappingFunction - the function to compute a value
        Returns:
        the new value associated with the specified key, or null if none
      • size

        public long size()
        Returns the number of items in the storage behind the cache
        Specified by:
        size in interface Accumulator
        Returns:
        number of items
      • flush

        public void flush()
        Merge the contents of this cache with the corresponding backing store.
        Specified by:
        flush in interface Accumulator