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