aboutsummaryrefslogtreecommitdiffstats
path: root/fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java
diff options
context:
space:
mode:
Diffstat (limited to 'fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java')
-rw-r--r--fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java b/fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java
index b1ef519d901..e8c08edb621 100644
--- a/fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java
+++ b/fileacquirer/src/main/java/com/yahoo/filedistribution/fileacquirer/Timer.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.filedistribution.fileacquirer;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
/**
@@ -10,16 +11,16 @@ import java.util.concurrent.TimeUnit;
class Timer {
private final long endTime;
- private long timeLeft() {
- return endTime - System.currentTimeMillis();
+ private Duration timeLeft() {
+ return Duration.ofNanos(endTime - System.nanoTime());
}
public Timer(long timeout, TimeUnit timeUnit) {
- endTime = System.currentTimeMillis() + timeUnit.toMillis(timeout);
+ endTime = System.nanoTime() + timeUnit.toNanos(timeout);
}
public long timeLeft(TimeUnit timeUnit) {
- long remaining = timeUnit.convert(timeLeft(), TimeUnit.MILLISECONDS);
+ long remaining = timeUnit.convert(timeLeft().toMillis(), TimeUnit.MILLISECONDS);
if (remaining > 0)
return remaining;
@@ -28,6 +29,6 @@ class Timer {
}
public boolean isTimeLeft() {
- return timeLeft() > 0;
+ return ! timeLeft().isNegative();
}
}