Skip to content

Commit

Permalink
do not log an error when disconnect is expected
Browse files Browse the repository at this point in the history
  • Loading branch information
philipparndt committed Dec 12, 2021
1 parent 4ee105d commit 48ef5fb
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class GwMqttClient {

private final MessageDeduplication deduplication;
private final AtomicBoolean connected = new AtomicBoolean(false);
private final AtomicBoolean expectDisconnect = new AtomicBoolean(false);

private GwMqttClient(final ConfigMqtt config) throws URISyntaxException {
this.config = config;
Expand Down Expand Up @@ -81,7 +82,9 @@ private void onConnected(final MqttClientConnectedContext context) {
}

private void onDisconnected(final MqttClientDisconnectedContext context) {
logger.error("MQTT client disconnected: {}", context.getCause().getMessage(), context.getCause());
if (!expectDisconnect.get()) {
logger.error("MQTT client disconnected: {}", context.getCause().getMessage(), context.getCause());
}
this.connected.set(false);
}

Expand All @@ -92,6 +95,7 @@ private void onMessage(final Mqtt3Publish message) {

private Mqtt3AsyncClient connect() throws URISyntaxException {
logger.info("Connecting MQTT client");
expectDisconnect.set(false);

final URI uri = new URI(this.config.getUrl());

Expand Down Expand Up @@ -217,6 +221,7 @@ public GwMqttClient online() {
}

public void shutdown() {
expectDisconnect.set(true);
onBridgInfo(BridgeInfo.OFFLINE);
this.client.disconnect();
}
Expand Down

0 comments on commit 48ef5fb

Please sign in to comment.