[mqtt] connectionStateChanged(CONNECTED) called twice (#12200)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>pull/12207/head
parent
97db73938d
commit
73b805b115
|
@ -114,8 +114,6 @@ public abstract class AbstractBrokerHandler extends BaseBridgeHandler implements
|
||||||
}).thenAccept(v -> {
|
}).thenAccept(v -> {
|
||||||
if (!v) {
|
if (!v) {
|
||||||
connectionStateChanged(MqttConnectionState.DISCONNECTED, new TimeoutException("Timeout"));
|
connectionStateChanged(MqttConnectionState.DISCONNECTED, new TimeoutException("Timeout"));
|
||||||
} else {
|
|
||||||
connectionStateChanged(MqttConnectionState.CONNECTED, null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connectionFuture.complete(connection);
|
connectionFuture.complete(connection);
|
||||||
|
|
|
@ -59,19 +59,18 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
|
||||||
@Override
|
@Override
|
||||||
public void connectionStateChanged(MqttConnectionState state, @Nullable Throwable error) {
|
public void connectionStateChanged(MqttConnectionState state, @Nullable Throwable error) {
|
||||||
super.connectionStateChanged(state, error);
|
super.connectionStateChanged(state, error);
|
||||||
// Store generated client ID if none was set by the user
|
|
||||||
final MqttBrokerConnection connection = this.connection;
|
final MqttBrokerConnection connection = this.connection;
|
||||||
String clientID = config.clientID;
|
|
||||||
if (connection != null && state == MqttConnectionState.CONNECTED) {
|
if (connection != null && state == MqttConnectionState.CONNECTED) {
|
||||||
|
String clientID = config.clientID;
|
||||||
if (clientID == null || clientID.isBlank()) {
|
if (clientID == null || clientID.isBlank()) {
|
||||||
|
// Store generated client ID if none was set by the user
|
||||||
clientID = connection.getClientId();
|
clientID = connection.getClientId();
|
||||||
config.clientID = clientID;
|
config.clientID = clientID;
|
||||||
Configuration editConfig = editConfiguration();
|
Configuration editConfig = editConfiguration();
|
||||||
editConfig.put("clientid", clientID);
|
editConfig.put("clientid", clientID);
|
||||||
updateConfiguration(editConfig);
|
updateConfiguration(editConfig);
|
||||||
} else {
|
|
||||||
publish(config.birthTopic, config.birthMessage, config.birthRetain);
|
|
||||||
}
|
}
|
||||||
|
publish(config.birthTopic, config.birthMessage, config.birthRetain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue