Skip to content

Commit bb084c3

Browse files
committed
Updating HttpRequestService
1 parent 815b7c5 commit bb084c3

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/connectivity/http/OkHttpSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.jetbrains.annotations.NotNull;
1313
import org.jetbrains.annotations.Nullable;
1414

15-
public class OkHttpSender implements HttpSender {
15+
public final class OkHttpSender implements HttpSender {
1616
private final OkHttpClient client;
1717
private final String url;
1818

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/request/service/HttpRequestService.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ public final class HttpRequestService implements RequestService, Runnable {
2626
private final PeriodicTaskExecutor executor;
2727
private final PeriodicDelay periodicRequestDelay;
2828
private final PeriodicDelay periodicRetryDelay;
29-
private final Object runningLock = new Object();
3029
private final AtomicBoolean retryModeEnabled = new AtomicBoolean(false);
30+
private final AtomicBoolean isRunning = new AtomicBoolean(false);
3131
@Nullable private Callback callback;
3232
@Nullable private Supplier<Request> requestSupplier;
33-
private boolean isRunning = false;
34-
private boolean isStopped = false;
3533
public static final PeriodicDelay DEFAULT_DELAY_BETWEEN_REQUESTS =
3634
PeriodicDelay.ofFixedDuration(Duration.ofSeconds(30));
3735

@@ -75,27 +73,18 @@ public static HttpRequestService create(
7573

7674
@Override
7775
public void start(Callback callback, Supplier<Request> requestSupplier) {
78-
synchronized (runningLock) {
79-
if (isStopped) {
80-
throw new IllegalStateException("RequestDispatcher has been stopped");
81-
}
82-
if (isRunning) {
83-
throw new IllegalStateException("RequestDispatcher is already running");
84-
}
76+
if (isRunning.compareAndSet(false, true)) {
8577
this.callback = callback;
8678
this.requestSupplier = requestSupplier;
8779
executor.start(this);
88-
isRunning = true;
80+
} else {
81+
throw new IllegalStateException("RequestDispatcher is already running");
8982
}
9083
}
9184

9285
@Override
9386
public void stop() {
94-
synchronized (runningLock) {
95-
if (!isRunning || isStopped) {
96-
return;
97-
}
98-
isStopped = true;
87+
if (isRunning.compareAndSet(true, false)) {
9988
executor.executeNow();
10089
executor.stop();
10190
}
@@ -165,7 +154,7 @@ private void handleHttpError(HttpSender.Response response) {
165154
String retryAfterHeader = response.getHeader("Retry-After");
166155
Duration retryAfter = null;
167156
if (retryAfterHeader != null) {
168-
// retryAfter = TODO parse header to duration
157+
retryAfter = Duration.ofSeconds(Long.parseLong(retryAfterHeader));
169158
}
170159
enableRetryMode(retryAfter);
171160
}

0 commit comments

Comments
 (0)