Пример #1
0
 @Override
 public CompletableFuture<Void> set(V value) {
   final MeteringAgent.Context newTimer = monitor.startTimer(SET);
   if (value == null) {
     return backingMap.remove(name).whenComplete((r, e) -> newTimer.stop(e)).thenApply(v -> null);
   }
   return backingMap
       .put(name, serializer.encode(value))
       .whenComplete((r, e) -> newTimer.stop(e))
       .thenApply(v -> null);
 }
Пример #2
0
 @Override
 public CompletableFuture<V> getAndSet(V value) {
   final MeteringAgent.Context newTimer = monitor.startTimer(GET_AND_SET);
   if (value == null) {
     return backingMap
         .remove(name)
         .thenApply(Versioned::valueOrNull)
         .thenApply(v -> v == null ? null : serializer.<V>decode(v))
         .whenComplete((r, e) -> newTimer.stop(e));
   }
   return backingMap
       .put(name, serializer.encode(value))
       .thenApply(Versioned::valueOrNull)
       .thenApply(v -> v == null ? null : serializer.<V>decode(v))
       .whenComplete((r, e) -> newTimer.stop(e));
 }