/** * {@inheritDoc} */ public DynamicType make(String auxiliaryTypeName, ClassFileVersion classFileVersion, MethodAccessorFactory methodAccessorFactory) { MethodDescription accessorMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT); LinkedHashMap<String, TypeDescription> parameterFields = extractFields(accessorMethod); DynamicType.Builder<?> builder = new ByteBuddy(classFileVersion) .with(TypeValidation.DISABLED) .with(PrecomputedMethodGraph.INSTANCE) .subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS) .name(auxiliaryTypeName) .modifiers(DEFAULT_TYPE_MODIFIER) .implement(Runnable.class, Callable.class).intercept(new MethodCall(accessorMethod, assigner)) .implement(serializableProxy ? new Class<?>[]{Serializable.class} : new Class<?>[0]) .defineConstructor().withParameters(parameterFields.values()) .intercept(ConstructorCall.INSTANCE); for (Map.Entry<String, TypeDescription> field : parameterFields.entrySet()) { builder = builder.defineField(field.getKey(), field.getValue(), Visibility.PRIVATE); } return builder.make(); }
@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() ); }
.implement(RLiveObject.class) .method(ElementMatchers.isAnnotatedWith(RFieldAccessor.class) .and(ElementMatchers.named("get") .or(ElementMatchers.isDeclaredBy(RObjectAsync.class))) .intercept(MethodDelegation.to(RObjectInterceptor.class)) .implement(RObject.class) .implement(RExpirable.class) .or(ElementMatchers.isDeclaredBy(RMap.class))) .intercept(MethodDelegation.to(RMapInterceptor.class)) .implement(RMap.class)
.implement(RLiveObject.class) .method(ElementMatchers.isAnnotatedWith(RFieldAccessor.class) .and(ElementMatchers.named("get") .or(ElementMatchers.isDeclaredBy(RObjectAsync.class))) .intercept(MethodDelegation.to(RObjectInterceptor.class)) .implement(RObject.class) .implement(RExpirable.class) .or(ElementMatchers.isDeclaredBy(RMap.class))) .intercept(MethodDelegation.to(RMapInterceptor.class)) .implement(RMap.class)
@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() ); }
.implement(RLiveObject.class) .method(ElementMatchers.isAnnotatedWith(RFieldAccessor.class) .and(ElementMatchers.named("get") .or(ElementMatchers.isDeclaredBy(RObjectAsync.class))) .intercept(MethodDelegation.to(RObjectInterceptor.class)) .implement(RObject.class) .implement(RExpirable.class) .or(ElementMatchers.isDeclaredBy(RMap.class))) .intercept(MethodDelegation.to(RMapInterceptor.class)) .implement(RMap.class)