Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>23</release>
<compilerArgs>
--add-modules=jdk.incubator.vector
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<argLine>
--add-modules=jdk.incubator.vector
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
184 changes: 0 additions & 184 deletions src/main/java/RetryExecutor.java

This file was deleted.

41 changes: 41 additions & 0 deletions src/main/java/org/fungover/breeze/client/ServerClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.fungover.breeze.client;

import org.fungover.breeze.control.RetryExecutor;
import org.fungover.breeze.control.ServerBusyException;

import java.security.SecureRandom;
import java.util.Objects;
import java.util.Random;

public class ServerClient {
private static final double DEFAULT_BUSY_PROBABILITY = 0.7;
private final double busyProbability;
private final Random random;

public ServerClient() {
this(DEFAULT_BUSY_PROBABILITY, new SecureRandom());
}

public ServerClient(double busyProbability, Random random) {
if (busyProbability < 0 || busyProbability > 1) {
throw new IllegalArgumentException("Probability must be between 0 and 1");
}
this.busyProbability = busyProbability;
this.random = Objects.requireNonNull(random, "Random instance cannot be null");
}

public String fetchData() throws Exception {
return RetryExecutor.executeWithRetry(this::attemptFetchData);
}

String attemptFetchData() throws ServerBusyException {
if (shouldSimulateBusyServer()) {
throw new ServerBusyException();
}
return "Sample Data";
}

private boolean shouldSimulateBusyServer() {
return random.nextDouble() < busyProbability;
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/fungover/breeze/control/RetryConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.fungover.breeze.control;

public final class RetryConfig {
public static final int DEFAULT_MAX_ATTEMPTS = 5;
public static final long DEFAULT_INITIAL_DELAY = 1000;
public static final long DEFAULT_MAX_DELAY = 16000;

private RetryConfig() {
throw new AssertionError("Utility class cannot be instantiated");
}
}
Loading