Flavio Castro
Committed by Gerrit Code Review

Added feature to count exceptions ocurred when operating distributed primitives

Change-Id: I24017e61cd2aefd1cf78aa5b241a3219e3e89b32
...@@ -51,34 +51,34 @@ public class DefaultAsyncAtomicCounter implements AsyncAtomicCounter { ...@@ -51,34 +51,34 @@ public class DefaultAsyncAtomicCounter implements AsyncAtomicCounter {
51 public CompletableFuture<Long> incrementAndGet() { 51 public CompletableFuture<Long> incrementAndGet() {
52 final MeteringAgent.Context timer = monitor.startTimer(INCREMENT_AND_GET); 52 final MeteringAgent.Context timer = monitor.startTimer(INCREMENT_AND_GET);
53 return addAndGet(1L) 53 return addAndGet(1L)
54 - .whenComplete((r, e) -> timer.stop()); 54 + .whenComplete((r, e) -> timer.stop(e));
55 } 55 }
56 56
57 @Override 57 @Override
58 public CompletableFuture<Long> get() { 58 public CompletableFuture<Long> get() {
59 final MeteringAgent.Context timer = monitor.startTimer(GET); 59 final MeteringAgent.Context timer = monitor.startTimer(GET);
60 return database.counterGet(name) 60 return database.counterGet(name)
61 - .whenComplete((r, e) -> timer.stop()); 61 + .whenComplete((r, e) -> timer.stop(e));
62 } 62 }
63 63
64 @Override 64 @Override
65 public CompletableFuture<Long> getAndIncrement() { 65 public CompletableFuture<Long> getAndIncrement() {
66 final MeteringAgent.Context timer = monitor.startTimer(GET_AND_INCREMENT); 66 final MeteringAgent.Context timer = monitor.startTimer(GET_AND_INCREMENT);
67 return getAndAdd(1L) 67 return getAndAdd(1L)
68 - .whenComplete((r, e) -> timer.stop()); 68 + .whenComplete((r, e) -> timer.stop(e));
69 } 69 }
70 70
71 @Override 71 @Override
72 public CompletableFuture<Long> getAndAdd(long delta) { 72 public CompletableFuture<Long> getAndAdd(long delta) {
73 final MeteringAgent.Context timer = monitor.startTimer(GET_AND_ADD); 73 final MeteringAgent.Context timer = monitor.startTimer(GET_AND_ADD);
74 return database.counterGetAndAdd(name, delta) 74 return database.counterGetAndAdd(name, delta)
75 - .whenComplete((r, e) -> timer.stop()); 75 + .whenComplete((r, e) -> timer.stop(e));
76 } 76 }
77 77
78 @Override 78 @Override
79 public CompletableFuture<Long> addAndGet(long delta) { 79 public CompletableFuture<Long> addAndGet(long delta) {
80 final MeteringAgent.Context timer = monitor.startTimer(ADD_AND_GET); 80 final MeteringAgent.Context timer = monitor.startTimer(ADD_AND_GET);
81 return database.counterAddAndGet(name, delta) 81 return database.counterAddAndGet(name, delta)
82 - .whenComplete((r, e) -> timer.stop()); 82 + .whenComplete((r, e) -> timer.stop(e));
83 } 83 }
84 } 84 }
......
...@@ -193,14 +193,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -193,14 +193,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
193 public CompletableFuture<Integer> size() { 193 public CompletableFuture<Integer> size() {
194 final MeteringAgent.Context timer = monitor.startTimer(SIZE); 194 final MeteringAgent.Context timer = monitor.startTimer(SIZE);
195 return database.mapSize(name) 195 return database.mapSize(name)
196 - .whenComplete((r, e) -> timer.stop()); 196 + .whenComplete((r, e) -> timer.stop(e));
197 } 197 }
198 198
199 @Override 199 @Override
200 public CompletableFuture<Boolean> isEmpty() { 200 public CompletableFuture<Boolean> isEmpty() {
201 final MeteringAgent.Context timer = monitor.startTimer(IS_EMPTY); 201 final MeteringAgent.Context timer = monitor.startTimer(IS_EMPTY);
202 return database.mapIsEmpty(name) 202 return database.mapIsEmpty(name)
203 - .whenComplete((r, e) -> timer.stop()); 203 + .whenComplete((r, e) -> timer.stop(e));
204 } 204 }
205 205
206 @Override 206 @Override
...@@ -208,7 +208,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -208,7 +208,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
208 checkNotNull(key, ERROR_NULL_KEY); 208 checkNotNull(key, ERROR_NULL_KEY);
209 final MeteringAgent.Context timer = monitor.startTimer(CONTAINS_KEY); 209 final MeteringAgent.Context timer = monitor.startTimer(CONTAINS_KEY);
210 return database.mapContainsKey(name, keyCache.getUnchecked(key)) 210 return database.mapContainsKey(name, keyCache.getUnchecked(key))
211 - .whenComplete((r, e) -> timer.stop()); 211 + .whenComplete((r, e) -> timer.stop(e));
212 } 212 }
213 213
214 @Override 214 @Override
...@@ -216,7 +216,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -216,7 +216,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
216 checkNotNull(value, ERROR_NULL_VALUE); 216 checkNotNull(value, ERROR_NULL_VALUE);
217 final MeteringAgent.Context timer = monitor.startTimer(CONTAINS_VALUE); 217 final MeteringAgent.Context timer = monitor.startTimer(CONTAINS_VALUE);
218 return database.mapContainsValue(name, serializer.encode(value)) 218 return database.mapContainsValue(name, serializer.encode(value))
219 - .whenComplete((r, e) -> timer.stop()); 219 + .whenComplete((r, e) -> timer.stop(e));
220 } 220 }
221 221
222 @Override 222 @Override
...@@ -224,7 +224,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -224,7 +224,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
224 checkNotNull(key, ERROR_NULL_KEY); 224 checkNotNull(key, ERROR_NULL_KEY);
225 final MeteringAgent.Context timer = monitor.startTimer(GET); 225 final MeteringAgent.Context timer = monitor.startTimer(GET);
226 return database.mapGet(name, keyCache.getUnchecked(key)) 226 return database.mapGet(name, keyCache.getUnchecked(key))
227 - .whenComplete((r, e) -> timer.stop()) 227 + .whenComplete((r, e) -> timer.stop(e))
228 .thenApply(v -> v != null ? v.map(serializer::decode) : null); 228 .thenApply(v -> v != null ? v.map(serializer::decode) : null);
229 } 229 }
230 230
...@@ -235,7 +235,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -235,7 +235,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
235 checkNotNull(mappingFunction, "Mapping function cannot be null"); 235 checkNotNull(mappingFunction, "Mapping function cannot be null");
236 final MeteringAgent.Context timer = monitor.startTimer(COMPUTE_IF_ABSENT); 236 final MeteringAgent.Context timer = monitor.startTimer(COMPUTE_IF_ABSENT);
237 return updateAndGet(key, Match.ifNull(), Match.any(), mappingFunction.apply(key)) 237 return updateAndGet(key, Match.ifNull(), Match.any(), mappingFunction.apply(key))
238 - .whenComplete((r, e) -> timer.stop()) 238 + .whenComplete((r, e) -> timer.stop(e))
239 .thenApply(v -> v.newValue()); 239 .thenApply(v -> v.newValue());
240 } 240 }
241 241
...@@ -279,7 +279,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -279,7 +279,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
279 Match<V> valueMatcher = r1 == null ? Match.ifNull() : Match.any(); 279 Match<V> valueMatcher = r1 == null ? Match.ifNull() : Match.any();
280 Match<Long> versionMatcher = r1 == null ? Match.any() : Match.ifValue(r1.version()); 280 Match<Long> versionMatcher = r1 == null ? Match.any() : Match.ifValue(r1.version());
281 return updateAndGet(key, valueMatcher, versionMatcher, computedValue.get()) 281 return updateAndGet(key, valueMatcher, versionMatcher, computedValue.get())
282 - .whenComplete((r, e) -> timer.stop()) 282 + .whenComplete((r, e) -> timer.stop(e))
283 .thenApply(v -> { 283 .thenApply(v -> {
284 if (v.updated()) { 284 if (v.updated()) {
285 return v.newValue(); 285 return v.newValue();
...@@ -296,7 +296,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -296,7 +296,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
296 checkNotNull(value, ERROR_NULL_VALUE); 296 checkNotNull(value, ERROR_NULL_VALUE);
297 final MeteringAgent.Context timer = monitor.startTimer(PUT); 297 final MeteringAgent.Context timer = monitor.startTimer(PUT);
298 return updateAndGet(key, Match.any(), Match.any(), value).thenApply(v -> v.oldValue()) 298 return updateAndGet(key, Match.any(), Match.any(), value).thenApply(v -> v.oldValue())
299 - .whenComplete((r, e) -> timer.stop()); 299 + .whenComplete((r, e) -> timer.stop(e));
300 } 300 }
301 301
302 @Override 302 @Override
...@@ -305,7 +305,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -305,7 +305,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
305 checkNotNull(value, ERROR_NULL_VALUE); 305 checkNotNull(value, ERROR_NULL_VALUE);
306 final MeteringAgent.Context timer = monitor.startTimer(PUT_AND_GET); 306 final MeteringAgent.Context timer = monitor.startTimer(PUT_AND_GET);
307 return updateAndGet(key, Match.any(), Match.any(), value).thenApply(v -> v.newValue()) 307 return updateAndGet(key, Match.any(), Match.any(), value).thenApply(v -> v.newValue())
308 - .whenComplete((r, e) -> timer.stop()); 308 + .whenComplete((r, e) -> timer.stop(e));
309 } 309 }
310 310
311 @Override 311 @Override
...@@ -313,7 +313,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -313,7 +313,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
313 checkNotNull(key, ERROR_NULL_KEY); 313 checkNotNull(key, ERROR_NULL_KEY);
314 final MeteringAgent.Context timer = monitor.startTimer(REMOVE); 314 final MeteringAgent.Context timer = monitor.startTimer(REMOVE);
315 return updateAndGet(key, Match.any(), Match.any(), null).thenApply(v -> v.oldValue()) 315 return updateAndGet(key, Match.any(), Match.any(), null).thenApply(v -> v.oldValue())
316 - .whenComplete((r, e) -> timer.stop()); 316 + .whenComplete((r, e) -> timer.stop(e));
317 } 317 }
318 318
319 @Override 319 @Override
...@@ -321,7 +321,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -321,7 +321,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
321 checkIfUnmodifiable(); 321 checkIfUnmodifiable();
322 final MeteringAgent.Context timer = monitor.startTimer(CLEAR); 322 final MeteringAgent.Context timer = monitor.startTimer(CLEAR);
323 return database.mapClear(name).thenApply(this::unwrapResult) 323 return database.mapClear(name).thenApply(this::unwrapResult)
324 - .whenComplete((r, e) -> timer.stop()); 324 + .whenComplete((r, e) -> timer.stop(e));
325 } 325 }
326 326
327 @Override 327 @Override
...@@ -332,14 +332,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -332,14 +332,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
332 .stream() 332 .stream()
333 .map(this::dK) 333 .map(this::dK)
334 .collect(Collectors.toSet())) 334 .collect(Collectors.toSet()))
335 - .whenComplete((r, e) -> timer.stop()); 335 + .whenComplete((r, e) -> timer.stop(e));
336 } 336 }
337 337
338 @Override 338 @Override
339 public CompletableFuture<Collection<Versioned<V>>> values() { 339 public CompletableFuture<Collection<Versioned<V>>> values() {
340 final MeteringAgent.Context timer = monitor.startTimer(VALUES); 340 final MeteringAgent.Context timer = monitor.startTimer(VALUES);
341 return database.mapValues(name) 341 return database.mapValues(name)
342 - .whenComplete((r, e) -> timer.stop()) 342 + .whenComplete((r, e) -> timer.stop(e))
343 .thenApply(c -> c 343 .thenApply(c -> c
344 .stream() 344 .stream()
345 .map(v -> v.<V>map(serializer::decode)) 345 .map(v -> v.<V>map(serializer::decode))
...@@ -350,7 +350,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -350,7 +350,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
350 public CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet() { 350 public CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet() {
351 final MeteringAgent.Context timer = monitor.startTimer(ENTRY_SET); 351 final MeteringAgent.Context timer = monitor.startTimer(ENTRY_SET);
352 return database.mapEntrySet(name) 352 return database.mapEntrySet(name)
353 - .whenComplete((r, e) -> timer.stop()) 353 + .whenComplete((r, e) -> timer.stop(e))
354 .thenApply(s -> s 354 .thenApply(s -> s
355 .stream() 355 .stream()
356 .map(this::mapRawEntry) 356 .map(this::mapRawEntry)
...@@ -363,7 +363,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -363,7 +363,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
363 checkNotNull(value, ERROR_NULL_VALUE); 363 checkNotNull(value, ERROR_NULL_VALUE);
364 final MeteringAgent.Context timer = monitor.startTimer(PUT_IF_ABSENT); 364 final MeteringAgent.Context timer = monitor.startTimer(PUT_IF_ABSENT);
365 return updateAndGet(key, Match.ifNull(), Match.any(), value) 365 return updateAndGet(key, Match.ifNull(), Match.any(), value)
366 - .whenComplete((r, e) -> timer.stop()) 366 + .whenComplete((r, e) -> timer.stop(e))
367 .thenApply(v -> v.oldValue()); 367 .thenApply(v -> v.oldValue());
368 } 368 }
369 369
...@@ -373,7 +373,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -373,7 +373,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
373 checkNotNull(value, ERROR_NULL_VALUE); 373 checkNotNull(value, ERROR_NULL_VALUE);
374 final MeteringAgent.Context timer = monitor.startTimer(REMOVE); 374 final MeteringAgent.Context timer = monitor.startTimer(REMOVE);
375 return updateAndGet(key, Match.ifValue(value), Match.any(), null) 375 return updateAndGet(key, Match.ifValue(value), Match.any(), null)
376 - .whenComplete((r, e) -> timer.stop()) 376 + .whenComplete((r, e) -> timer.stop(e))
377 .thenApply(v -> v.updated()); 377 .thenApply(v -> v.updated());
378 } 378 }
379 379
...@@ -382,7 +382,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -382,7 +382,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
382 checkNotNull(key, ERROR_NULL_KEY); 382 checkNotNull(key, ERROR_NULL_KEY);
383 final MeteringAgent.Context timer = monitor.startTimer(REMOVE); 383 final MeteringAgent.Context timer = monitor.startTimer(REMOVE);
384 return updateAndGet(key, Match.any(), Match.ifValue(version), null) 384 return updateAndGet(key, Match.any(), Match.ifValue(version), null)
385 - .whenComplete((r, e) -> timer.stop()) 385 + .whenComplete((r, e) -> timer.stop(e))
386 .thenApply(v -> v.updated()); 386 .thenApply(v -> v.updated());
387 } 387 }
388 388
...@@ -393,7 +393,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -393,7 +393,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
393 checkNotNull(newValue, ERROR_NULL_VALUE); 393 checkNotNull(newValue, ERROR_NULL_VALUE);
394 final MeteringAgent.Context timer = monitor.startTimer(REPLACE); 394 final MeteringAgent.Context timer = monitor.startTimer(REPLACE);
395 return updateAndGet(key, Match.ifValue(oldValue), Match.any(), newValue) 395 return updateAndGet(key, Match.ifValue(oldValue), Match.any(), newValue)
396 - .whenComplete((r, e) -> timer.stop()) 396 + .whenComplete((r, e) -> timer.stop(e))
397 .thenApply(v -> v.updated()); 397 .thenApply(v -> v.updated());
398 } 398 }
399 399
...@@ -401,7 +401,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V ...@@ -401,7 +401,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V
401 public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) { 401 public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) {
402 final MeteringAgent.Context timer = monitor.startTimer(REPLACE); 402 final MeteringAgent.Context timer = monitor.startTimer(REPLACE);
403 return updateAndGet(key, Match.any(), Match.ifValue(oldVersion), newValue) 403 return updateAndGet(key, Match.any(), Match.ifValue(oldVersion), newValue)
404 - .whenComplete((r, e) -> timer.stop()) 404 + .whenComplete((r, e) -> timer.stop(e))
405 .thenApply(v -> v.updated()); 405 .thenApply(v -> v.updated());
406 } 406 }
407 407
......
...@@ -72,7 +72,7 @@ public class DefaultAtomicValue<V> implements AtomicValue<V> { ...@@ -72,7 +72,7 @@ public class DefaultAtomicValue<V> implements AtomicValue<V> {
72 return valueMap.replace(name, serializer.encode(expect), serializer.encode(update)); 72 return valueMap.replace(name, serializer.encode(expect), serializer.encode(update));
73 } 73 }
74 } finally { 74 } finally {
75 - newTimer.stop(); 75 + newTimer.stop(null);
76 } 76 }
77 } 77 }
78 78
...@@ -83,7 +83,7 @@ public class DefaultAtomicValue<V> implements AtomicValue<V> { ...@@ -83,7 +83,7 @@ public class DefaultAtomicValue<V> implements AtomicValue<V> {
83 Versioned<byte[]> rawValue = valueMap.get(name); 83 Versioned<byte[]> rawValue = valueMap.get(name);
84 return rawValue == null ? null : serializer.decode(rawValue.value()); 84 return rawValue == null ? null : serializer.decode(rawValue.value());
85 } finally { 85 } finally {
86 - newTimer.stop(); 86 + newTimer.stop(null);
87 } 87 }
88 } 88 }
89 89
...@@ -95,7 +95,7 @@ public class DefaultAtomicValue<V> implements AtomicValue<V> { ...@@ -95,7 +95,7 @@ public class DefaultAtomicValue<V> implements AtomicValue<V> {
95 valueMap.remove(name) : valueMap.put(name, serializer.encode(value)); 95 valueMap.remove(name) : valueMap.put(name, serializer.encode(value));
96 return previousValue == null ? null : serializer.decode(previousValue.value()); 96 return previousValue == null ? null : serializer.decode(previousValue.value());
97 } finally { 97 } finally {
98 - newTimer.stop(); 98 + newTimer.stop(null);
99 } 99 }
100 } 100 }
101 101
......
...@@ -73,7 +73,7 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> { ...@@ -73,7 +73,7 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> {
73 @Override 73 @Override
74 public long size() { 74 public long size() {
75 final MeteringAgent.Context timer = monitor.startTimer(SIZE); 75 final MeteringAgent.Context timer = monitor.startTimer(SIZE);
76 - return Futures.getUnchecked(database.queueSize(name).whenComplete((r, e) -> timer.stop())); 76 + return Futures.getUnchecked(database.queueSize(name).whenComplete((r, e) -> timer.stop(e)));
77 } 77 }
78 78
79 @Override 79 @Override
...@@ -81,14 +81,14 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> { ...@@ -81,14 +81,14 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> {
81 checkNotNull(entry, ERROR_NULL_ENTRY); 81 checkNotNull(entry, ERROR_NULL_ENTRY);
82 final MeteringAgent.Context timer = monitor.startTimer(PUSH); 82 final MeteringAgent.Context timer = monitor.startTimer(PUSH);
83 Futures.getUnchecked(database.queuePush(name, serializer.encode(entry)) 83 Futures.getUnchecked(database.queuePush(name, serializer.encode(entry))
84 - .whenComplete((r, e) -> timer.stop())); 84 + .whenComplete((r, e) -> timer.stop(e)));
85 } 85 }
86 86
87 @Override 87 @Override
88 public CompletableFuture<E> pop() { 88 public CompletableFuture<E> pop() {
89 final MeteringAgent.Context timer = monitor.startTimer(POP); 89 final MeteringAgent.Context timer = monitor.startTimer(POP);
90 return database.queuePop(name) 90 return database.queuePop(name)
91 - .whenComplete((r, e) -> timer.stop()) 91 + .whenComplete((r, e) -> timer.stop(e))
92 .thenCompose(v -> { 92 .thenCompose(v -> {
93 if (v != null) { 93 if (v != null) {
94 return CompletableFuture.completedFuture(serializer.decode(v)); 94 return CompletableFuture.completedFuture(serializer.decode(v));
...@@ -97,6 +97,7 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> { ...@@ -97,6 +97,7 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> {
97 pendingFutures.add(newPendingFuture); 97 pendingFutures.add(newPendingFuture);
98 return newPendingFuture; 98 return newPendingFuture;
99 }); 99 });
100 +
100 } 101 }
101 102
102 @Override 103 @Override
...@@ -104,7 +105,7 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> { ...@@ -104,7 +105,7 @@ public class DefaultDistributedQueue<E> implements DistributedQueue<E> {
104 final MeteringAgent.Context timer = monitor.startTimer(PEEK); 105 final MeteringAgent.Context timer = monitor.startTimer(PEEK);
105 return Futures.getUnchecked(database.queuePeek(name) 106 return Futures.getUnchecked(database.queuePeek(name)
106 .thenApply(v -> v != null ? serializer.<E>decode(v) : null) 107 .thenApply(v -> v != null ? serializer.<E>decode(v) : null)
107 - .whenComplete((r, e) -> timer.stop())); 108 + .whenComplete((r, e) -> timer.stop(e)));
108 } 109 }
109 110
110 public String name() { 111 public String name() {
......
...@@ -67,7 +67,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -67,7 +67,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
67 try { 67 try {
68 return backingMap.size(); 68 return backingMap.size();
69 } finally { 69 } finally {
70 - timer.stop(); 70 + timer.stop(null);
71 } 71 }
72 } 72 }
73 73
...@@ -77,7 +77,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -77,7 +77,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
77 try { 77 try {
78 return backingMap.isEmpty(); 78 return backingMap.isEmpty();
79 } finally { 79 } finally {
80 - timer.stop(); 80 + timer.stop(null);
81 } 81 }
82 } 82 }
83 83
...@@ -88,7 +88,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -88,7 +88,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
88 try { 88 try {
89 return backingMap.containsKey((E) o); 89 return backingMap.containsKey((E) o);
90 } finally { 90 } finally {
91 - timer.stop(); 91 + timer.stop(null);
92 } 92 }
93 } 93 }
94 94
...@@ -99,7 +99,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -99,7 +99,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
99 try { 99 try {
100 return backingMap.keySet().iterator(); 100 return backingMap.keySet().iterator();
101 } finally { 101 } finally {
102 - timer.stop(); 102 + timer.stop(null);
103 } 103 }
104 } 104 }
105 105
...@@ -109,7 +109,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -109,7 +109,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
109 try { 109 try {
110 return backingMap.keySet().stream().toArray(); 110 return backingMap.keySet().stream().toArray();
111 } finally { 111 } finally {
112 - timer.stop(); 112 + timer.stop(null);
113 } 113 }
114 } 114 }
115 115
...@@ -119,7 +119,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -119,7 +119,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
119 try { 119 try {
120 return backingMap.keySet().stream().toArray(size -> a); 120 return backingMap.keySet().stream().toArray(size -> a);
121 } finally { 121 } finally {
122 - timer.stop(); 122 + timer.stop(null);
123 } 123 }
124 } 124 }
125 125
...@@ -129,7 +129,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -129,7 +129,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
129 try { 129 try {
130 return backingMap.putIfAbsent(e, true) == null; 130 return backingMap.putIfAbsent(e, true) == null;
131 } finally { 131 } finally {
132 - timer.stop(); 132 + timer.stop(null);
133 } 133 }
134 } 134 }
135 135
...@@ -140,7 +140,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -140,7 +140,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
140 try { 140 try {
141 return backingMap.remove((E) o) != null; 141 return backingMap.remove((E) o) != null;
142 } finally { 142 } finally {
143 - timer.stop(); 143 + timer.stop(null);
144 } 144 }
145 } 145 }
146 146
...@@ -151,7 +151,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -151,7 +151,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
151 return c.stream() 151 return c.stream()
152 .allMatch(this::contains); 152 .allMatch(this::contains);
153 } finally { 153 } finally {
154 - timer.stop(); 154 + timer.stop(null);
155 } 155 }
156 } 156 }
157 157
...@@ -164,7 +164,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -164,7 +164,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
164 .reduce(Boolean::logicalOr) 164 .reduce(Boolean::logicalOr)
165 .orElse(false); 165 .orElse(false);
166 } finally { 166 } finally {
167 - timer.stop(); 167 + timer.stop(null);
168 } 168 }
169 } 169 }
170 170
...@@ -180,7 +180,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -180,7 +180,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
180 .reduce(Boolean::logicalOr) 180 .reduce(Boolean::logicalOr)
181 .orElse(false); 181 .orElse(false);
182 } finally { 182 } finally {
183 - timer.stop(); 183 + timer.stop(null);
184 } 184 }
185 } 185 }
186 186
...@@ -196,7 +196,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -196,7 +196,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
196 .reduce(Boolean::logicalOr) 196 .reduce(Boolean::logicalOr)
197 .orElse(false); 197 .orElse(false);
198 } finally { 198 } finally {
199 - timer.stop(); 199 + timer.stop(null);
200 } 200 }
201 } 201 }
202 202
...@@ -206,7 +206,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> { ...@@ -206,7 +206,7 @@ public class DefaultDistributedSet<E> implements DistributedSet<E> {
206 try { 206 try {
207 backingMap.clear(); 207 backingMap.clear();
208 } finally { 208 } finally {
209 - timer.stop(); 209 + timer.stop(null);
210 } 210 }
211 } 211 }
212 212
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.store.consistent.impl; 16 package org.onosproject.store.consistent.impl;
17 17
18 +import com.codahale.metrics.Counter;
18 import com.codahale.metrics.Timer; 19 import com.codahale.metrics.Timer;
19 import com.google.common.collect.Maps; 20 import com.google.common.collect.Maps;
20 import org.onlab.metrics.MetricsComponent; 21 import org.onlab.metrics.MetricsComponent;
...@@ -32,6 +33,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -32,6 +33,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
32 */ 33 */
33 public class MeteringAgent { 34 public class MeteringAgent {
34 35
36 + private Counter exceptionCounter;
37 + private Counter perObjExceptionCounter;
35 private MetricsService metricsService; 38 private MetricsService metricsService;
36 private MetricsComponent metricsComponent; 39 private MetricsComponent metricsComponent;
37 private MetricsFeature metricsFeature; 40 private MetricsFeature metricsFeature;
...@@ -63,6 +66,8 @@ public class MeteringAgent { ...@@ -63,6 +66,8 @@ public class MeteringAgent {
63 this.wildcard = metricsComponent.registerFeature("*"); 66 this.wildcard = metricsComponent.registerFeature("*");
64 this.perObjTimer = metricsService.createTimer(metricsComponent, metricsFeature, "*"); 67 this.perObjTimer = metricsService.createTimer(metricsComponent, metricsFeature, "*");
65 this.perPrimitiveTimer = metricsService.createTimer(metricsComponent, wildcard, "*"); 68 this.perPrimitiveTimer = metricsService.createTimer(metricsComponent, wildcard, "*");
69 + this.perObjExceptionCounter = metricsService.createCounter(metricsComponent, metricsFeature, "exceptions");
70 + this.exceptionCounter = metricsService.createCounter(metricsComponent, wildcard, "exceptions");
66 } 71 }
67 } 72 }
68 73
...@@ -103,11 +108,13 @@ public class MeteringAgent { ...@@ -103,11 +108,13 @@ public class MeteringAgent {
103 108
104 /** 109 /**
105 * Stops timer given a specific context and updates all related metrics. 110 * Stops timer given a specific context and updates all related metrics.
111 + * @param e
106 */ 112 */
107 - public void stop() { 113 + public void stop(Throwable e) {
108 if (!activated) { 114 if (!activated) {
109 return; 115 return;
110 } 116 }
117 + if (e == null) {
111 //Stop and updates timer with specific measurements per map, per operation 118 //Stop and updates timer with specific measurements per map, per operation
112 final long time = context.stop(); 119 final long time = context.stop();
113 //updates timer with aggregated measurements per map 120 //updates timer with aggregated measurements per map
...@@ -116,6 +123,10 @@ public class MeteringAgent { ...@@ -116,6 +123,10 @@ public class MeteringAgent {
116 perObjTimer.update(time, TimeUnit.NANOSECONDS); 123 perObjTimer.update(time, TimeUnit.NANOSECONDS);
117 //updates timer with aggregated measurements per all Consistent Maps 124 //updates timer with aggregated measurements per all Consistent Maps
118 perPrimitiveTimer.update(time, TimeUnit.NANOSECONDS); 125 perPrimitiveTimer.update(time, TimeUnit.NANOSECONDS);
126 + } else {
127 + exceptionCounter.inc();
128 + perObjExceptionCounter.inc();
129 + }
119 } 130 }
120 } 131 }
121 132
......