Skip to content

Commit 68ff698

Browse files
committed
Update SSEClient to not use synchronized
1 parent 9a58002 commit 68ff698

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

client/src/main/java/io/split/engine/sse/client/SSEClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ private enum ConnectionState {
5959
private final AtomicReference<HttpGet> _ongoingRequest = new AtomicReference<>();
6060
private AtomicBoolean _forcedStop;
6161
private final RequestDecorator _requestDecorator;
62-
6362
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;
63+
private final AtomicBoolean openGuard = new AtomicBoolean(false);
6464

6565
public SSEClient(Function<RawEvent, Void> eventCallback,
6666
Function<StatusMessage, Void> statusCallback,
@@ -77,12 +77,17 @@ public SSEClient(Function<RawEvent, Void> eventCallback,
7777
_requestDecorator = requestDecorator;
7878
}
7979

80-
public synchronized boolean open(URI uri) {
80+
public boolean open(URI uri) {
8181
if (isOpen()) {
8282
_log.info("SSEClient already open.");
8383
return false;
8484
}
8585

86+
if (!openGuard.compareAndSet(false, true)) {
87+
_log.debug("Open SSEClient already running");
88+
return false;
89+
}
90+
8691
_statusCallback.apply(StatusMessage.INITIALIZATION_IN_PROGRESS);
8792

8893
CountDownLatch signal = new CountDownLatch(1);
@@ -99,6 +104,8 @@ public synchronized boolean open(URI uri) {
99104
}
100105
_log.info(e.getMessage());
101106
return false;
107+
} finally {
108+
openGuard.set(false);
102109
}
103110
return isOpen();
104111
}

0 commit comments

Comments
 (0)