11package org .fluentd .logger .sender ;
22
3- import org .slf4j .Logger ;
4- import org .slf4j .LoggerFactory ;
5-
63import java .util .LinkedList ;
74
85/**
96 * Calcurate exponential delay for reconnecting
107 */
118public class ExponentialDelayReconnector implements Reconnector {
129
13- private double wait = 0.5 ;
10+ private double waitMillis = 50 ; // Start wait is 50ms
1411
1512 private double waitIncrRate = 1.5 ;
1613
17- private double waitMax = 60 ;
14+ private double waitMaxMillis = 60 * 1000 ; // Max wait is 1 minute
1815
1916 private int waitMaxCount ;
2017
@@ -26,7 +23,7 @@ public ExponentialDelayReconnector() {
2623 }
2724
2825 private int getWaitMaxCount () {
29- double r = waitMax / wait ;
26+ double r = waitMaxMillis / waitMillis ;
3027 for (int j = 1 ; j <= 100 ; j ++) {
3128 if (r < waitIncrRate ) {
3229 return j + 1 ;
@@ -57,13 +54,13 @@ public boolean enableReconnection(long timestamp) {
5754 return true ;
5855 }
5956
60- double suppressSec ;
57+ double suppressMillis ;
6158 if (size < waitMaxCount ) {
62- suppressSec = wait * Math .pow (waitIncrRate , size - 1 );
59+ suppressMillis = waitMillis * Math .pow (waitIncrRate , size - 1 );
6360 } else {
64- suppressSec = waitMax ;
61+ suppressMillis = waitMaxMillis ;
6562 }
6663
67- return (!( timestamp - errorHistory .getLast () < suppressSec )) ;
64+ return (timestamp - errorHistory .getLast ()) > suppressMillis ;
6865 }
6966}
0 commit comments