From 5229906f6980c9ab36daa30fc5a305db0301f171 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 4 May 2022 08:31:24 +0200 Subject: [PATCH] SEBSERV-303 fixed by taking samples first value then current-time --- .../impl/indicator/PingIntervalClientIndicator.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java index e7b1c76b..4461963a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/PingIntervalClientIndicator.java @@ -76,19 +76,18 @@ public final class PingIntervalClientIndicator extends AbstractPingIndicator { return Double.NaN; } + // take samples, current value before current time to prevent negative ping times + final double value = this.currentValue; + final long currentTimeMillis = DateTimeUtils.currentTimeMillis(); + if (this.initialized && !this.cachingEnabled && this.active && this.lastUpdate != this.distributedIndicatorValueService.lastUpdate()) { - final long currentTimeMillis = DateTimeUtils.currentTimeMillis(); this.currentValue = computeValueAt(currentTimeMillis); this.lastUpdate = this.distributedIndicatorValueService.lastUpdate(); - return (currentTimeMillis < this.currentValue) - ? DateTimeUtils.currentTimeMillis() - this.currentValue - : currentTimeMillis - this.currentValue; - - } else { - return DateTimeUtils.currentTimeMillis() - this.currentValue; } + + return currentTimeMillis - value; } @Override