Exemplo n.º 1
0
  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()));
   }
 }
Exemplo n.º 3
0
  /**
   * 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();
    }
  }
Exemplo n.º 4
0
 public InetAddress getEndPoint(Token token) {
   lock.readLock().lock();
   try {
     return tokenToEndPointMap.get(token);
   } finally {
     lock.readLock().unlock();
   }
 }
Exemplo n.º 5
0
 /** 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();
   }
 }
Exemplo n.º 6
0
  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;
  }
Exemplo n.º 7
0
  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));
  }
Exemplo n.º 9
0
 public Class<?> classOf(ONIX o) {
   return map.get(o);
 }
Exemplo n.º 10
0
 public ONIX onixTypeOf(Object o) {
   return map.get(o.getClass());
 }