11package org .fluentd .logger .sender ;
22
3- import org .slf4j .Logger ;
4- import org .slf4j .LoggerFactory ;
5-
63import java .util .LinkedList ;
74
85/**
9- * Calcurate exponential delay for reconnecting
6+ * Calculates exponential delay for reconnecting. The start delay is 50ms and exponentially grows to max 60 seconds in
7+ * function of the number of connection errors.
108 */
119public class ExponentialDelayReconnector implements Reconnector {
1210
13- private double wait = 0.5 ;
11+ private double waitMillis = 50 ; // Start wait is 50ms
1412
1513 private double waitIncrRate = 1.5 ;
1614
17- private double waitMax = 60 ;
15+ private double waitMaxMillis = 60 * 1000 ; // Max wait is 1 minute
1816
1917 private int waitMaxCount ;
2018
@@ -26,7 +24,7 @@ public ExponentialDelayReconnector() {
2624 }
2725
2826 private int getWaitMaxCount () {
29- double r = waitMax / wait ;
27+ double r = waitMaxMillis / waitMillis ;
3028 for (int j = 1 ; j <= 100 ; j ++) {
3129 if (r < waitIncrRate ) {
3230 return j + 1 ;
@@ -57,13 +55,13 @@ public boolean enableReconnection(long timestamp) {
5755 return true ;
5856 }
5957
60- double suppressSec ;
58+ double suppressMillis ;
6159 if (size < waitMaxCount ) {
62- suppressSec = wait * Math .pow (waitIncrRate , size - 1 );
60+ suppressMillis = waitMillis * Math .pow (waitIncrRate , size - 1 );
6361 } else {
64- suppressSec = waitMax ;
62+ suppressMillis = waitMaxMillis ;
6563 }
6664
67- return (!( timestamp - errorHistory .getLast () < suppressSec )) ;
65+ return (timestamp - errorHistory .getLast ()) >= suppressMillis ;
6866 }
6967}
0 commit comments