@Test public void getFirstNodeValue() { AbstractConsistentHash map = new TreeMapConsistentHash() ; List<String> strings = new ArrayList<String>(); for (int i = 0; i < 10; i++) { strings.add("127.0.0." + i) ; } String process = map.process(strings,"zhangsan"); System.out.println(process); Assert.assertEquals("127.0.0.2",process); }
@Override public String getFirstNodeValue(String value) { long hash = super.hash(value); System.out.println("value=" + value + " hash = " + hash); SortedMap<Long, String> last = treeMap.tailMap(hash); if (!last.isEmpty()) { return last.get(last.firstKey()); } if (treeMap.size() == 0){ throw new CIMException(StatusEnum.SERVER_NOT_AVAILABLE) ; } return treeMap.firstEntry().getValue(); }
TreeMapConsistentHash extends AbstractConsistentHash { @Override public String getFirstNodeValue(String value) { long hash = super.hash(value); System.out.println("value=" + value + " hash = " + hash); SortedMap<Long, String> last = treeMap.tailMap(hash); if (!last.isEmpty()) { return last.get(last.firstKey()); } if (treeMap.size() == 0){ throw new CIMException(StatusEnum.SERVER_NOT_AVAILABLE) ; } return treeMap.firstEntry().getValue(); } }
TreeMapConsistentHash extends AbstractConsistentHash { @Override public String getFirstNodeValue(String value) { long hash = super.hash(value); System.out.println("value=" + value + " hash = " + hash); SortedMap<Long, String> last = treeMap.tailMap(hash); if (!last.isEmpty()) { return last.get(last.firstKey()); } if (treeMap.size() == 0){ throw new CIMException(StatusEnum.SERVER_NOT_AVAILABLE) ; } return treeMap.firstEntry().getValue(); }  }
TreeMapConsistentHash extends AbstractConsistentHash { @Override public String getFirstNodeValue(String value) { long hash = super.hash(value); System.out.println("value=" + value + " hash = " + hash); SortedMap<Long, String> last = treeMap.tailMap(hash); if (!last.isEmpty()) { return last.get(last.firstKey()); } if (treeMap.size() == 0){ throw new CIMException(StatusEnum.SERVER_NOT_AVAILABLE) ; } return treeMap.firstEntry().getValue(); }  @Override void add(long key, String value); @Override String getFirstNodeValue(String value); }
TreeMapConsistentHash extends AbstractConsistentHash { @Override public String getFirstNodeValue(String value) { long hash = super.hash(value); System.out.println("value=" + value + " hash = " + hash); SortedMap<Long, String> last = treeMap.tailMap(hash); if (!last.isEmpty()) { return last.get(last.firstKey()); } if (treeMap.size() == 0){ throw new CIMException(StatusEnum.SERVER_NOT_AVAILABLE) ; } return treeMap.firstEntry().getValue(); }  @Override void add(long key, String value); @Override String getFirstNodeValue(String value);  }