Search in sources :

Example 1 with EtcdException

use of io.etcd.jetcd.common.exception.EtcdException in project dubbo by alibaba.

the class JEtcdClientWrapper method keepAlive.

@SuppressWarnings("unchecked")
private <T> void keepAlive(long lease, Consumer<T> onFailed) {
    final StreamObserver<LeaseKeepAliveResponse> observer = new Observers.Builder().onError((e) -> {
        if (e instanceof EtcdException) {
            EtcdException error = (EtcdException) e;
            /**
             * ttl has expired
             */
            if (error.getErrorCode() == ErrorCode.NOT_FOUND) {
                keepAlive0(onFailed);
            }
        }
    }).onCompleted(() -> {
        /**
         * deadline reached.
         */
        keepAlive0(onFailed);
    }).build();
    /**
     * If there is already a keepalive, cancel first
     */
    cancelKeepAlive();
    /**
     * create and set new keepAlive to globalKeepAliveRef
     */
    this.keepAlive = client.getLeaseClient().keepAlive(lease, observer);
}
Also used : LeaseKeepAliveResponse(io.etcd.jetcd.lease.LeaseKeepAliveResponse) Observers(io.etcd.jetcd.support.Observers) EtcdException(io.etcd.jetcd.common.exception.EtcdException)

Aggregations

EtcdException (io.etcd.jetcd.common.exception.EtcdException)1 LeaseKeepAliveResponse (io.etcd.jetcd.lease.LeaseKeepAliveResponse)1 Observers (io.etcd.jetcd.support.Observers)1