Package com.newrelic.agent.bridge
Class DefaultCollectionFactory
- java.lang.Object
-
- com.newrelic.agent.bridge.DefaultCollectionFactory
-
- All Implemented Interfaces:
CollectionFactory
public class DefaultCollectionFactory extends java.lang.Object implements CollectionFactory
This implementation ofCollectionFactorywill only be used if the agent-bridge is being used by an application and the agent is NOT being loaded. Thus, it is unlikely that the objects created by this implementation are going to receive much use. So methods in this implementation do not need to implement all functional requirements of the methods in the interface, but they should not break under low use.
-
-
Constructor Summary
Constructors Constructor Description DefaultCollectionFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <K,V>
java.util.function.Function<K,V>createAccessTimeBasedCache(long ageInSeconds, int initialCapacity, java.util.function.Function<K,V> loader)Note: In this implementation, this method will return the loader function as is.<K,V>
java.util.Map<K,V>createConcurrentTimeBasedEvictionMap(long ageInSeconds)Note: In this implementation, this method will return a simple concurrent map since an eviction cache can't be easily created with just vanilla JDK Map SDKs.<K,V>
java.util.Map<K,V>createConcurrentWeakKeyedMap()Create a concurrent-safe, weak-keyed map.<K,V>
java.util.function.Function<K,V>memorize(java.util.function.Function<K,V> loader, int maxSize)Wraps the provided function into one that will cache the results for future calls.
-
-
-
Method Detail
-
createConcurrentWeakKeyedMap
public <K,V> java.util.Map<K,V> createConcurrentWeakKeyedMap()
Description copied from interface:CollectionFactoryCreate a concurrent-safe, weak-keyed map.- Specified by:
createConcurrentWeakKeyedMapin interfaceCollectionFactory- Type Parameters:
K- Key typeV- Value type- Returns:
- concurrent-safe, weak-keyed map
-
createConcurrentTimeBasedEvictionMap
public <K,V> java.util.Map<K,V> createConcurrentTimeBasedEvictionMap(long ageInSeconds)
Note: In this implementation, this method will return a simple concurrent map since an eviction cache can't be easily created with just vanilla JDK Map SDKs.- Specified by:
createConcurrentTimeBasedEvictionMapin interfaceCollectionFactory- Type Parameters:
K- key typeV- value type- Parameters:
ageInSeconds- how old, in seconds, a cache entry must be to be evicted after last write- Returns:
- a time based concurrent cache
-
memorize
public <K,V> java.util.function.Function<K,V> memorize(java.util.function.Function<K,V> loader, int maxSize)Description copied from interface:CollectionFactoryWraps the provided function into one that will cache the results for future calls.- Specified by:
memorizein interfaceCollectionFactory- Type Parameters:
K- the type of keyV- the type of value stored/returned- Parameters:
loader- the function that calculates the value.maxSize- the max number of items to be cached.- Returns:
- the cached item, or the result of the loader call.
-
createAccessTimeBasedCache
public <K,V> java.util.function.Function<K,V> createAccessTimeBasedCache(long ageInSeconds, int initialCapacity, java.util.function.Function<K,V> loader)Note: In this implementation, this method will return the loader function as is.- Specified by:
createAccessTimeBasedCachein interfaceCollectionFactory- Type Parameters:
K- key typeV- cached type- Parameters:
ageInSeconds- how old, in seconds, a cache entry must be to be evicted after last accessinitialCapacity- the initial capacity of the cacheloader- the function to calculate the value for a key, used if the key is not cached- Returns:
- a time based concurrent cache
-
-