Compare commits
2 commits
80f33b6dbc
...
ab51cfb0c5
Author | SHA1 | Date | |
---|---|---|---|
ab51cfb0c5 | |||
55eb8bb081 |
2 changed files with 11 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
||||||
package de.hhhammer.dchat.discord.ws.connection;
|
package de.hhhammer.dchat.discord.ws.connection;
|
||||||
|
|
||||||
import de.hhhammer.dchat.discord.ws.Retryer;
|
import de.hhhammer.dchat.discord.ws.Retryer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
@ -8,8 +10,7 @@ import java.util.Timer;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public final class BackoffRetryer implements Retryer {
|
public final class BackoffRetryer implements Retryer {
|
||||||
private static final int delayInSeconds = 10;
|
private static final Logger logger = LoggerFactory.getLogger(BackoffRetryer.class);
|
||||||
private static final int backoffMultiplier = 2;
|
|
||||||
private final AtomicInteger tries = new AtomicInteger();
|
private final AtomicInteger tries = new AtomicInteger();
|
||||||
private final int maxRetries;
|
private final int maxRetries;
|
||||||
private LocalTime lastRetry = null;
|
private LocalTime lastRetry = null;
|
||||||
|
@ -24,8 +25,14 @@ public final class BackoffRetryer implements Retryer {
|
||||||
|
|
||||||
public int nextRetryInSeconds() {
|
public int nextRetryInSeconds() {
|
||||||
// reset retry on successful connection for more than 5 minutes.
|
// reset retry on successful connection for more than 5 minutes.
|
||||||
if (lastRetry != null && LocalTime.now().minusMinutes(lastRetry.getMinute()).getMinute() > 5) tries.set(0);
|
final int successfulTimeInMinute = 5;
|
||||||
|
if (lastRetry != null && LocalTime.now().minusMinutes(lastRetry.getMinute()).getMinute() > successfulTimeInMinute) {
|
||||||
|
logger.info("Resetting retry backoff: connection was successful for more than {} minutes", successfulTimeInMinute);
|
||||||
|
tries.set(0);
|
||||||
|
}
|
||||||
final int currentTry = tries.getAndIncrement();
|
final int currentTry = tries.getAndIncrement();
|
||||||
|
final int delayInSeconds = 10;
|
||||||
|
final int backoffMultiplier = 2;
|
||||||
int seconds = delayInSeconds;
|
int seconds = delayInSeconds;
|
||||||
for (int i = 0; i < currentTry; i++) {
|
for (int i = 0; i < currentTry; i++) {
|
||||||
seconds = seconds * backoffMultiplier;
|
seconds = seconds * backoffMultiplier;
|
||||||
|
|
|
@ -5,7 +5,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public final class ResumeConnector {
|
public final class ResumeConnector {
|
||||||
private static Logger logger = LoggerFactory.getLogger(ResumeConnector.class);
|
private static final Logger logger = LoggerFactory.getLogger(ResumeConnector.class);
|
||||||
private final String initGatewayUrl;
|
private final String initGatewayUrl;
|
||||||
private final String token;
|
private final String token;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue