private synchronized ServiceEndPoint choose(Map<String, ServiceEndPoint> endPointsById, HashCode partitionHash) { // Update the ring if the set of active end points has changed. for (String endPointId : Sets.difference(_endPointsById.keySet(), endPointsById.keySet())) { for (Integer hash : computeHashCodes(endPointId)) { _ring.remove(hash); } } for (String endPointId : Sets.difference(endPointsById.keySet(), _endPointsById.keySet())) { for (Integer hash : computeHashCodes(endPointId)) { _ring.put(hash, endPointId); } } if (!_endPointsById.equals(endPointsById)) { _endPointsById = endPointsById; } // For the given partition hash, find its location in the ring and return its associated end point. Map.Entry<Integer, String> entry = _ring.ceilingEntry(partitionHash.asInt()); if (entry == null) { entry = _ring.firstEntry(); } return _endPointsById.get(entry.getValue()); }
private synchronized ServiceEndPoint choose(Map<String, ServiceEndPoint> endPointsById, HashCode partitionHash) { // Update the ring if the set of active end points has changed. for (String endPointId : Sets.difference(_endPointsById.keySet(), endPointsById.keySet())) { for (Integer hash : computeHashCodes(endPointId)) { _ring.remove(hash); } } for (String endPointId : Sets.difference(endPointsById.keySet(), _endPointsById.keySet())) { for (Integer hash : computeHashCodes(endPointId)) { _ring.put(hash, endPointId); } } if (!_endPointsById.equals(endPointsById)) { _endPointsById = endPointsById; } // For the given partition hash, find its location in the ring and return its associated end point. Map.Entry<Integer, String> entry = _ring.ceilingEntry(partitionHash.asInt()); if (entry == null) { entry = _ring.firstEntry(); } return _endPointsById.get(entry.getValue()); }