summaryrefslogtreecommitdiffstats
path: root/jrt/src/com/yahoo/jrt/slobrok/api/BackOff.java
blob: d8a6718b40796345b2df68b67e8127f14308124e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt.slobrok.api;


class BackOff implements BackOffPolicy
{
    private double time = 0.50;

    public void reset() {
        time = 0.50;
    }

    public double get() {
        double ret = time;
        if (time < 5.0) {
            time += 0.5;
        } else if (time < 10.0) {
            time += 1.0;
        } else if (time < 30.0) {
            time += 5;
        } else {
            // max retry time is 30 seconds
        }
        return ret;
    }

    public boolean shouldWarn(double t) {
        return ((t > 8.1 && t < 9.9) || (t > 29.9));
    }
}