org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluency Show documentation
Show all versions of fluency Show documentation
Yet another fluent logger
package org.komamitsu.fluency.sender.retry;
public class ExponentialBackOffRetryStrategy
extends RetryStrategy
{
private ExponentialBackOffRetryStrategy(Config config)
{
super(config);
}
@Override
public long getNextIntervalMillis(int retryCount)
{
long interval = config.getBaseIntervalMillis() * ((int) Math.pow(2.0, (double) retryCount));
if (interval > config.getMaxIntervalMillis()) {
return config.getMaxIntervalMillis();
}
return interval;
}
public static class Config extends RetryStrategy.Config
{
private long baseIntervalMillis = 400;
private long maxIntervalMillis = 30 * 1000;
public long getBaseIntervalMillis()
{
return baseIntervalMillis;
}
public Config setBaseIntervalMillis(long baseIntervalMillis)
{
this.baseIntervalMillis = baseIntervalMillis;
return this;
}
public long getMaxIntervalMillis()
{
return maxIntervalMillis;
}
public Config setMaxIntervalMillis(long maxIntervalMillis)
{
this.maxIntervalMillis = maxIntervalMillis;
return this;
}
@Override
public ExponentialBackOffRetryStrategy createInstance()
{
return new ExponentialBackOffRetryStrategy(this);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy