Interface CollectionFactory

  • All Known Implementing Classes:
    DefaultCollectionFactory

    public interface CollectionFactory
    Allows instrumentation and bridge API implementations to use collections from third partly libraries without depending directly on them. For example, there is no default weak-keyed concurrent map in the JDK, so instrumentation authors end up using a fully synchronized wrapper around a WeakHashMap. Caffeine has a better implementation; this interface allows the Agent to provide it at runtime.
    • Method Summary

      All Methods Instance Methods Abstract 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)
      Create a time based eviction cache in which an entry's age is determined on a last-access basis.
      <K,​V>
      java.util.Map<K,​V>
      createConcurrentTimeBasedEvictionMap​(long ageInSeconds)
      Create a time based eviction cache in which an entry's age is determined on a last-write basis.
      <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

        <K,​V> java.util.Map<K,​V> createConcurrentWeakKeyedMap()
        Create a concurrent-safe, weak-keyed map.
        Type Parameters:
        K - Key type
        V - Value type
        Returns:
        concurrent-safe, weak-keyed map
      • createConcurrentTimeBasedEvictionMap

        <K,​V> java.util.Map<K,​V> createConcurrentTimeBasedEvictionMap​(long ageInSeconds)
        Create a time based eviction cache in which an entry's age is determined on a last-write basis.
        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

        <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.
        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

        <K,​V> java.util.function.Function<K,​V> createAccessTimeBasedCache​(long ageInSeconds,
                                                                                      int initialCapacity,
                                                                                      java.util.function.Function<K,​V> loader)
        Create a time based eviction cache in which an entry's age is determined on a last-access basis.
        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