public void addBootstrapToken(Token token, InetAddress endpoint) { assert token != null; assert endpoint != null; lock.writeLock().lock(); try { InetAddress oldEndPoint = null; 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)) throw new RuntimeException( "Bootstrap Token collision between " + oldEndPoint + " and " + endpoint + " (token " + token); bootstrapTokens.inverse().remove(endpoint); bootstrapTokens.put(token, endpoint); } finally { lock.writeLock().unlock(); } }
@Override protected void assertMoreInvariants(Map<String, Integer> map) { BiMap<String, Integer> bimap = (BiMap<String, Integer>) map; BiMap<Integer, String> inverse = bimap.inverse(); assertEquals(bimap.size(), inverse.size()); for (Entry<String, Integer> entry : bimap.entrySet()) { assertEquals(entry.getKey(), inverse.get(entry.getValue())); } for (Entry<Integer, String> entry : inverse.entrySet()) { assertEquals(entry.getKey(), bimap.get(entry.getValue())); } }
/** * Store an end-point to host ID mapping. Each ID must be unique, and cannot be changed after the * fact. * * @param hostId * @param endpoint */ public void updateHostId(UUID hostId, InetAddress endpoint) { assert hostId != null; assert endpoint != null; lock.writeLock().lock(); try { InetAddress storedEp = endpointToHostIdMap.inverse().get(hostId); if (storedEp != null) { if (!storedEp.equals(endpoint) && (FailureDetector.instance.isAlive(storedEp))) { throw new RuntimeException( String.format( "Host ID collision between active endpoint %s and %s (id=%s)", storedEp, endpoint, hostId)); } } UUID storedId = endpointToHostIdMap.get(endpoint); if ((storedId != null) && (!storedId.equals(hostId))) logger.warn("Changing {}'s host ID from {} to {}", endpoint, storedId, hostId); endpointToHostIdMap.forcePut(endpoint, hostId); } finally { lock.writeLock().unlock(); } }
public InetAddress getEndPoint(Token token) { lock.readLock().lock(); try { return tokenToEndPointMap.get(token); } finally { lock.readLock().unlock(); } }
/** Return the unique host ID for an end-point. */ public UUID getHostId(InetAddress endpoint) { lock.readLock().lock(); try { return endpointToHostIdMap.get(endpoint); } finally { lock.readLock().unlock(); } }
public UUID convertOldCfId(Integer oldCfId) throws UnknownColumnFamilyException { UUID cfId = oldCfIdMap.get(oldCfId); if (cfId == null) throw new UnknownColumnFamilyException( "ColumnFamily identified by old " + oldCfId + " was not found.", null); return cfId; }
public InetAddress getFirstEndpoint() { assert tokenToEndPointMap.size() > 0; lock.readLock().lock(); try { return tokenToEndPointMap.get(sortedTokens.get(0)); } finally { lock.readLock().unlock(); } }
@Test public void whenCreateBiMap_thenCreated() { final BiMap<String, Integer> words = HashBiMap.create(); words.put("First", 1); words.put("Second", 2); words.put("Third", 3); assertEquals(2, words.get("Second").intValue()); assertEquals("Third", words.inverse().get(3)); }
public Class<?> classOf(ONIX o) { return map.get(o); }
public ONIX onixTypeOf(Object o) { return map.get(o.getClass()); }