Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017, 2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.ibm.etcd.client.utils;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.google.protobuf.ByteString;
import com.ibm.etcd.client.EtcdClient;
import com.ibm.etcd.client.FutureListener;
import com.ibm.etcd.client.GrpcClient;
import com.ibm.etcd.client.ListenerObserver;
import com.ibm.etcd.client.kv.KvClient;
import com.ibm.etcd.client.lease.PersistentLease;
import com.ibm.etcd.client.lease.PersistentLease.LeaseState;
import com.ibm.etcd.api.PutRequest;
import com.ibm.etcd.api.RangeRequest;
import com.ibm.etcd.api.TxnResponse;
/**
* Etcd key-value bound to a PersistentLease. If the key already exists its
* value won't be changed but it will be associated with the provided lease.
* If it doesn't already exist or is deleted by someone else, it will be
* (re)-created with a provided default value.
*
* Can be optionally associated with a {@link RangeCache} within whose range the
* key lies. Doing so helps to ensure local state consistency between the two.
*
* Closing the {@link PersistentLeaseKey} will always delete the associated
* key-value.
*
*/
public class PersistentLeaseKey extends AbstractFuture implements AutoCloseable {
private final EtcdClient client;
protected final ByteString key;
protected final ListenerObserver stateObserver;
private final RangeCache rangeCache; // optional
private PersistentLease lease; // final post-start
private Executor executor; // serialized, final post-start
private volatile ByteString defaultValue;
// these only modified in serialized context
protected boolean leaseActive;
protected ListenableFuture> updateFuture;
protected SettableFuture