예제 #1
0
  private void putMyOpinion(
      long stateTimestamp, HBRefData refData, HBResult result, String newState)
      throws MgmtZooKeeperException, NodeExistsException {
    String path = makePathOfMyOpinion(result.getTarget().getTargetOfHeartbeatPath());
    byte[] data;

    data = makeDataOfMyOpinion(refData, stateTimestamp, result, newState);

    try {
      zookeeper.createEphemeralZNode(path, data);
    } catch (NodeExistsException e) {
      Logger.error(
          "Put my opinion fail. path: {}, opinion: {}",
          path,
          makeStringOfMyOpinion(refData, stateTimestamp, newState),
          e);
      throw e;
    } catch (MgmtZooKeeperException e) {
      Logger.error(
          "Put my opinion fail. path: {}, opinion: {}",
          path,
          makeStringOfMyOpinion(refData, stateTimestamp, newState),
          e);
      throw e;
    }

    Logger.info(result.toString());

    refData.setLastState(newState);
    refData.setLastStateTimestamp(stateTimestamp);
    refData.setSubmitMyOpinion(true);
  }
예제 #2
0
  private void removeMyOpinion(HBRefData refData, HBResult result, String newState)
      throws MgmtZooKeeperException {
    String path = makePathOfMyOpinion(result.getTarget().getTargetOfHeartbeatPath());

    zookeeper.deleteZNode(path, -1);

    Logger.info(result.toString());

    refData.setLastState(Constant.SERVER_STATE_UNKNOWN);
    refData.setLastStateTimestamp(0L);
    refData.setSubmitMyOpinion(false);
  }