Class DefaultCollectionFactory

  • All Implemented Interfaces:
    CollectionFactory

    public class DefaultCollectionFactory
    extends java.lang.Object
    implements CollectionFactory
    This implementation of CollectionFactory will 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.
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultCollectionFactory

        public DefaultCollectionFactory()
    • Method Detail

      • createConcurrentWeakKeyedMap

        public <K,​V> java.util.Map<K,​V> createConcurrentWeakKeyedMap()
        Description copied from interface: CollectionFactory
        Create a concurrent-safe, weak-keyed map.
        Specified by:
        createConcurrentWeakKeyedMap in interface CollectionFactory
        Type Parameters:
        K - Key type
        V - 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:
        createConcurrentTimeBasedEvictionMap in interface CollectionFactory
        Type Parameters:
        K - key type
        V - 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: CollectionFactory
        Wraps the provided function into one that will cache the results for future calls.
        Specified by:
        memorize in interface CollectionFactory
        Type Parameters:
        K - the type of key
        V - 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:
        createAccessTimeBasedCache in interface CollectionFactory
        Type Parameters:
        K - key type
        V - cached type
        Parameters:
        ageInSeconds - how old, in seconds, a cache entry must be to be evicted after last access
        initialCapacity - the initial capacity of the cache
        loader - the function to calculate the value for a key, used if the key is not cached
        Returns:
        a time based concurrent cache