Пример #1
0
 public InetAddress getEndpoint(Token token) {
   lock.readLock().lock();
   try {
     return tokenToEndpointMap.get(token);
   } finally {
     lock.readLock().unlock();
   }
 }
Пример #2
0
  public void addBootstrapTokens(Collection<Token> tokens, InetAddress endpoint) {
    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))
          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();
    }
  }