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
@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
@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
@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
private CacheProviderWrapper() {
    this.delegate = new SoftReference<TypePool.CacheProvider>(new TypePool.CacheProvider.Simple());
}
 
Example 5
@Nullable
TypePool.CacheProvider get() {
    return delegate.get();
}
 
Example 6
Source Project: kanela   File: PoolStrategyCache.java    License: 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 Project: kanela   File: PoolStrategyCache.java    License: 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);
}