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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations