Search in sources :

Example 1 with ComponentInfo

use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.

the class ServiceClientImpl method removeService.

@Override
public void removeService(Class<?> interfaceClass, String uniqueId, int millisecondsToDelay) {
    if (millisecondsToDelay < 0) {
        throw new IllegalArgumentException("Argument delay must be a positive integer or zero.");
    }
    Collection<ComponentInfo> serviceComponents = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ServiceComponent.SERVICE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : serviceComponents) {
        if (!(componentInfo instanceof ServiceComponent)) {
            continue;
        }
        ServiceComponent serviceComponent = (ServiceComponent) componentInfo;
        if (serviceComponent.getService().getInterfaceType() == interfaceClass && serviceComponent.getService().getUniqueId().equals(uniqueId)) {
            Map<String, Property> properties = serviceComponent.getProperties();
            Property property = new Property();
            property.setValue(millisecondsToDelay);
            properties.put(ServiceComponent.UNREGISTER_DELAY_MILLISECONDS, property);
            sofaRuntimeContext.getComponentManager().unregister(serviceComponent);
        }
    }
}
Also used : ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Property(com.alipay.sofa.runtime.api.component.Property)

Example 2 with ComponentInfo

use of com.alipay.sofa.runtime.spi.component.ComponentInfo 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);
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ServiceImpl(com.alipay.sofa.runtime.service.component.impl.ServiceImpl) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) Service(com.alipay.sofa.runtime.service.component.Service) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) BindingParam(com.alipay.sofa.runtime.api.client.param.BindingParam) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext)

Example 3 with ComponentInfo

use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, SofaRuntimeContext sofaRuntimeContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (reference.jvmService() && binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE)) {
        throw new ServiceRuntimeException("jvm-service=\"true\" can not be used with JVM binding.");
    }
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && isLocalFirst(reference, sofaRuntimeContext)) {
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    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) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 4 with ComponentInfo

use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.

the class ComponentHealthChecker method isHealthy.

@Override
public Health isHealthy() {
    boolean allPassed = true;
    Health.Builder builder = new Health.Builder();
    for (ComponentInfo componentInfo : SofaFrameworkHolder.getSofaFramework().getSofaRuntimeContext(Slite2Configuration.getAppName()).getComponentManager().getComponents()) {
        HealthResult healthy = componentInfo.isHealthy();
        if (healthy.isHealthy()) {
            builder.withDetail(healthy.getHealthName(), "passed");
        } else {
            builder.withDetail(healthy.getHealthName(), healthy.getHealthReport());
            allPassed = false;
        }
    }
    if (allPassed) {
        return builder.status(Status.UP).build();
    } else {
        return builder.status(Status.DOWN).build();
    }
}
Also used : Health(org.springframework.boot.actuate.health.Health) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult)

Example 5 with ComponentInfo

use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.

the class ComponentManagerImpl method shutdown.

@Override
public void shutdown() {
    List<ComponentInfo> elems = new ArrayList<ComponentInfo>(registry.values());
    for (ComponentInfo ri : elems) {
        try {
            unregister(ri);
        } catch (Exception e) {
            SofaLogger.error(e, "failed to shutdown component manager");
        }
    }
    try {
        registry.clear();
        registry = null;
        resolvedRegistry.clear();
        resolvedRegistry = null;
        clientFactoryInternal = null;
    } catch (Exception e) {
        SofaLogger.error(e, "Failed to shutdown registry manager");
    }
}
Also used : ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Aggregations

ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)11 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)6 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)4 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 Binding (com.alipay.sofa.runtime.spi.binding.Binding)3 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)3 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)3 ComponentType (com.alipay.sofa.runtime.model.ComponentType)2 Service (com.alipay.sofa.runtime.service.component.Service)2 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)2 SofaService (com.alipay.sofa.runtime.api.annotation.SofaService)1 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)1 Property (com.alipay.sofa.runtime.api.component.Property)1 Reference (com.alipay.sofa.runtime.service.component.Reference)1 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)1 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)1 HealthResult (com.alipay.sofa.runtime.spi.health.HealthResult)1 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)1 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)1