public BiMultiValMap(BiMultiValMap<K, V> map) { this(); forwardMap.putAll(map); reverseMap.putAll(map.inverse()); }
private void addBootstrapTokens(Collection<Token> tokens, InetAddress endpoint, InetAddress original) { assert tokens != null && !tokens.isEmpty(); assert endpoint != null; lock.writeLock().lock(); try { InetAddress oldEndpoint; for (Token token : tokens) { oldEndpoint = bootstrapTokens.get(token); if (oldEndpoint != null && !oldEndpoint.equals(endpoint)) throw new RuntimeException("Bootstrap Token collision between " + oldEndpoint + " and " + endpoint + " (token " + token); oldEndpoint = tokenToEndpointMap.get(token); if (oldEndpoint != null && !oldEndpoint.equals(endpoint) && !oldEndpoint.equals(original)) throw new RuntimeException("Bootstrap Token collision between " + oldEndpoint + " and " + endpoint + " (token " + token); } bootstrapTokens.removeValue(endpoint); for (Token token : tokens) bootstrapTokens.put(token, endpoint); } finally { lock.writeLock().unlock(); } }
/** @return a copy of the bootstrapping tokens map */ public BiMultiValMap<Token, InetAddress> getBootstrapTokens() { lock.readLock().lock(); try { return new BiMultiValMap<Token, InetAddress>(bootstrapTokens); } finally { lock.readLock().unlock(); } }
if (bootstrapTokens.isEmpty() && leavingEndpoints.isEmpty() && movingEndpoints.isEmpty()) BiMultiValMap<Token, InetAddress> bootstrapTokens = new BiMultiValMap<>(); Set<InetAddress> leavingEndpoints = new HashSet<>(); Set<Pair<Token, InetAddress>> movingEndpoints = new HashSet<>(); try bootstrapTokens.putAll(this.bootstrapTokens); leavingEndpoints.addAll(this.leavingEndpoints); movingEndpoints.addAll(this.movingEndpoints);
bootstrapTokens.removeValue(endpoint); tokenToEndpointMap.removeValue(endpoint); topology.addEndpoint(endpoint); leavingEndpoints.remove(endpoint); InetAddress prev = tokenToEndpointMap.put(token, endpoint); if (!endpoint.equals(prev))
private ArrayList<Token> sortTokens() { return new ArrayList<>(tokenToEndpointMap.keySet()); }
public void putAll(Map<? extends K, ? extends V> m) { for (Map.Entry<? extends K, ? extends V> entry : m.entrySet()) put(entry.getKey(), entry.getValue()); }
public InetAddress getEndpoint(Token token) { lock.readLock().lock(); try { return tokenToEndpointMap.get(token); } finally { lock.readLock().unlock(); } }
public void removeBootstrapTokens(Collection<Token> tokens) { assert tokens != null && !tokens.isEmpty(); lock.writeLock().lock(); try { for (Token token : tokens) bootstrapTokens.remove(token); } finally { lock.writeLock().unlock(); } }
/** @return an endpoint to token multimap representation of tokenToEndpointMap (a copy) */ public Multimap<InetAddress, Token> getEndpointToTokenMapForReading() { lock.readLock().lock(); try { Multimap<InetAddress, Token> cloned = HashMultimap.create(); for (Map.Entry<Token, InetAddress> entry : tokenToEndpointMap.entrySet()) cloned.put(entry.getValue(), entry.getKey()); return cloned; } finally { lock.readLock().unlock(); } }
/** used by tests */ public void clearUnsafe() { lock.writeLock().lock(); try { tokenToEndpointMap.clear(); endpointToHostIdMap.clear(); bootstrapTokens.clear(); leavingEndpoints.clear(); pendingRanges.clear(); movingEndpoints.clear(); sortedTokens.clear(); topology.clear(); invalidateCachedRings(); } finally { lock.writeLock().unlock(); } }
public void removeEndpoint(InetAddress endpoint) { assert endpoint != null; lock.writeLock().lock(); try { bootstrapTokens.removeValue(endpoint); tokenToEndpointMap.removeValue(endpoint); topology.removeEndpoint(endpoint); leavingEndpoints.remove(endpoint); endpointToHostIdMap.remove(endpoint); sortedTokens = sortTokens(); invalidateCachedRings(); } finally { lock.writeLock().unlock(); } }
if (bootstrapTokens.isEmpty() && leavingEndpoints.isEmpty() && movingEndpoints.isEmpty()) BiMultiValMap<Token, InetAddress> bootstrapTokens = new BiMultiValMap<>(); Set<InetAddress> leavingEndpoints = new HashSet<>(); Set<Pair<Token, InetAddress>> movingEndpoints = new HashSet<>(); try bootstrapTokens.putAll(this.bootstrapTokens); leavingEndpoints.addAll(this.leavingEndpoints); movingEndpoints.addAll(this.movingEndpoints);
bootstrapTokens.removeValue(endpoint); tokenToEndpointMap.removeValue(endpoint); topology.addEndpoint(endpoint); leavingEndpoints.remove(endpoint); InetAddress prev = tokenToEndpointMap.put(token, endpoint); if (!endpoint.equals(prev))
private ArrayList<Token> sortTokens() { return new ArrayList<>(tokenToEndpointMap.keySet()); }
public void putAll(Map<? extends K, ? extends V> m) { for (Map.Entry<? extends K, ? extends V> entry : m.entrySet()) put(entry.getKey(), entry.getValue()); }
public InetAddress getEndpoint(Token token) { lock.readLock().lock(); try { return tokenToEndpointMap.get(token); } finally { lock.readLock().unlock(); } }