Search in sources :

Example 21 with Binding

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);
}
Also used : Binding(com.alipay.sofa.runtime.spi.binding.Binding) SofaReferenceBinding(com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding) Field(java.lang.reflect.Field) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with Binding

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;
}
Also used : SofaServiceBinding(com.alipay.sofa.runtime.api.annotation.SofaServiceBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) SofaReferenceBinding(com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding) BindingType(com.alipay.sofa.runtime.api.binding.BindingType) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) ArrayList(java.util.ArrayList) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 23 with Binding

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);
}
Also used : Binding(com.alipay.sofa.runtime.spi.binding.Binding) Reference(com.alipay.sofa.runtime.service.component.Reference) SofaReference(com.alipay.sofa.runtime.api.annotation.SofaReference) BindingType(com.alipay.sofa.runtime.api.binding.BindingType) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) ReferenceImpl(com.alipay.sofa.runtime.service.component.impl.ReferenceImpl) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 24 with Binding

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;
}
Also used : SofaServiceBinding(com.alipay.sofa.runtime.api.annotation.SofaServiceBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) SofaReferenceBinding(com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding) SofaServiceBinding(com.alipay.sofa.runtime.api.annotation.SofaServiceBinding) BindingType(com.alipay.sofa.runtime.api.binding.BindingType) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) ArrayList(java.util.ArrayList) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 25 with Binding

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;
}
Also used : Binding(com.alipay.sofa.runtime.spi.binding.Binding) Element(org.w3c.dom.Element) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) ArrayList(java.util.ArrayList) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext)

Aggregations

Binding (com.alipay.sofa.runtime.spi.binding.Binding)42 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)23 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)22 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)12 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)12 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)10 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)10 ArrayList (java.util.ArrayList)10 SofaReferenceBinding (com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding)6 BindingType (com.alipay.sofa.runtime.api.binding.BindingType)6 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)6 SofaServiceBinding (com.alipay.sofa.runtime.api.annotation.SofaServiceBinding)4 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)4 JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)4 Reference (com.alipay.sofa.runtime.service.component.Reference)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 ReferenceImpl (com.alipay.sofa.runtime.service.component.impl.ReferenceImpl)4 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)4 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)4 HealthResult (com.alipay.sofa.runtime.spi.health.HealthResult)4