Search in sources :

Example 6 with Binding

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);
            }
        }
    }
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 7 with Binding

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();
}
Also used : Binding(com.alipay.sofa.runtime.spi.binding.Binding)

Example 8 with Binding

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;
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding)

Example 9 with Binding

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();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 10 with Binding

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);
}
Also used : Binding(com.alipay.sofa.runtime.spi.binding.Binding) ArrayList(java.util.ArrayList) HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult)

Aggregations

Binding (com.alipay.sofa.runtime.spi.binding.Binding)42 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)23 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)22 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)12 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)12 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)10 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)10 ArrayList (java.util.ArrayList)10 SofaReferenceBinding (com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding)6 BindingType (com.alipay.sofa.runtime.api.binding.BindingType)6 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)6 SofaServiceBinding (com.alipay.sofa.runtime.api.annotation.SofaServiceBinding)4 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)4 JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)4 Reference (com.alipay.sofa.runtime.service.component.Reference)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 ReferenceImpl (com.alipay.sofa.runtime.service.component.impl.ReferenceImpl)4 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)4 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)4 HealthResult (com.alipay.sofa.runtime.spi.health.HealthResult)4