private void assumeLeadership()

in modules/core/src/main/java/org/apache/fluo/core/oracle/OracleServer.java [361:396]


  private void assumeLeadership() {
    Preconditions.checkState(!isLeader);

    // sanity check- make sure previous oracle is no longer listening for connections
    if (currentLeader != null) {
      String[] address = currentLeader.getId().split(":");
      String host = address[0];
      int port = Integer.parseInt(address[1]);

      OracleService.Client client = getOracleClient(host, port);
      if (client != null) {
        try {
          while (client.isLeader()) {
            Thread.sleep(500);
          }
        } catch (Exception e) {
          log.debug("Exception thrown in takeLeadership()", e);
        }
      }
    }

    try {
      synchronized (this) {
        byte[] d = curatorFramework.getData().forPath(maxTsPath);
        currentTs = maxTs = LongUtil.fromByteArray(d);
      }

      gcTsTracker = new GcTimestampTracker();
      gcTsTracker.start();

      isLeader = true;
      log.info("Assumed leadership " + leaderLatch.getId());
    } catch (Exception e) {
      log.warn("Failed to become leader ", e);
    }
  }