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