use of com.ibm.etcd.api.ResponseOp in project etcd-java by IBM.
the class RangeCache method fullRefreshCache.
// internal method - should not be called while watch is active
protected ListenableFuture<Boolean> fullRefreshCache() {
ListenableFuture<List<RangeResponse>> rrfut;
long seenUpTo = seenUpToRev.get();
boolean firstTime = (seenUpTo == 0L);
if (firstTime || entries.size() <= 20) {
// TODO *maybe* chunking (for large caches)
ListenableFuture<RangeResponse> rrf = kvClient.get(fromKey).rangeEnd(toKey).backoffRetry(() -> !closed).timeout(300_000L).async();
rrfut = Futures.transform(rrf, Collections::singletonList, directExecutor());
} else {
// in case the local cache is large, reduce data transfer by requesting
// just keys, and full key+value only for those modified since seenUpToRev
RangeRequest.Builder rangeReqBld = RangeRequest.newBuilder().setKey(fromKey).setRangeEnd(toKey);
RangeRequest newModsReq = rangeReqBld.setMinModRevision(seenUpTo + 1).build();
RangeRequest otherKeysReq = rangeReqBld.clearMinModRevision().setMaxModRevision(seenUpTo).setKeysOnly(true).build();
ListenableFuture<TxnResponse> trf = kvClient.batch().get(newModsReq).get(otherKeysReq).backoffRetry(() -> !closed).timeout(300_000L).async();
rrfut = Futures.transform(trf, tr -> tr.getResponsesList().stream().map(ResponseOp::getResponseRange).collect(Collectors.toList()), directExecutor());
}
final SettableFuture<Boolean> promise = new SettableFuture<Boolean>() {
@Override
protected void interruptTask() {
if (rrfut.cancel(true)) {
return;
}
Watch theWatch;
synchronized (RangeCache.this) {
theWatch = watch;
}
if (theWatch != null) {
theWatch.close();
}
}
};
Futures.addCallback(rrfut, (FutureListener<List<RangeResponse>>) (rrs, err) -> {
if (rrs != null)
try {
setupWatch(rrs, firstTime, promise);
return;
} catch (Throwable t) {
err = t;
}
promise.setException(err);
}, listenerExecutor);
return promise;
}
Aggregations