Search in sources :

Example 1 with Implementation

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

the class ExtensionPointFactoryBean method publishAsNuxeoExtensionPoint.

private void publishAsNuxeoExtensionPoint(Class<?> beanClass) throws Exception {
    Assert.notNull(beanClass, "Service must be implement!");
    ExtensionPointBuilder extensionPointBuilder = ExtensionPointBuilder.genericExtensionPoint(this.name, applicationContext.getClassLoader());
    if (this.contribution != null && this.contribution.length != 0) {
        for (int i = 0; i < contribution.length; i++) {
            extensionPointBuilder.addContribution(contribution[i]);
        }
    }
    Assert.hasLength(beanName, "required property 'beanName' has not been set for creating implementation");
    Assert.notNull(applicationContext, "required property 'applicationContext' has not been set for creating implementation");
    Implementation implementation = new SpringImplementationImpl(targetBeanName, applicationContext);
    ComponentInfo extensionPointComponent = new ExtensionPointComponent(extensionPointBuilder.getExtensionPoint(), sofaRuntimeContext, implementation);
    extensionPointComponent.setApplicationContext(applicationContext);
    sofaRuntimeContext.getComponentManager().register(extensionPointComponent);
}
Also used : ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ExtensionPointComponent(com.alipay.sofa.runtime.ext.component.ExtensionPointComponent) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) SpringImplementationImpl(com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)

Example 2 with Implementation

use of com.alipay.sofa.runtime.spi.component.Implementation 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 3 with Implementation

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

the class SpringContextInstallStage method publishContextAsSofaComponent.

private void publishContextAsSofaComponent(DeploymentDescriptor deployment, ApplicationRuntimeModel application, ApplicationContext context) {
    ComponentName componentName = ComponentNameFactory.createComponentName(SpringContextComponent.SPRING_COMPONENT_TYPE, deployment.getModuleName());
    Implementation implementation = new SpringContextImplementation(context);
    ComponentInfo componentInfo = new SpringContextComponent(componentName, implementation, application.getSofaRuntimeContext());
    application.getSofaRuntimeContext().getComponentManager().register(componentInfo);
}
Also used : SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation)

Example 4 with Implementation

use of com.alipay.sofa.runtime.spi.component.Implementation 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)

Example 5 with Implementation

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

the class ServiceAnnotationBeanPostProcessor method processSofaService.

private void processSofaService(Object bean, String beanName) {
    final Class<?> beanClass = AopProxyUtils.ultimateTargetClass(bean);
    SofaService sofaServiceAnnotation = beanClass.getAnnotation(SofaService.class);
    if (sofaServiceAnnotation == null) {
        return;
    }
    Class<?> interfaceType = sofaServiceAnnotation.interfaceType();
    if (interfaceType.equals(void.class)) {
        Class<?>[] interfaces = beanClass.getInterfaces();
        if (interfaces == null || interfaces.length == 0 || interfaces.length > 1) {
            throw new ServiceRuntimeException("Bean " + beanName + " does not has any interface or has more than one interface.");
        }
        interfaceType = interfaces[0];
    }
    Implementation implementation = new SpringImplementationImpl(beanName, applicationContext);
    implementation.setTarget(bean);
    Service service = new ServiceImpl(sofaServiceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, bean);
    service.addBinding(new JvmBinding());
    ComponentInfo componentInfo = new ServiceComponent(implementation, service, sofaRuntimeContext);
    sofaRuntimeContext.getComponentManager().register(componentInfo);
}
Also used : ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ServiceImpl(com.alipay.sofa.runtime.service.component.impl.ServiceImpl) Service(com.alipay.sofa.runtime.service.component.Service) SofaService(com.alipay.sofa.runtime.api.annotation.SofaService) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SofaService(com.alipay.sofa.runtime.api.annotation.SofaService) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) SpringImplementationImpl(com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Aggregations

ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)11 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)11 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)6 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)5 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)5 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)5 ExtensionPointComponent (com.alipay.sofa.runtime.ext.component.ExtensionPointComponent)4 Binding (com.alipay.sofa.runtime.spi.binding.Binding)4 Service (com.alipay.sofa.runtime.service.component.Service)3 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)3 SpringImplementationImpl (com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)3 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)2 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)2 ExtensionPointImpl (com.alipay.sofa.runtime.ext.component.ExtensionPointImpl)2 JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)2 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)2 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)2 SpringContextComponent (com.alipay.sofa.runtime.spring.SpringContextComponent)2 SpringContextImplementation (com.alipay.sofa.runtime.spring.SpringContextImplementation)2 ExtensionPoint (com.alipay.sofa.service.api.component.ExtensionPoint)2