Skip to content

Commit

Permalink
review: renamed atomicboolean + reset it to "false" when connection w…
Browse files Browse the repository at this point in the history
…as (re-)established

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Jun 10, 2021
1 parent 3062cf0 commit cb788d2
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -35,6 +35,9 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import org.eclipse.ditto.base.model.acks.AcknowledgementLabel;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
import org.eclipse.ditto.client.configuration.AuthenticationConfiguration;
import org.eclipse.ditto.client.configuration.MessagingConfiguration;
import org.eclipse.ditto.client.internal.DefaultThreadFactory;
Expand All @@ -47,9 +50,6 @@
import org.eclipse.ditto.client.messaging.MessagingProvider;
import org.eclipse.ditto.json.JsonCollectors;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.base.model.acks.AcknowledgementLabel;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -86,7 +86,7 @@ public final class WebSocketMessagingProvider extends WebSocketAdapter implement
private final Map<Object, String> subscriptionMessages;
private final AtomicBoolean reconnecting = new AtomicBoolean(false);
private final AtomicBoolean initializing = new AtomicBoolean(false);
private final AtomicBoolean websocketClosed = new AtomicBoolean(false);
private final AtomicBoolean explicitlyClosing = new AtomicBoolean(false);
private final CompletableFuture<WebSocket> initializationFuture = new CompletableFuture<>();

private final AtomicReference<WebSocket> webSocket;
Expand Down Expand Up @@ -271,7 +271,7 @@ public void close() {
connectExecutor.shutdownNow();
authenticationProvider.destroy();
adaptableBus.shutdownExecutor();
websocketClosed.getAndSet(true);
explicitlyClosing.set(true);
final WebSocket ws = webSocket.get();
if (ws != null) {
ws.disconnect();
Expand Down Expand Up @@ -312,7 +312,7 @@ public void onDisconnected(final WebSocket websocket, final WebSocketFrame serve
serverCloseFrame.getCloseCode(),
serverCloseFrame.getCloseReason());
handleReconnectionIfEnabled();
} else if (!websocketClosed.get()) {
} else if (!explicitlyClosing.get()) {
// client closed connection because of a connection interruption or something similar
LOGGER.info("Client <{}>: WebSocket connection to endpoint <{}> was unintentionally closed by client " +
"- client will try to reconnect if enabled!",
Expand Down Expand Up @@ -389,6 +389,7 @@ private void reconnectWithRetries() {
}

private void setWebSocket(final WebSocket webSocket) {
explicitlyClosing.set(false); // reset potential explicit close request by the user
synchronized (this.webSocket) {
final WebSocket oldWebSocket = this.webSocket.get();
this.webSocket.set(webSocket);
Expand Down

0 comments on commit cb788d2

Please sign in to comment.