Search in sources :

Example 1 with DcAgnosticNodeSet

use of com.datastax.oss.driver.internal.core.loadbalancing.nodeset.DcAgnosticNodeSet in project java-driver by datastax.

the class BasicLoadBalancingPolicy method init.

@Override
public void init(@NonNull Map<UUID, Node> nodes, @NonNull DistanceReporter distanceReporter) {
    this.distanceReporter = distanceReporter;
    localDc = discoverLocalDc(nodes).orElse(null);
    nodeDistanceEvaluator = createNodeDistanceEvaluator(localDc, nodes);
    liveNodes = localDc == null ? new DcAgnosticNodeSet() : maxNodesPerRemoteDc <= 0 ? new SingleDcNodeSet(localDc) : new MultiDcNodeSet();
    for (Node node : nodes.values()) {
        NodeDistance distance = computeNodeDistance(node);
        distanceReporter.setDistance(node, distance);
        if (distance != NodeDistance.IGNORED && node.getState() != NodeState.DOWN) {
            // This includes state == UNKNOWN. If the node turns out to be unreachable, this will be
            // detected when we try to open a pool to it, it will get marked down and this will be
            // signaled back to this policy, which will then remove it from the live set.
            liveNodes.add(node);
        }
    }
}
Also used : SingleDcNodeSet(com.datastax.oss.driver.internal.core.loadbalancing.nodeset.SingleDcNodeSet) NodeDistance(com.datastax.oss.driver.api.core.loadbalancing.NodeDistance) MultiDcNodeSet(com.datastax.oss.driver.internal.core.loadbalancing.nodeset.MultiDcNodeSet) Node(com.datastax.oss.driver.api.core.metadata.Node) DcAgnosticNodeSet(com.datastax.oss.driver.internal.core.loadbalancing.nodeset.DcAgnosticNodeSet)

Aggregations

NodeDistance (com.datastax.oss.driver.api.core.loadbalancing.NodeDistance)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 DcAgnosticNodeSet (com.datastax.oss.driver.internal.core.loadbalancing.nodeset.DcAgnosticNodeSet)1 MultiDcNodeSet (com.datastax.oss.driver.internal.core.loadbalancing.nodeset.MultiDcNodeSet)1 SingleDcNodeSet (com.datastax.oss.driver.internal.core.loadbalancing.nodeset.SingleDcNodeSet)1