use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class SofaBootRpcAllTest method testLoadBalancerAnnotation.
@Test
public void testLoadBalancerAnnotation() throws NoSuchFieldException, IllegalAccessException {
Field consumerConfigMapField = ConsumerConfigContainer.class.getDeclaredField("consumerConfigMap");
consumerConfigMapField.setAccessible(true);
ConcurrentMap<Binding, ConsumerConfig> consumerConfigMap = (ConcurrentMap<Binding, ConsumerConfig>) consumerConfigMapField.get(consumerConfigContainer);
boolean found = false;
for (ConsumerConfig consumerConfig : consumerConfigMap.values()) {
if ("loadbalancer".equals(consumerConfig.getUniqueId()) && AnnotationService.class.getName().equals(consumerConfig.getInterfaceId())) {
found = true;
Assert.assertEquals("roundRobin", consumerConfig.getLoadBalancer());
}
}
Assert.assertTrue("Found roundrobin reference", found);
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ServiceBeanFactoryPostProcessor method getSofaReferenceBinding.
/**
* get sofa reference binding annotated on parameter. At present, only jvm sofa reference is supported .
* @param sofaReferenceAnnotation
* @param sofaReferenceBinding
* @return
*/
private List<Binding> getSofaReferenceBinding(SofaReference sofaReferenceAnnotation, SofaReferenceBinding sofaReferenceBinding) {
if (!JvmBinding.XmlConstants.BINDING_TYPE.equals(sofaReferenceBinding.bindingType())) {
throw new ServiceRuntimeException(ErrorCode.convert("01-02005"));
}
List<Binding> bindings = new ArrayList<>();
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaReferenceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaReferenceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaReferenceAnnotation, sofaReferenceBinding, bindingConverterContext);
bindings.add(binding);
return bindings;
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ReferenceAnnotationBeanPostProcessor method createReferenceProxy.
private Object createReferenceProxy(SofaReference sofaReferenceAnnotation, Class<?> interfaceType) {
Reference reference = new ReferenceImpl(sofaReferenceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, sofaReferenceAnnotation.jvmFirst());
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaReferenceAnnotation.binding().bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaReferenceAnnotation.binding().bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaReferenceAnnotation, sofaReferenceAnnotation.binding(), bindingConverterContext);
reference.addBinding(binding);
return ReferenceRegisterHelper.registerReference(reference, bindingAdapterFactory, sofaRuntimeContext, applicationContext);
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ServiceBeanFactoryPostProcessor method getSofaServiceBinding.
private List<Binding> getSofaServiceBinding(SofaService sofaServiceAnnotation, SofaServiceBinding[] sofaServiceBindings) {
List<Binding> bindings = new ArrayList<>();
for (SofaServiceBinding sofaServiceBinding : sofaServiceBindings) {
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaServiceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaServiceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(false);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaServiceAnnotation, sofaServiceBinding, bindingConverterContext);
bindings.add(binding);
}
return bindings;
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class AbstractContractFactoryBean method parseBindings.
protected List<Binding> parseBindings(List<Element> parseElements, ApplicationContext appContext, boolean isInBinding) {
List<Binding> result = new ArrayList<>();
if (parseElements != null) {
for (Element element : parseElements) {
String tagName = element.getLocalName();
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverterByTagName(tagName);
if (bindingConverter == null) {
dealWithbindingConverterNotExist(tagName);
continue;
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(isInBinding);
bindingConverterContext.setApplicationContext(appContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
bindingConverterContext.setRepeatReferLimit(repeatReferLimit);
bindingConverterContext.setBeanId(beanId);
setProperties(bindingConverterContext);
Binding binding = bindingConverter.convert(element, bindingConverterContext);
result.add(binding);
}
}
return result;
}
Aggregations