Search in sources :

Example 6 with EtcdKeysResponse

use of mousio.etcd4j.responses.EtcdKeysResponse in project camel by apache.

the class EtcdRoutePolicy method tryTakeLeadership.

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);
        EtcdHelper.setIndex(index, response);
    } catch (EtcdException e) {
        if (!e.isErrorCode(EtcdErrorCode.NodeExist)) {
            throw e;
        }
    }
    return result;
}
Also used : EtcdKeysResponse(mousio.etcd4j.responses.EtcdKeysResponse) EtcdException(mousio.etcd4j.responses.EtcdException)

Aggregations

EtcdKeysResponse (mousio.etcd4j.responses.EtcdKeysResponse)6 EtcdException (mousio.etcd4j.responses.EtcdException)4 TimeoutException (java.util.concurrent.TimeoutException)3 RuntimeCamelException (org.apache.camel.RuntimeCamelException)3 EtcdClient (mousio.etcd4j.EtcdClient)2 Exchange (org.apache.camel.Exchange)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 EtcdKeyGetRequest (mousio.etcd4j.requests.EtcdKeyGetRequest)1 Predicate (org.apache.camel.Predicate)1 ServiceDefinition (org.apache.camel.cloud.ServiceDefinition)1 EtcdConfiguration (org.apache.camel.component.etcd.EtcdConfiguration)1 EtcdHelper (org.apache.camel.component.etcd.EtcdHelper)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1