Search in sources :

Example 1 with NodeDistanceEvaluator

use of com.datastax.oss.driver.api.core.loadbalancing.NodeDistanceEvaluator in project java-driver by datastax.

the class DefaultNodeDistanceEvaluatorHelper method nodeDistanceEvaluatorFromConfig.

@NonNull
protected NodeDistanceEvaluator nodeDistanceEvaluatorFromConfig() {
    NodeDistanceEvaluator evaluator = context.getNodeDistanceEvaluator(profile.getName());
    if (evaluator != null) {
        LOG.debug("[{}] Node distance evaluator set programmatically", logPrefix);
    } else {
        evaluator = Reflection.buildFromConfig(context, profile.getName(), DefaultDriverOption.LOAD_BALANCING_DISTANCE_EVALUATOR_CLASS, NodeDistanceEvaluator.class).orElse(null);
        if (evaluator != null) {
            LOG.debug("[{}] Node distance evaluator set from configuration", logPrefix);
        } else {
            @SuppressWarnings({ "unchecked", "deprecation" }) Predicate<Node> nodeFilterFromConfig = Reflection.buildFromConfig(context, profile.getName(), DefaultDriverOption.LOAD_BALANCING_FILTER_CLASS, Predicate.class).orElse(null);
            if (nodeFilterFromConfig != null) {
                evaluator = new NodeFilterToDistanceEvaluatorAdapter(nodeFilterFromConfig);
                LOG.debug("[{}] Node distance evaluator set from deprecated node filter configuration", logPrefix);
            }
        }
    }
    if (evaluator == null) {
        evaluator = PASS_THROUGH_DISTANCE_EVALUATOR;
    }
    return evaluator;
}
Also used : NodeDistanceEvaluator(com.datastax.oss.driver.api.core.loadbalancing.NodeDistanceEvaluator) Node(com.datastax.oss.driver.api.core.metadata.Node) Predicate(java.util.function.Predicate) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

NodeDistanceEvaluator (com.datastax.oss.driver.api.core.loadbalancing.NodeDistanceEvaluator)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Predicate (java.util.function.Predicate)1