@Override public void onDown(Host host) { CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc(host)); if (dcHosts != null) dcHosts.remove(host); }
@Override public void onUp(Host host) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, // use it. if (localDc == UNSET && dc != UNSET) { logger.info( "Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null) { CopyOnWriteArrayList<Host> newMap = new CopyOnWriteArrayList<Host>(Collections.singletonList(host)); dcHosts = perDcLiveHosts.putIfAbsent(dc, newMap); // If we've successfully put our new host, we're good, otherwise we've been beaten so continue if (dcHosts == null) return; } dcHosts.addIfAbsent(host); }
String dc = dc(host);
/** * Return the HostDistance for the provided host. * * <p>This policy consider nodes in the local datacenter as {@code LOCAL}. For each remote * datacenter, it considers a configurable number of hosts as {@code REMOTE} and the rest is * {@code IGNORED}. * * <p>To configure how many hosts in each remote datacenter should be considered, see {@link * Builder#withUsedHostsPerRemoteDc(int)}. * * @param host the host of which to return the distance of. * @return the HostDistance to {@code host}. */ @Override public HostDistance distance(Host host) { String dc = dc(host); if (dc == UNSET || dc.equals(localDc)) return HostDistance.LOCAL; CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null || usedHostsPerRemoteDc == 0) return HostDistance.IGNORED; // We need to clone, otherwise our subList call is not thread safe dcHosts = cloneList(dcHosts); return dcHosts.subList(0, Math.min(dcHosts.size(), usedHostsPerRemoteDc)).contains(host) ? HostDistance.REMOTE : HostDistance.IGNORED; }
@Override public void onDown(Host host) { CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc(host)); if (dcHosts != null) dcHosts.remove(host); }
@Override public void onDown(Host host) { CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc(host)); if (dcHosts != null) dcHosts.remove(host); }
@Override public void onDown(Host host) { CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc(host)); if (dcHosts != null) dcHosts.remove(host); }
@Override public void onDown(Host host) { CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc(host)); if (dcHosts != null) dcHosts.remove(host); }
@Override public void onUp(Host host) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null) { CopyOnWriteArrayList<Host> newMap = new CopyOnWriteArrayList<Host>(Collections.singletonList(host)); dcHosts = perDcLiveHosts.putIfAbsent(dc, newMap); // If we've successfully put our new host, we're good, otherwise we've been beaten so continue if (dcHosts == null) return; } dcHosts.addIfAbsent(host); }
@Override public void onUp(Host host) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null) { CopyOnWriteArrayList<Host> newMap = new CopyOnWriteArrayList<Host>(Collections.singletonList(host)); dcHosts = perDcLiveHosts.putIfAbsent(dc, newMap); // If we've successfully put our new host, we're good, otherwise we've been beaten so continue if (dcHosts == null) return; } dcHosts.addIfAbsent(host); }
@Override public void onUp(Host host) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null) { CopyOnWriteArrayList<Host> newMap = new CopyOnWriteArrayList<Host>(Collections.singletonList(host)); dcHosts = perDcLiveHosts.putIfAbsent(dc, newMap); // If we've successfully put our new host, we're good, otherwise we've been beaten so continue if (dcHosts == null) return; } dcHosts.addIfAbsent(host); }
@Override public void onUp(Host host) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null) { CopyOnWriteArrayList<Host> newMap = new CopyOnWriteArrayList<Host>(Collections.singletonList(host)); dcHosts = perDcLiveHosts.putIfAbsent(dc, newMap); // If we've successfully put our new host, we're good, otherwise we've been beaten so continue if (dcHosts == null) return; } dcHosts.addIfAbsent(host); }
@Override public void init(Cluster cluster, Collection<Host> hosts) { this.queryOptions = cluster.getConfiguration().getQueryOptions(); for (Host host : hosts) { String dc = dc(host); CopyOnWriteArrayList<Host> prev = perDcLiveHosts.get(dc); if (prev == null) perDcLiveHosts.put(dc, new CopyOnWriteArrayList<Host>(Collections.singletonList(host))); else prev.addIfAbsent(host); } }
@Override public void init(Cluster cluster, Collection<Host> hosts) { if (localDc != UNSET) logger.info("Using provided data-center name '{}' for DCAwareRoundRobinPolicy", localDc); this.configuration = cluster.getConfiguration(); ArrayList<String> notInLocalDC = new ArrayList<String>(); for (Host host : hosts) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } else if (!dc.equals(localDc)) notInLocalDC.add(String.format("%s (%s)", host.toString(), dc)); CopyOnWriteArrayList<Host> prev = perDcLiveHosts.get(dc); if (prev == null) perDcLiveHosts.put(dc, new CopyOnWriteArrayList<Host>(Collections.singletonList(host))); else prev.addIfAbsent(host); } if (notInLocalDC.size() > 0) { String nonLocalHosts = Joiner.on(",").join(notInLocalDC); logger.warn("Some contact points don't match local data center. Local DC = {}. Non-conforming contact points: {}", localDc, nonLocalHosts); } this.index.set(new Random().nextInt(Math.max(hosts.size(), 1))); }
@Override public void init(Cluster cluster, Collection<Host> hosts) { if (localDc != UNSET) logger.info("Using provided data-center name '{}' for DCAwareRoundRobinPolicy", localDc); this.configuration = cluster.getConfiguration(); ArrayList<String> notInLocalDC = new ArrayList<String>(); for (Host host : hosts) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } else if (!dc.equals(localDc)) notInLocalDC.add(String.format("%s (%s)", host.toString(), dc)); CopyOnWriteArrayList<Host> prev = perDcLiveHosts.get(dc); if (prev == null) perDcLiveHosts.put(dc, new CopyOnWriteArrayList<Host>(Collections.singletonList(host))); else prev.addIfAbsent(host); } if (notInLocalDC.size() > 0) { String nonLocalHosts = Joiner.on(",").join(notInLocalDC); logger.warn("Some contact points don't match local data center. Local DC = {}. Non-conforming contact points: {}", localDc, nonLocalHosts); } this.index.set(new Random().nextInt(Math.max(hosts.size(), 1))); }
@Override public void init(Cluster cluster, Collection<Host> hosts) { if (localDc != UNSET) logger.info("Using provided data-center name '{}' for DCAwareRoundRobinPolicy", localDc); this.configuration = cluster.getConfiguration(); ArrayList<String> notInLocalDC = new ArrayList<String>(); for (Host host : hosts) { String dc = dc(host); // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. if (localDc == UNSET && dc != UNSET) { logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc); localDc = dc; } else if (!dc.equals(localDc)) notInLocalDC.add(String.format("%s (%s)", host.toString(), dc)); CopyOnWriteArrayList<Host> prev = perDcLiveHosts.get(dc); if (prev == null) perDcLiveHosts.put(dc, new CopyOnWriteArrayList<Host>(Collections.singletonList(host))); else prev.addIfAbsent(host); } if (notInLocalDC.size() > 0) { String nonLocalHosts = Joiner.on(",").join(notInLocalDC); logger.warn("Some contact points don't match local data center. Local DC = {}. Non-conforming contact points: {}", localDc, nonLocalHosts); } this.index.set(new Random().nextInt(Math.max(hosts.size(), 1))); }
/** * Return the HostDistance for the provided host. * <p/> * This policy consider nodes in the local datacenter as {@code LOCAL}. * For each remote datacenter, it considers a configurable number of * hosts as {@code REMOTE} and the rest is {@code IGNORED}. * <p/> * To configure how many hosts in each remote datacenter should be considered, * see {@link Builder#withUsedHostsPerRemoteDc(int)}. * * @param host the host of which to return the distance of. * @return the HostDistance to {@code host}. */ @Override public HostDistance distance(Host host) { String dc = dc(host); if (dc == UNSET || dc.equals(localDc)) return HostDistance.LOCAL; CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null || usedHostsPerRemoteDc == 0) return HostDistance.IGNORED; // We need to clone, otherwise our subList call is not thread safe dcHosts = cloneList(dcHosts); return dcHosts.subList(0, Math.min(dcHosts.size(), usedHostsPerRemoteDc)).contains(host) ? HostDistance.REMOTE : HostDistance.IGNORED; }
/** * Return the HostDistance for the provided host. * <p/> * This policy consider nodes in the local datacenter as {@code LOCAL}. * For each remote datacenter, it considers a configurable number of * hosts as {@code REMOTE} and the rest is {@code IGNORED}. * <p/> * To configure how many hosts in each remote datacenter should be considered, * see {@link Builder#withUsedHostsPerRemoteDc(int)}. * * @param host the host of which to return the distance of. * @return the HostDistance to {@code host}. */ @Override public HostDistance distance(Host host) { String dc = dc(host); if (dc == UNSET || dc.equals(localDc)) return HostDistance.LOCAL; CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null || usedHostsPerRemoteDc == 0) return HostDistance.IGNORED; // We need to clone, otherwise our subList call is not thread safe dcHosts = cloneList(dcHosts); return dcHosts.subList(0, Math.min(dcHosts.size(), usedHostsPerRemoteDc)).contains(host) ? HostDistance.REMOTE : HostDistance.IGNORED; }
/** * Return the HostDistance for the provided host. * <p/> * This policy consider nodes in the local datacenter as {@code LOCAL}. * For each remote datacenter, it considers a configurable number of * hosts as {@code REMOTE} and the rest is {@code IGNORED}. * <p/> * To configure how many hosts in each remote datacenter should be considered, * see {@link Builder#withUsedHostsPerRemoteDc(int)}. * * @param host the host of which to return the distance of. * @return the HostDistance to {@code host}. */ @Override public HostDistance distance(Host host) { String dc = dc(host); if (dc == UNSET || dc.equals(localDc)) return HostDistance.LOCAL; CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null || usedHostsPerRemoteDc == 0) return HostDistance.IGNORED; // We need to clone, otherwise our subList call is not thread safe dcHosts = cloneList(dcHosts); return dcHosts.subList(0, Math.min(dcHosts.size(), usedHostsPerRemoteDc)).contains(host) ? HostDistance.REMOTE : HostDistance.IGNORED; }
/** * Return the HostDistance for the provided host. * <p> * This policy consider nodes in the local datacenter as {@code LOCAL}. * For each remote datacenter, it considers a configurable number of * hosts as {@code REMOTE} and the rest is {@code IGNORED}. * <p> * To configure how many host in each remote datacenter is considered * {@code REMOTE}, see {@link #DCAwareRoundRobinPolicy(String, int)}. * * @param host the host of which to return the distance of. * @return the HostDistance to {@code host}. */ @Override public HostDistance distance(Host host) { String dc = dc(host); if (dc == UNSET || dc.equals(localDc)) return HostDistance.LOCAL; CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc); if (dcHosts == null || usedHostsPerRemoteDc == 0) return HostDistance.IGNORED; // We need to clone, otherwise our subList call is not thread safe dcHosts = cloneList(dcHosts); return dcHosts.subList(0, Math.min(dcHosts.size(), usedHostsPerRemoteDc)).contains(host) ? HostDistance.REMOTE : HostDistance.IGNORED; }