Search in sources :

Example 1 with DefaultImplementation

use of com.alipay.sofa.runtime.spi.component.DefaultImplementation in project sofa-boot by sofastack.

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(ErrorCode.convert("01-00201"));
    }
    Service service = new ServiceImpl(serviceParam.getUniqueId(), serviceParam.getInterfaceType(), InterfaceMode.api, serviceParam.getInstance(), null);
    for (BindingParam bindingParam : serviceParam.getBindingParams()) {
        BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(bindingParam.getBindingType());
        if (bindingConverter == null) {
            throw new ServiceRuntimeException(ErrorCode.convert("01-00200", 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, bindingAdapterFactory, 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 DefaultImplementation

use of com.alipay.sofa.runtime.spi.component.DefaultImplementation in project sofa-boot by sofastack.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, BindingAdapterFactory bindingAdapterFactory, SofaRuntimeContext sofaRuntimeContext, ApplicationContext applicationContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && !SofaRuntimeProperties.isDisableJvmFirst(sofaRuntimeContext) && reference.isJvmFirst()) {
        // as rpc invocation would be serialized, so here would Not ignore serialized
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), bindingAdapterFactory, sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    componentInfo.setApplicationContext(applicationContext);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 3 with DefaultImplementation

use of com.alipay.sofa.runtime.spi.component.DefaultImplementation in project sofa-boot by alipay.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, SofaRuntimeContext sofaRuntimeContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (reference.jvmService() && binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE)) {
        throw new ServiceRuntimeException("jvm-service=\"true\" can not be used with JVM binding.");
    }
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && isLocalFirst(reference, sofaRuntimeContext)) {
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 4 with DefaultImplementation

use of com.alipay.sofa.runtime.spi.component.DefaultImplementation in project sofa-boot by alipay.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, BindingAdapterFactory bindingAdapterFactory, SofaRuntimeContext sofaRuntimeContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && !SofaRuntimeProperties.isDisableJvmFirst(sofaRuntimeContext) && reference.isJvmFirst()) {
        // as rpc invocation would be serialized, so here would Not ignore serialized
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), bindingAdapterFactory, sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 5 with DefaultImplementation

use of com.alipay.sofa.runtime.spi.component.DefaultImplementation 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(ErrorCode.convert("01-00201"));
    }
    Service service = new ServiceImpl(serviceParam.getUniqueId(), serviceParam.getInterfaceType(), InterfaceMode.api, serviceParam.getInstance(), null);
    for (BindingParam bindingParam : serviceParam.getBindingParams()) {
        BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(bindingParam.getBindingType());
        if (bindingConverter == null) {
            throw new ServiceRuntimeException(ErrorCode.convert("01-00200", 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, bindingAdapterFactory, 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)

Aggregations

DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)12 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)10 Binding (com.alipay.sofa.runtime.spi.binding.Binding)10 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)10 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)6 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)5 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)4 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)2 ExtensionPointComponent (com.alipay.sofa.runtime.ext.component.ExtensionPointComponent)2 ExtensionPointImpl (com.alipay.sofa.runtime.ext.component.ExtensionPointImpl)2 JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)2 Service (com.alipay.sofa.runtime.service.component.Service)2 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)2 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)2 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)2 ExtensionPoint (com.alipay.sofa.service.api.component.ExtensionPoint)2