use of com.alipay.sofa.runtime.service.component.impl.ReferenceImpl in project sofa-boot by alipay.
the class ServiceAnnotationBeanPostProcessor method processSofaReference.
private void processSofaReference(final Object bean) {
final Class<?> beanClass = bean.getClass();
ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() {
@Override
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
SofaReference sofaReferenceAnnotation = field.getAnnotation(SofaReference.class);
if (sofaReferenceAnnotation == null) {
return;
}
Class<?> interfaceType = sofaReferenceAnnotation.interfaceType();
if (interfaceType.equals(void.class)) {
interfaceType = field.getType();
}
Reference reference = new ReferenceImpl(sofaReferenceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, false, false);
reference.addBinding(new JvmBinding());
Object proxy = ReferenceRegisterHelper.registerReference(reference, sofaRuntimeContext);
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, bean, proxy);
}
}, new ReflectionUtils.FieldFilter() {
@Override
public boolean matches(Field field) {
return !Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(SofaReference.class);
}
});
}
use of com.alipay.sofa.runtime.service.component.impl.ReferenceImpl in project sofa-boot by alipay.
the class ReferenceClientImpl method getReferenceFromReferenceParam.
private <T> Reference getReferenceFromReferenceParam(ReferenceParam<T> referenceParam) {
BindingParam bindingParam = referenceParam.getBindingParam();
Reference reference = new ReferenceImpl(referenceParam.getUniqueId(), referenceParam.getInterfaceType(), InterfaceMode.api, referenceParam.isLocalFirst(), referenceParam.isJvmService(), null);
if (bindingParam == null) {
// add JVM Binding Default
reference.addBinding(new JvmBinding());
} else {
BindingConverter bindingConverter = BindingFactoryContainer.getBindingConverterFactory().getBindingConverter(bindingParam.getBindingType());
if (bindingConverter == null) {
throw new ServiceRuntimeException("Can not found binding converter for binding type " + bindingParam.getBindingType());
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(bindingParam, bindingConverterContext);
reference.addBinding(binding);
}
return reference;
}
Aggregations