Search in sources :

Example 1 with BindingConverterContext

use of com.alipay.sofa.runtime.spi.service.BindingConverterContext in project sofa-boot by alipay.

the class ServiceClientImpl method service.

@SuppressWarnings("unchecked")
public void service(ServiceParam serviceParam) {
    Implementation implementation = new DefaultImplementation();
    implementation.setTarget(serviceParam.getInstance());
    if (serviceParam.getInterfaceType() == null) {
        throw new ServiceRuntimeException("Interface type is null. Interface type is required while publish a service.");
    }
    Service service = new ServiceImpl(serviceParam.getUniqueId(), serviceParam.getInterfaceType(), InterfaceMode.api, serviceParam.getInstance(), null);
    for (BindingParam bindingParam : serviceParam.getBindingParams()) {
        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(false);
        bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
        bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
        Binding binding = bindingConverter.convert(bindingParam, bindingConverterContext);
        service.addBinding(binding);
    }
    boolean hasJvmBinding = false;
    for (Binding binding : service.getBindings()) {
        if (binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE)) {
            hasJvmBinding = true;
            break;
        }
    }
    if (!hasJvmBinding) {
        service.addBinding(new JvmBinding());
    }
    ComponentInfo componentInfo = new ServiceComponent(implementation, service, sofaRuntimeContext);
    sofaRuntimeContext.getComponentManager().register(componentInfo);
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ServiceImpl(com.alipay.sofa.runtime.service.component.impl.ServiceImpl) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) Service(com.alipay.sofa.runtime.service.component.Service) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) BindingParam(com.alipay.sofa.runtime.api.client.param.BindingParam) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext)

Example 2 with BindingConverterContext

use of com.alipay.sofa.runtime.spi.service.BindingConverterContext 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<Binding>();
    if (parseElements != null) {
        for (Element element : parseElements) {
            String tagName = element.getLocalName();
            BindingConverter bindingConverter = bindingConverterFactory.getBindingConverterByTagName(tagName);
            if (bindingConverter == null) {
                continue;
            }
            BindingConverterContext bindingConverterContext = new BindingConverterContext();
            bindingConverterContext.setInBinding(isInBinding);
            bindingConverterContext.setApplicationContext(appContext);
            bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
            bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
            bindingConverterContext.setRepeatReferLimit(repeatReferLimit);
            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)

Example 3 with BindingConverterContext

use of com.alipay.sofa.runtime.spi.service.BindingConverterContext 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;
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) Reference(com.alipay.sofa.runtime.service.component.Reference) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) BindingParam(com.alipay.sofa.runtime.api.client.param.BindingParam) ReferenceImpl(com.alipay.sofa.runtime.service.component.impl.ReferenceImpl) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Aggregations

Binding (com.alipay.sofa.runtime.spi.binding.Binding)3 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)3 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)3 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)2 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)2 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)2 Reference (com.alipay.sofa.runtime.service.component.Reference)1 Service (com.alipay.sofa.runtime.service.component.Service)1 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)1 ReferenceImpl (com.alipay.sofa.runtime.service.component.impl.ReferenceImpl)1 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)1 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)1 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)1 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)1 ArrayList (java.util.ArrayList)1 Element (org.w3c.dom.Element)1