Search in sources :

Example 1 with HealthCheckProcessor

use of com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor in project nacos by alibaba.

the class HealthCheckExtendProvider method loadExtend.

private void loadExtend() {
    Iterator<HealthCheckProcessor> processorIt = processors.iterator();
    Iterator<AbstractHealthChecker> healthCheckerIt = checkers.iterator();
    Set<String> origin = new HashSet<>();
    for (HealthCheckType type : HealthCheckType.values()) {
        origin.add(type.name());
    }
    Set<String> processorType = new HashSet<>(origin);
    Set<String> healthCheckerType = new HashSet<>(origin);
    while (processorIt.hasNext()) {
        HealthCheckProcessor processor = processorIt.next();
        String type = processor.getType();
        if (processorType.contains(type)) {
            throw new RuntimeException("More than one processor of the same type was found : [type=\"" + type + "\"]");
        }
        processorType.add(type);
        registry.registerSingleton(lowerFirstChar(processor.getClass().getSimpleName()), processor);
    }
    while (healthCheckerIt.hasNext()) {
        AbstractHealthChecker checker = healthCheckerIt.next();
        String type = checker.getType();
        if (healthCheckerType.contains(type)) {
            throw new RuntimeException("More than one healthChecker of the same type was found : [type=\"" + type + "\"]");
        }
        healthCheckerType.add(type);
        HealthCheckType.registerHealthChecker(checker.getType(), checker.getClass());
    }
    if (!processorType.equals(healthCheckerType)) {
        throw new RuntimeException("An unmatched processor and healthChecker are detected in the extension package.");
    }
    if (processorType.size() > origin.size()) {
        processorType.removeAll(origin);
        LOGGER.debug("init health plugin : types=" + processorType);
    }
}
Also used : HealthCheckProcessor(com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor) AbstractHealthChecker(com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker) HealthCheckType(com.alibaba.nacos.api.naming.pojo.healthcheck.HealthCheckType) HashSet(java.util.HashSet)

Aggregations

AbstractHealthChecker (com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker)1 HealthCheckType (com.alibaba.nacos.api.naming.pojo.healthcheck.HealthCheckType)1 HealthCheckProcessor (com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor)1 HashSet (java.util.HashSet)1