Java Code Examples for net.bytebuddy.TypeCache#SimpleKey

The following examples show how to use net.bytebuddy.TypeCache#SimpleKey . 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: ByteBuddyState.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
ByteBuddyState() {
	this.byteBuddy = new ByteBuddy().with( TypeValidation.DISABLED );

	this.proxyCache = new TypeCache.WithInlineExpunction<TypeCache.SimpleKey>( TypeCache.Sort.WEAK );
	this.basicProxyCache = new TypeCache.WithInlineExpunction<TypeCache.SimpleKey>( TypeCache.Sort.WEAK );

	if ( System.getSecurityManager() != null ) {
		this.getDeclaredMethodMemberSubstitution = getDeclaredMethodMemberSubstitution();
		this.getMethodMemberSubstitution = getMethodMemberSubstitution();
	}
	else {
		this.getDeclaredMethodMemberSubstitution = null;
		this.getMethodMemberSubstitution = null;
	}

	this.proxyDefinitionHelpers = new ProxyDefinitionHelpers();
}
 
Example 2
Source File: BasicProxyFactoryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces, ByteBuddyState byteBuddyState) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}

	final Class<?> superClassOrMainInterface = superClass != null ? superClass : interfaces[0];
	final TypeCache.SimpleKey cacheKey = getCacheKey( superClass, interfaces );

	this.proxyClass = byteBuddyState.loadBasicProxy( superClassOrMainInterface, cacheKey, byteBuddy -> byteBuddy
			.with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( superClassOrMainInterface.getName() ) ) )
			.subclass( superClass == null ? Object.class : superClass, ConstructorStrategy.Default.DEFAULT_CONSTRUCTOR )
			.implement( interfaces == null ? NO_INTERFACES : interfaces )
			.defineField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE )
			.method( byteBuddyState.getProxyDefinitionHelpers().getVirtualNotFinalizerFilter() )
					.intercept( byteBuddyState.getProxyDefinitionHelpers().getDelegateToInterceptorDispatcherMethodDelegation() )
			.implement( ProxyConfiguration.class )
					.intercept( byteBuddyState.getProxyDefinitionHelpers().getInterceptorFieldAccessor() )
	);
	this.interceptor = new PassThroughInterceptor( proxyClass.getName() );
}
 
Example 3
Source File: ByteBuddyState.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> load(Class<?> referenceClass, TypeCache<TypeCache.SimpleKey> cache,
		TypeCache.SimpleKey cacheKey, Function<ByteBuddy, DynamicType.Builder<?>> makeProxyFunction) {
	return cache.findOrInsert(
			referenceClass.getClassLoader(),
			cacheKey,
			() -> make( makeProxyFunction.apply( byteBuddy ) )
					.load( referenceClass.getClassLoader(), resolveClassLoadingStrategy( referenceClass ) )
					.getLoaded(),
			cache );
}
 
Example 4
Source File: BasicProxyFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private TypeCache.SimpleKey getCacheKey(Class<?> superClass, Class<?>[] interfaces) {
	Set<Class<?>> key = new HashSet<Class<?>>();
	if ( superClass != null ) {
		key.add( superClass );
	}
	if ( interfaces != null ) {
		key.addAll( Arrays.<Class<?>>asList( interfaces ) );
	}

	return new TypeCache.SimpleKey( key );
}
 
Example 5
Source File: ByteBuddyState.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Load a proxy as generated by the {@link ProxyFactory}.
 *
 * @param referenceClass The main class to proxy - might be an interface.
 * @param cacheKey The cache key.
 * @param makeProxyFunction A function building the proxy.
 * @return The loaded proxy class.
 */
public Class<?> loadProxy(Class<?> referenceClass, TypeCache.SimpleKey cacheKey,
		Function<ByteBuddy, DynamicType.Builder<?>> makeProxyFunction) {
	return load( referenceClass, proxyCache, cacheKey, makeProxyFunction );
}
 
Example 6
Source File: ByteBuddyState.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Load a proxy as generated by the {@link BasicProxyFactory}.
 *
 * @param referenceClass The main class to proxy - might be an interface.
 * @param cacheKey The cache key.
 * @param makeProxyFunction A function building the proxy.
 * @return The loaded proxy class.
 */
Class<?> loadBasicProxy(Class<?> referenceClass, TypeCache.SimpleKey cacheKey,
		Function<ByteBuddy, DynamicType.Builder<?>> makeProxyFunction) {
	return load( referenceClass, basicProxyCache, cacheKey, makeProxyFunction );
}