Java Code Examples for net.bytebuddy.pool.TypePool#CacheProvider

The following examples show how to use net.bytebuddy.pool.TypePool#CacheProvider . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoftlyReferencingTypePoolCache.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Override
protected TypePool.CacheProvider locate(ClassLoader classLoader) {
    if (ignoredClassLoaders.matches(classLoader)) {
        return TypePool.CacheProvider.Simple.withObjectType();
    }
    classLoader = classLoader == null ? getBootstrapMarkerLoader() : classLoader;
    CacheProviderWrapper cacheProviderRef = cacheProviders.get(classLoader);
    if (cacheProviderRef == null || cacheProviderRef.get() == null) {
        cacheProviderRef = new CacheProviderWrapper();
        cacheProviders.put(classLoader, cacheProviderRef);
        // accommodate for race condition
        cacheProviderRef = cacheProviders.get(classLoader);
    }
    final TypePool.CacheProvider cacheProvider = cacheProviderRef.get();
    // guard against edge case when the soft reference has already been cleared since evaluating the loop condition
    return cacheProvider != null ? cacheProvider : TypePool.CacheProvider.Simple.withObjectType();
}
 
Example 2
Source File: AgentBuilderTypeLocatorWithTypePoolCacheSimpleTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleImplementation() throws Exception {
    ConcurrentMap<ClassLoader, TypePool.CacheProvider> cacheProviders = new ConcurrentHashMap<ClassLoader, TypePool.CacheProvider>();
    cacheProviders.put(first, firstCache);
    cacheProviders.put(second, secondCache);
    AgentBuilder.PoolStrategy poolStrategy = new AgentBuilder.PoolStrategy.WithTypePoolCache.Simple(TypePool.Default.ReaderMode.FAST, cacheProviders);
    assertThat(poolStrategy.typePool(classFileLocator, first), hasPrototype(poolStrategy.typePool(classFileLocator, first)));
    assertThat(poolStrategy.typePool(classFileLocator, first), not(hasPrototype(poolStrategy.typePool(classFileLocator, second))));
}
 
Example 3
Source File: AgentBuilderTypeLocatorWithTypePoolCacheSimpleTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleImplementationBootstrap() throws Exception {
    ConcurrentMap<ClassLoader, TypePool.CacheProvider> cacheProviders = new ConcurrentHashMap<ClassLoader, TypePool.CacheProvider>();
    cacheProviders.put(ClassLoader.getSystemClassLoader(), firstCache);
    cacheProviders.put(second, secondCache);
    AgentBuilder.PoolStrategy poolStrategy = new AgentBuilder.PoolStrategy.WithTypePoolCache.Simple(TypePool.Default.ReaderMode.FAST, cacheProviders);
    assertThat(poolStrategy.typePool(classFileLocator, null), hasPrototype(poolStrategy.typePool(classFileLocator, null)));
    assertThat(poolStrategy.typePool(classFileLocator, null), not(hasPrototype(poolStrategy.typePool(classFileLocator, second))));
}
 
Example 4
Source File: SoftlyReferencingTypePoolCache.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private CacheProviderWrapper() {
    this.delegate = new SoftReference<TypePool.CacheProvider>(new TypePool.CacheProvider.Simple());
}
 
Example 5
Source File: SoftlyReferencingTypePoolCache.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Nullable
TypePool.CacheProvider get() {
    return delegate.get();
}
 
Example 6
Source File: PoolStrategyCache.java    From kanela with Apache License 2.0 4 votes vote down vote up
@Override
protected TypePool.CacheProvider locate(ClassLoader classLoader) {
    val mapKey = (classLoader == null) ? ClassLoader.getSystemClassLoader() : classLoader;
    return cache.get(mapKey);
}
 
Example 7
Source File: PoolStrategyCache.java    From kanela with Apache License 2.0 4 votes vote down vote up
private ExpirationListener<Object, TypePool.CacheProvider> LogExpirationListener() {
    return (key, value) ->   Logger.debug(() -> "Expiring key: " + key + "with value" + value);
}