use of org.redisson.liveobject.core.AccessorInterceptor in project redisson by redisson.
the class RedissonLiveObjectService method registerClassInternal.
private <T> void registerClassInternal(Class<T> entityClass) {
DynamicType.Builder<T> builder = new ByteBuddy().subclass(entityClass);
for (FieldDescription.InDefinedShape field : Introspectior.getTypeDescription(LiveObjectTemplate.class).getDeclaredFields()) {
builder = builder.define(field);
}
Class<? extends T> proxied = builder.method(ElementMatchers.isDeclaredBy(Introspectior.getTypeDescription(RLiveObject.class)).and(ElementMatchers.isGetter().or(ElementMatchers.isSetter()).or(ElementMatchers.named("isPhantom")).or(ElementMatchers.named("delete")))).intercept(MethodDelegation.withDefaultConfiguration().withBinders(FieldProxy.Binder.install(LiveObjectInterceptor.Getter.class, LiveObjectInterceptor.Setter.class)).to(new LiveObjectInterceptor(redisson, codecProvider, entityClass, getRIdFieldName(entityClass)))).implement(RLiveObject.class).method(ElementMatchers.isAnnotatedWith(RFieldAccessor.class).and(ElementMatchers.named("get").or(ElementMatchers.named("set")))).intercept(MethodDelegation.to(FieldAccessorInterceptor.class)).method(ElementMatchers.isDeclaredBy(RObject.class).or(ElementMatchers.isDeclaredBy(RObjectAsync.class))).intercept(MethodDelegation.to(RObjectInterceptor.class)).implement(RObject.class).method(ElementMatchers.isDeclaredBy(RExpirable.class).or(ElementMatchers.isDeclaredBy(RExpirableAsync.class))).intercept(MethodDelegation.to(RExpirableInterceptor.class)).implement(RExpirable.class).method(ElementMatchers.isDeclaredBy(Map.class).or(ElementMatchers.isDeclaredBy(ConcurrentMap.class)).or(ElementMatchers.isDeclaredBy(RMapAsync.class)).or(ElementMatchers.isDeclaredBy(RMap.class))).intercept(MethodDelegation.to(RMapInterceptor.class)).implement(RMap.class).method(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class)).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RLiveObject.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RExpirable.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RExpirableAsync.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RObject.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RObjectAsync.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(ConcurrentMap.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(Map.class))).and(ElementMatchers.isGetter().or(ElementMatchers.isSetter())).and(ElementMatchers.isPublic().or(ElementMatchers.isProtected()))).intercept(MethodDelegation.to(new AccessorInterceptor(redisson, objectBuilder))).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
classCache.putIfAbsent(entityClass, proxied);
}
Aggregations