long getMaxKey() { return getKetamaNodes().lastKey(); }
MemcachedNode getNodeForKey(long hash) { final MemcachedNode rv; if (!ketamaNodes.containsKey(hash)) { // Java 1.6 adds a ceilingKey method, but I'm still stuck in 1.5 // in a lot of places, so I'm doing this myself. SortedMap<Long, MemcachedNode> tailMap = getKetamaNodes().tailMap(hash); if (tailMap.isEmpty()) { hash = getKetamaNodes().firstKey(); } else { hash = tailMap.firstKey(); } } rv = getKetamaNodes().get(hash); return rv; }
public NodeLocator getReadonlyCopy() { TreeMap<Long, MemcachedNode> smn = new TreeMap<Long, MemcachedNode>(getKetamaNodes()); Collection<MemcachedNode> an = new ArrayList<MemcachedNode>(allNodes.size()); // Rewrite the values a copy of the map. for (Map.Entry<Long, MemcachedNode> me : smn.entrySet()) { smn.put(me.getKey(), new MemcachedNodeROImpl(me.getValue())); } // Copy the allNodes collection. for (MemcachedNode n : allNodes) { an.add(new MemcachedNodeROImpl(n)); } return new RefinedKetamaNodeLocator(smn, an, hashAlg, weights, config); }
/** * the previous 7 may be too small to reduce the chance to get all down nodes * @param k * @return */ public Iterator<MemcachedNode> getSequence(String k) { // Seven searches gives us a 1 in 2^maxTry chance of hitting the // same dead node all of the time. int maxTry = config.getNodeRepetitions() + 1; if (maxTry < 20) { maxTry = 20; } return new KetamaIterator(k, maxTry, getKetamaNodes(), hashAlg); }
long getMaxKey() { return getKetamaNodes().lastKey(); }
MemcachedNode getNodeForKey(long hash) { final MemcachedNode rv; if (!ketamaNodes.containsKey(hash)) { // Java 1.6 adds a ceilingKey method, but I'm still stuck in 1.5 // in a lot of places, so I'm doing this myself. SortedMap<Long, MemcachedNode> tailMap = getKetamaNodes().tailMap(hash); if (tailMap.isEmpty()) { hash = getKetamaNodes().firstKey(); } else { hash = tailMap.firstKey(); } } rv = getKetamaNodes().get(hash); return rv; }
public NodeLocator getReadonlyCopy() { TreeMap<Long, MemcachedNode> smn = new TreeMap<Long, MemcachedNode>(getKetamaNodes()); Collection<MemcachedNode> an = new ArrayList<MemcachedNode>(allNodes.size()); // Rewrite the values a copy of the map. for (Map.Entry<Long, MemcachedNode> me : smn.entrySet()) { smn.put(me.getKey(), new MemcachedNodeROImpl(me.getValue())); } // Copy the allNodes collection. for (MemcachedNode n : allNodes) { an.add(new MemcachedNodeROImpl(n)); } return new RefinedKetamaNodeLocator(smn, an, hashAlg, weights, config); }
/** * the previous 7 may be too small to reduce the chance to get all down nodes * @param k * @return */ public Iterator<MemcachedNode> getSequence(String k) { // Seven searches gives us a 1 in 2^maxTry chance of hitting the // same dead node all of the time. int maxTry = config.getNodeRepetitions() + 1; if (maxTry < 20) { maxTry = 20; } return new KetamaIterator(k, maxTry, getKetamaNodes(), hashAlg); }