summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/concurrent/Timer.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/concurrent/Timer.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/concurrent/Timer.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/Timer.java b/vespajlib/src/main/java/com/yahoo/concurrent/Timer.java
index 1793e860af8..282524c0d54 100644
--- a/vespajlib/src/main/java/com/yahoo/concurrent/Timer.java
+++ b/vespajlib/src/main/java/com/yahoo/concurrent/Timer.java
@@ -1,6 +1,9 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.concurrent;
+import java.time.Clock;
+import java.util.concurrent.TimeUnit;
+
/**
* This interface wraps access to some timer that can be used to measure elapsed time, in milliseconds. This
* abstraction allows for unit testing the behavior of time-based constructs.
@@ -16,5 +19,14 @@ public interface Timer {
* @return The current value of the timer, in milliseconds.
*/
long milliTime();
+ Timer monotonic = () -> TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
+ static Timer wrap(Clock original) {
+ return new Timer() {
+ private final Clock clock = original;
+ @Override
+ public long milliTime() {
+ return clock.millis();
+ }
+ }; }
}