localLiveHosts == null ? Collections.<Host>emptyList() : cloneList(localLiveHosts); final int startIdx = index.getAndIncrement();
/** * 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; }
final List<Host> hosts = localLiveHosts == null ? Collections.<Host>emptyList() : cloneList(localLiveHosts); final int startIdx = index.getAndIncrement();
final List<Host> hosts = localLiveHosts == null ? Collections.<Host>emptyList() : cloneList(localLiveHosts); final int startIdx = index.getAndIncrement();
final List<Host> hosts = localLiveHosts == null ? Collections.<Host>emptyList() : cloneList(localLiveHosts); final int startIdx = index.getAndIncrement();
final List<Host> hosts = localLiveHosts == null ? Collections.<Host>emptyList() : cloneList(localLiveHosts); final int startIdx = index.getAndIncrement();
/** * 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; }
/** * 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; }