use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
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 ServiceComponent method dump.
@Override
public String dump() {
StringBuilder sb = new StringBuilder(super.dump());
Collection<Binding> bindings = service.getBindings();
for (Binding binding : bindings) {
sb.append("\n|------>[binding]-").append(binding.dump());
}
return sb.toString();
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class ReferenceRegisterHelper method generateBindingHashCode.
public static int generateBindingHashCode(Reference reference) {
Collection<Binding> bindings = reference.getBindings();
int result = 1;
for (Binding binding : bindings) {
result = result * 31 + binding.getBindingHashCode();
}
ClassLoader cl = reference.getInterfaceType().getClassLoader();
if (cl != null) {
result += reference.getInterfaceType().getClassLoader().hashCode();
}
return result;
}
use of com.alipay.sofa.runtime.spi.binding.Binding 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.binding.Binding in project sofa-boot by sofastack.
the class AbstractComponent method aggregateBindingHealth.
protected String aggregateBindingHealth(Collection<Binding> bindings) {
List<String> healthResult = new ArrayList<>();
for (Binding binding : bindings) {
HealthResult result = binding.healthCheck();
String report = "[" + result.getHealthName() + "," + (result.getHealthReport() == null ? (result.isHealthy() ? "passed" : "failed") : result.getHealthReport()) + "]";
healthResult.add(report);
}
return String.join(" ", healthResult);
}
Aggregations