Esempio n. 1
0
 @Override
 public boolean equals(Object object) {
   if (object instanceof DefaultEndpoint) {
     DefaultEndpoint that = (DefaultEndpoint) object;
     return ObjectHelper.equal(this.getEndpointUri(), that.getEndpointUri());
   }
   return false;
 }
Esempio n. 2
0
  private boolean tryTakeLeadership() throws Exception {
    boolean result = false;

    try {
      EtcdKeysResponse response =
          getClient().put(servicePath, serviceName).prevExist(false).ttl(ttl).send().get();

      result = ObjectHelper.equal(serviceName, response.node.value);
      setIndex(response);
    } catch (EtcdException e) {
      if (!e.isErrorCode(EtcdErrorCode.NodeExist)) {
        throw e;
      }
    }

    return result;
  }
Esempio n. 3
0
  @Override
  public void onResponse(ResponsePromise<EtcdKeysResponse> promise) {
    if (!isRunAllowed()) {
      return;
    }

    Throwable throwable = promise.getException();
    if (throwable != null && throwable instanceof EtcdException) {
      EtcdException exception = (EtcdException) throwable;
      if (EtcdHelper.isOutdatedIndexException(exception)) {
        LOGGER.debug("Outdated index, key={}, cause={}", servicePath, exception.etcdCause);
        index.set(exception.index + 1);
        throwable = null;
      }
    } else {
      try {
        EtcdKeysResponse response = promise.get();
        setIndex(response);

        if (response.node.value == null) {
          setLeader(tryTakeLeadership());
        } else if (!ObjectHelper.equal(serviceName, response.node.value) && leader.get()) {
          // Looks like I've lost leadership
          setLeader(false);
        }
      } catch (TimeoutException e) {
        LOGGER.debug("Timeout watching for {}", servicePath);
        throwable = null;
      } catch (Exception e1) {
        throwable = e1;
      }
    }

    if (throwable == null) {
      try {
        watch();
      } catch (Exception e) {
        throw new RuntimeCamelException(e);
      }
    } else {
      throw new RuntimeCamelException(throwable);
    }
  }