use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class ReferenceAnnotationBeanPostProcessor method createReferenceProxy.
private Object createReferenceProxy(SofaReference sofaReferenceAnnotation, Class<?> interfaceType) {
Reference reference = new ReferenceImpl(sofaReferenceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, sofaReferenceAnnotation.jvmFirst());
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaReferenceAnnotation.binding().bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaReferenceAnnotation.binding().bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaReferenceAnnotation, sofaReferenceAnnotation.binding(), bindingConverterContext);
reference.addBinding(binding);
return ReferenceRegisterHelper.registerReference(reference, bindingAdapterFactory, sofaRuntimeContext, applicationContext);
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class ServiceBeanFactoryPostProcessor method getSofaServiceBinding.
private List<Binding> getSofaServiceBinding(SofaService sofaServiceAnnotation, SofaServiceBinding[] sofaServiceBindings) {
List<Binding> bindings = new ArrayList<>();
for (SofaServiceBinding sofaServiceBinding : sofaServiceBindings) {
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaServiceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaServiceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(false);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaServiceAnnotation, sofaServiceBinding, bindingConverterContext);
bindings.add(binding);
}
return bindings;
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class AbstractContractFactoryBean method parseBindings.
protected List<Binding> parseBindings(List<Element> parseElements, ApplicationContext appContext, boolean isInBinding) {
List<Binding> result = new ArrayList<>();
if (parseElements != null) {
for (Element element : parseElements) {
String tagName = element.getLocalName();
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverterByTagName(tagName);
if (bindingConverter == null) {
dealWithbindingConverterNotExist(tagName);
continue;
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(isInBinding);
bindingConverterContext.setApplicationContext(appContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
bindingConverterContext.setRepeatReferLimit(repeatReferLimit);
bindingConverterContext.setBeanId(beanId);
setProperties(bindingConverterContext);
Binding binding = bindingConverter.convert(element, bindingConverterContext);
result.add(binding);
}
}
return result;
}
use of com.alipay.sofa.runtime.spi.binding.Binding 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.binding.Binding in project sofa-boot by sofastack.
the class ReferenceComponent method isHealthy.
@Override
public HealthResult isHealthy() {
HealthResult result = new HealthResult(componentName.getRawName());
List<HealthResult> bindingHealth = new ArrayList<>();
JvmBinding jvmBinding = null;
HealthResult jvmBindingHealthResult = null;
if (reference.hasBinding()) {
for (Binding binding : reference.getBindings()) {
bindingHealth.add(binding.healthCheck());
if (JvmBinding.JVM_BINDING_TYPE.equals(binding.getBindingType())) {
jvmBinding = (JvmBinding) binding;
jvmBindingHealthResult = bindingHealth.get(bindingHealth.size() - 1);
}
}
}
// check reference has a corresponding service
if (!SofaRuntimeProperties.isSkipJvmReferenceHealthCheck(sofaRuntimeContext) && jvmBinding != null) {
Object serviceTarget = getServiceTarget();
if (serviceTarget == null && !jvmBinding.hasBackupProxy()) {
jvmBindingHealthResult.setHealthy(false);
jvmBindingHealthResult.setHealthReport("can not find corresponding jvm service");
}
}
List<HealthResult> failedBindingHealth = new ArrayList<>();
for (HealthResult healthResult : bindingHealth) {
if (healthResult != null && !healthResult.isHealthy()) {
failedBindingHealth.add(healthResult);
}
}
result.setHealthy(failedBindingHealth.size() == 0);
String report = aggregateBindingHealth(reference.getBindings());
if (e != null) {
report += " [" + e.getMessage() + "]";
result.setHealthy(false);
}
result.setHealthReport(report);
return result;
}
Aggregations