use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
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;
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ReferenceComponent method unregister.
@Override
public void unregister() throws ServiceRuntimeException {
super.unregister();
if (reference.hasBinding()) {
for (Binding binding : reference.getBindings()) {
BindingAdapter<Binding> bindingAdapter = this.bindingAdapterFactory.getBindingAdapter(binding.getBindingType());
if (bindingAdapter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00100", binding.getBindingType(), reference));
}
SofaLogger.info(" >>Un-in Binding [{}] Begins - {}.", binding.getBindingType(), reference);
try {
bindingAdapter.unInBinding(reference, binding, sofaRuntimeContext);
} finally {
SofaLogger.info(" >>Un-in Binding [{}] Ends - {}.", binding.getBindingType(), reference);
}
}
}
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class XsdTimeoutTest method testReferenceTimeout.
@Test
public void testReferenceTimeout() {
Collection<ComponentInfo> c = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
for (ComponentInfo componentInfo : c) {
if (componentInfo instanceof ReferenceComponent) {
ReferenceComponent referenceComponent = (ReferenceComponent) componentInfo;
if (!referenceComponent.getReference().getInterfaceType().equals(WhateverInterface.class)) {
continue;
}
Binding binding = referenceComponent.getReference().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
if (binding instanceof RpcBinding) {
RpcBinding rpcBinding = (RpcBinding) binding;
Assert.assertEquals((long) rpcBinding.getRpcBindingParam().getTimeout(), 10000);
}
}
}
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class SofaBootRpcAllTest method testLoadBalancerAnnotation.
@Test
public void testLoadBalancerAnnotation() throws NoSuchFieldException, IllegalAccessException {
Field consumerConfigMapField = ConsumerConfigContainer.class.getDeclaredField("consumerConfigMap");
consumerConfigMapField.setAccessible(true);
ConcurrentMap<Binding, ConsumerConfig> consumerConfigMap = (ConcurrentMap<Binding, ConsumerConfig>) consumerConfigMapField.get(consumerConfigContainer);
boolean found = false;
for (ConsumerConfig consumerConfig : consumerConfigMap.values()) {
if ("loadbalancer".equals(consumerConfig.getUniqueId()) && AnnotationService.class.getName().equals(consumerConfig.getInterfaceId())) {
found = true;
Assert.assertEquals("roundRobin", consumerConfig.getLoadBalancer());
}
}
Assert.assertTrue("Found roundrobin reference", found);
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class ServiceBeanFactoryPostProcessor method getSofaReferenceBinding.
/**
* get sofa reference binding annotated on parameter. At present, only jvm sofa reference is supported .
* @param sofaReferenceAnnotation
* @param sofaReferenceBinding
* @return
*/
private List<Binding> getSofaReferenceBinding(SofaReference sofaReferenceAnnotation, SofaReferenceBinding sofaReferenceBinding) {
if (!JvmBinding.XmlConstants.BINDING_TYPE.equals(sofaReferenceBinding.bindingType())) {
throw new ServiceRuntimeException(ErrorCode.convert("01-02005"));
}
List<Binding> bindings = new ArrayList<>();
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaReferenceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaReferenceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaReferenceAnnotation, sofaReferenceBinding, bindingConverterContext);
bindings.add(binding);
return bindings;
}
Aggregations