Compare commits

..

2 commits

Author SHA1 Message Date
ab51cfb0c5 discrod-ws: Improve BackoffRetryer
All checks were successful
ci/woodpecker/push/java Pipeline was successful
ci/woodpecker/push/oci-image-build Pipeline was successful
Move static fields into usage since they wher only used once.
Add logging on retry reset.
2024-12-04 20:24:26 +01:00
55eb8bb081 discord-ws: Fix missing final 2024-12-04 20:19:29 +01:00
2 changed files with 11 additions and 4 deletions

View file

@ -1,6 +1,8 @@
package de.hhhammer.dchat.discord.ws.connection;
import de.hhhammer.dchat.discord.ws.Retryer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.time.LocalTime;
@ -8,8 +10,7 @@ import java.util.Timer;
import java.util.concurrent.atomic.AtomicInteger;
public final class BackoffRetryer implements Retryer {
private static final int delayInSeconds = 10;
private static final int backoffMultiplier = 2;
private static final Logger logger = LoggerFactory.getLogger(BackoffRetryer.class);
private final AtomicInteger tries = new AtomicInteger();
private final int maxRetries;
private LocalTime lastRetry = null;
@ -24,8 +25,14 @@ public final class BackoffRetryer implements Retryer {
public int nextRetryInSeconds() {
// 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 delayInSeconds = 10;
final int backoffMultiplier = 2;
int seconds = delayInSeconds;
for (int i = 0; i < currentTry; i++) {
seconds = seconds * backoffMultiplier;

View file

@ -5,7 +5,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 token;