@Override public void onAdd(Host host) { childPolicy.onAdd(host); }
@Override public void onAdd(Host host) { childPolicy.onAdd(host); }
@Override public void onAdd(Host host) { if (predicate.apply(host)) childPolicy.onAdd(host); }
@Override public void onAdd(Host host) { childPolicy.onAdd(host); latencyTracker.addHost(host); }
public void onAdd(Host host) { delegate.onAdd(host); }
private void updateChosenHosts() { if (chosenHosts.size() > maxHosts - threshold || liveHosts.size() == 0) return; // We lock to prevent two events from triggering this simultaneously. updateLock.lock(); try { int missing = maxHosts - chosenHosts.size(); if (missing < threshold || liveHosts.size() == 0) return; Set<Host> newlyChosen = new HashSet<Host>(); for (Host host : liveHosts) { // Note that this picks hosts whatever their distance is. // We can't reliably call childPolicy.distance() here, because the childPolicy // might require hosts to be already added to compute their distance properly // (this is the case for DCAware policy). newlyChosen.add(host); missing -= 1; if (missing == 0) break; } chosenHosts.addAll(newlyChosen); liveHosts.removeAll(newlyChosen); for (Host host : newlyChosen) { delegate.onAdd(host); // delegate should have updated the distance, inform the driver so that it can // recreate the pool. cluster.getConfiguration().getPoolingOptions().refreshConnectedHost(host); } } finally { updateLock.unlock(); } }
loadBalancingPolicy().onAdd(host);
@Test(groups = "unit") public void should_not_delegate_to_wrapped_policy_when_predicate_is_false() { Predicate<Host> predicate = Predicates.alwaysFalse(); HostFilterPolicy policy = new HostFilterPolicy(wrappedPolicy, predicate); policy.onAdd(host1); verify(wrappedPolicy, never()).onAdd(host1); policy.onDown(host1); verify(wrappedPolicy, never()).onDown(host1); policy.onUp(host1); verify(wrappedPolicy, never()).onUp(host1); policy.onRemove(host1); verify(wrappedPolicy, never()).onRemove(host1); assertThat(policy.distance(host1)).isSameAs(HostDistance.IGNORED); }
@Test(groups = "unit") public void should_delegate_to_wrapped_policy_when_predicate_is_true() { Predicate<Host> predicate = Predicates.alwaysTrue(); HostFilterPolicy policy = new HostFilterPolicy(wrappedPolicy, predicate); policy.onAdd(host1); verify(wrappedPolicy).onAdd(host1); policy.onDown(host1); verify(wrappedPolicy).onDown(host1); policy.onUp(host1); verify(wrappedPolicy).onUp(host1); policy.onRemove(host1); verify(wrappedPolicy).onRemove(host1); assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL); policy.close(); verify(wrappedPolicy).close(); }
private static void updateLocationInfo( Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (MoreObjects.equal(host.getDatacenter(), datacenter) && MoreObjects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing // policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }
@Override public void onAdd(Host host) { childPolicy.onAdd(host); }
@Override public void onAdd(Host host) { if (predicate.apply(host)) childPolicy.onAdd(host); }
if (!contactPointHosts.contains(host)) loadBalancingPolicy().onAdd(host);
@Override public void onAdd(Host host) { if (predicate.apply(host)) childPolicy.onAdd(host); }
@Override public void onAdd(Host host) { if (predicate.apply(host)) childPolicy.onAdd(host); }
@Override public void onAdd(Host host) { if (whiteList.contains(host.getSocketAddress())) childPolicy.onAdd(host); }
private static void updateLocationInfo(Host host, String datacenter, String rack, Cluster.Manager cluster) { if (Objects.equal(host.getDatacenter(), datacenter) && Objects.equal(host.getRack(), rack)) return; // If the dc/rack information changes, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); cluster.loadBalancingPolicy().onAdd(host); }
private static void updateLocationInfo(Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (MoreObjects.equal(host.getDatacenter(), datacenter) && MoreObjects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }
private static void updateLocationInfo(Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (Objects.equal(host.getDatacenter(), datacenter) && Objects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }