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);
}
}
}
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);
}
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();
}
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();
}
}
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");
}
}
Aggregations