You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by mi...@apache.org on 2019/12/15 10:50:00 UTC

[httpcomponents-client] 09/12: ExponentialBackOffSchedulingStrategy should use TimeValue internally

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch consistency
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 83bc2c497dad58963c322b3a0b809f651a11a176
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Dec 15 11:00:46 2019 +0100

    ExponentialBackOffSchedulingStrategy should use TimeValue internally
---
 .../http/impl/schedule/ExponentialBackOffSchedulingStrategy.java  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/schedule/ExponentialBackOffSchedulingStrategy.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/schedule/ExponentialBackOffSchedulingStrategy.java
index a9a808c..af70789 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/schedule/ExponentialBackOffSchedulingStrategy.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/schedule/ExponentialBackOffSchedulingStrategy.java
@@ -91,7 +91,7 @@ public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy
 
     @Override
     public TimeValue schedule(final int attemptNumber) {
-        return TimeValue.ofMilliseconds(calculateDelayInMillis(attemptNumber));
+        return calculateDelay(attemptNumber);
     }
 
     public long getBackOffRate() {
@@ -106,12 +106,12 @@ public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy
         return maxExpiry;
     }
 
-    protected long calculateDelayInMillis(final int consecutiveFailedAttempts) {
+    protected TimeValue calculateDelay(final int consecutiveFailedAttempts) {
         if (consecutiveFailedAttempts > 0) {
             final long delay = (long) (initialExpiry.toMillis() * Math.pow(backOffRate, consecutiveFailedAttempts - 1));
-            return Math.min(delay, maxExpiry.toMillis());
+            return TimeValue.ofMilliseconds(Math.min(delay, maxExpiry.toMillis()));
         }
-        return 0;
+        return TimeValue.ZERO_MILLISECONDS;
     }
 
 }