summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2022-04-28 22:12:00 +0200
committerjonmv <venstad@gmail.com>2022-04-28 22:12:00 +0200
commite8e9cd5d722af2efa5489b9eb4a17aa4b58303a4 (patch)
tree6ef39c96a22b23d20d5f381e0cacfb57cfbb8ad3 /vespajlib
parent3af9c40612e539660c9a831520066420eb9f88ab (diff)
Replace Jersey in orchestrator with apache, remove jaxrx_client_utils
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/time/TimeBudget.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java
index 64cf9dd522c..7e6c015bca8 100644
--- a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java
+++ b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java
@@ -60,7 +60,7 @@ public class TimeBudget {
Duration passed = timePassed();
Duration left = timeout.minus(passed);
if (left.toMillis() <= 0) {
- throw new UncheckedTimeoutException("Time since start " + passed + " exceeds timeout " + this.timeout);
+ throw new UncheckedTimeoutException("Time since start " + passed + " exceeds timeout " + timeout);
}
return left;
@@ -75,8 +75,7 @@ public class TimeBudget {
/** Returns the time left as a new TimeBudget. */
public TimeBudget timeLeftAsTimeBudget() {
Instant now = clock.instant();
- Optional<Instant> deadline = deadline();
- return new TimeBudget(clock, now, deadline.map(d -> Duration.between(now, d)));
+ return new TimeBudget(clock, now, deadline().map(d -> Duration.between(now, d)));
}
/** Returns a new TimeBudget with the same clock and start, but with this deadline. */
@@ -84,6 +83,11 @@ public class TimeBudget {
return new TimeBudget(clock, start, Optional.of(Duration.between(start, deadline)));
}
+ /** Returns a new TimeBudget with the given duration chopped off, reserved for something else. */
+ public TimeBudget withReserved(Duration chunk) {
+ return timeout.isEmpty() ? this : new TimeBudget(clock, start, Optional.of(timeout.get().minus(chunk)));
+ }
+
private static Duration nonNegativeBetween(Instant start, Instant end) {
return makeNonNegative(Duration.between(start, end));
}