Class AgentBuilder.PoolStrategy.WithTypePoolCache

java.lang.Object
net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache
All Implemented Interfaces:
AgentBuilder.PoolStrategy
Direct Known Subclasses:
AgentBuilder.PoolStrategy.WithTypePoolCache.Simple
Enclosing interface:
AgentBuilder.PoolStrategy

@Enhance public abstract static class AgentBuilder.PoolStrategy.WithTypePoolCache extends Object implements AgentBuilder.PoolStrategy

A type locator that uses type pools but allows for the configuration of a custom cache provider by class loader. Note that a TypePool can grow in size and that a static reference is kept to this pool by Byte Buddy's registration of a ClassFileTransformer what can cause a memory leak if the supplied caches are not cleared on a regular basis. Also note that a cache provider can be accessed concurrently by multiple ClassLoaders.

All types that are returned by the locator's type pool are resolved lazily.

  • Field Details

  • Constructor Details

  • Method Details

    • typePool

      public TypePool typePool(ClassFileLocator classFileLocator, @MaybeNull ClassLoader classLoader)
      Creates a type pool for a given class file locator.
      Specified by:
      typePool in interface AgentBuilder.PoolStrategy
      Parameters:
      classFileLocator - The class file locator to use.
      classLoader - The class loader for which the class file locator was created or null if the boot loader.
      Returns:
      A type pool for the supplied class file locator.
    • typePool

      public TypePool typePool(ClassFileLocator classFileLocator, @MaybeNull ClassLoader classLoader, String name)
      Creates a type pool for a given class file locator. If a cache is used, the type that is currently instrumented is not used.
      Specified by:
      typePool in interface AgentBuilder.PoolStrategy
      Parameters:
      classFileLocator - The class file locator to use.
      classLoader - The class loader for which the class file locator was created or null if the boot loader.
      name - The name of the currently instrumented type.
      Returns:
      A type pool for the supplied class file locator.
    • locate

      protected abstract TypePool.CacheProvider locate(@MaybeNull ClassLoader classLoader)
      Locates a cache provider for a given class loader.
      Parameters:
      classLoader - The class loader for which to locate a cache. This class loader might be null to represent the bootstrap loader.
      Returns:
      The cache provider to use.