コード例 #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();
    }
  }
コード例 #2
0
 @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()));
   }
 }
コード例 #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();
    }
  }
コード例 #4
0
 public InetAddress getEndPoint(Token token) {
   lock.readLock().lock();
   try {
     return tokenToEndPointMap.get(token);
   } finally {
     lock.readLock().unlock();
   }
 }
コード例 #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();
   }
 }
コード例 #6
0
ファイル: Schema.java プロジェクト: Steve667/cassandra-cdh4
  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;
  }
コード例 #7
0
  public InetAddress getFirstEndpoint() {
    assert tokenToEndPointMap.size() > 0;

    lock.readLock().lock();
    try {
      return tokenToEndPointMap.get(sortedTokens.get(0));
    } finally {
      lock.readLock().unlock();
    }
  }
コード例 #8
0
  @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));
  }
コード例 #9
0
ファイル: JonixResolver.java プロジェクト: JoerKt/jonix
 public Class<?> classOf(ONIX o) {
   return map.get(o);
 }
コード例 #10
0
ファイル: JonixResolver.java プロジェクト: JoerKt/jonix
 public ONIX onixTypeOf(Object o) {
   return map.get(o.getClass());
 }