1 package com.atlassian.plugin.instrumentation;
2
3 import com.atlassian.instrumentation.operations.OpTimer;
4
5 import javax.annotation.Nonnull;
6 import java.io.Closeable;
7 import java.util.Optional;
8
9 import static com.google.common.base.Preconditions.checkNotNull;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class Timer implements Closeable {
23 private final Optional<OpTimer> opTimer;
24
25 Timer(@Nonnull Optional<OpTimer> opTimer) {
26 this.opTimer = checkNotNull(opTimer);
27 }
28
29
30
31
32 public Optional<OpTimer> getOpTimer() {
33 return opTimer;
34 }
35
36
37
38
39 @Override
40 public void close() {
41 if (opTimer.isPresent()) {
42 opTimer.get().end();
43 }
44 }
45 }