Class AccumulationCache
- java.lang.Object
-
- com.wavefront.agent.histogram.accumulator.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 Summary
Constructors Modifier Constructor Description AccumulationCache(ConcurrentMap<HistogramKey,AgentDigest> backingStore, AgentDigestFactory agentDigestFactory, long cacheSize, String metricPrefix, com.github.benmanes.caffeine.cache.Ticker ticker)
Constructs a new AccumulationCache instance aroundbackingStore
and builds an in-memory index maintaining dispatch times in milliseconds for all HistogramKeys in the backingStore.protected
AccumulationCache(ConcurrentMap<HistogramKey,AgentDigest> backingStore, AgentDigestFactory agentDigestFactory, long cacheSize, String metricPrefix, com.github.benmanes.caffeine.cache.Ticker ticker, Runnable onFailure)
Constructs a new AccumulationCache instance aroundbackingStore
and builds an in-memory index maintaining dispatch times in milliseconds for all HistogramKeys in the backingStore.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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).void
flush()
Merge the contents of this cache with the corresponding backing store.Iterator<HistogramKey>
getRipeDigestsIterator(com.wavefront.common.TimeProvider clock)
Returns an iterator over "ripe" digests ready to be shippedvoid
put(HistogramKey key, double value)
UpdateAgentDigest
in the cache with a double value.void
put(HistogramKey key, AgentDigest value)
UpdateAgentDigest
in the cache with anotherAgentDigest
.void
put(HistogramKey key, wavefront.report.Histogram value)
UpdateAgentDigest
in the cache with aHistogram
value.long
size()
Returns the number of items in the storage behind the cache
-
-
-
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 aroundbackingStore
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
- aConcurrentMap
storingAgentDigests
agentDigestFactory
- a factory that generatesAgentDigests
with pre-defined compression level and TTL timecacheSize
- maximum size of the cacheticker
- 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 aroundbackingStore
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
- aConcurrentMap
storingAgentDigests
agentDigestFactory
- a factory that generatesAgentDigests
with pre-defined compression level and TTL timecacheSize
- maximum size of the cacheticker
- a nanosecond-precision time sourceonFailure
- aRunnable
that is invoked when backing store overflows
-
-
Method Detail
-
put
public void put(HistogramKey key, @Nonnull AgentDigest value)
UpdateAgentDigest
in the cache with anotherAgentDigest
.- Specified by:
put
in interfaceAccumulator
- Parameters:
key
- histogram keyvalue
-AgentDigest
to be merged
-
put
public void put(HistogramKey key, double value)
UpdateAgentDigest
in the cache with a double value. If suchAgentDigest
does not exist for the specified key, it will be created usingAgentDigestFactory
- Specified by:
put
in interfaceAccumulator
- Parameters:
key
- histogram keyvalue
- value to be merged into theAgentDigest
-
put
public void put(HistogramKey key, wavefront.report.Histogram value)
UpdateAgentDigest
in the cache with aHistogram
value. If suchAgentDigest
does not exist for the specified key, it will be created usingAgentDigestFactory
.- Specified by:
put
in interfaceAccumulator
- Parameters:
key
- histogram keyvalue
- aHistogram
to be merged into theAgentDigest
-
getRipeDigestsIterator
public Iterator<HistogramKey> getRipeDigestsIterator(com.wavefront.common.TimeProvider clock)
Returns an iterator over "ripe" digests ready to be shipped- Specified by:
getRipeDigestsIterator
in interfaceAccumulator
- 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 interfaceAccumulator
- Parameters:
key
- key with which the specified value is to be associatedremappingFunction
- 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 interfaceAccumulator
- Returns:
- number of items
-
flush
public void flush()
Merge the contents of this cache with the corresponding backing store.- Specified by:
flush
in interfaceAccumulator
-
-