Search in sources :

Example 1 with CompareOrBuilder

use of com.ibm.etcd.api.CompareOrBuilder in project etcd-java by IBM.

the class RangeCache method doPut.

protected ListenableFuture<TxnResponse> doPut(ByteString key, ByteString value, boolean getOnFail, long lease, CompareOrBuilder... conditions) {
    TxnRequest.Builder tb = TxnRequest.newBuilder();
    if (conditions != null && conditions.length > 0) {
        for (CompareOrBuilder comp : conditions) {
            if (comp instanceof Compare)
                tb.addCompare((Compare) comp);
            else
                tb.addCompare((Compare.Builder) comp);
        }
    } else
        getOnFail = false;
    RequestOp.Builder bld = RequestOp.newBuilder();
    RequestOp getOp = getOnFail || value != null ? getReq(bld, key) : null;
    if (value != null)
        tb.addSuccess(putReq(bld, key, value, lease)).addSuccess(getOp);
    else
        tb.addSuccess(deleteReq(bld, key));
    if (getOnFail)
        tb.addFailure(getOp);
    return kvClient.txn(tb.build());
}
Also used : TxnRequest(com.ibm.etcd.api.TxnRequest) CompareOrBuilder(com.ibm.etcd.api.CompareOrBuilder) CompareOrBuilder(com.ibm.etcd.api.CompareOrBuilder) Compare(com.ibm.etcd.api.Compare) RequestOp(com.ibm.etcd.api.RequestOp)

Aggregations

Compare (com.ibm.etcd.api.Compare)1 CompareOrBuilder (com.ibm.etcd.api.CompareOrBuilder)1 RequestOp (com.ibm.etcd.api.RequestOp)1 TxnRequest (com.ibm.etcd.api.TxnRequest)1