private void updateStatus()

in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransport.java [1691:1776]


    private void updateStatus(IotHubConnectionStatus newConnectionStatus, IotHubConnectionStatusChangeReason reason, Throwable throwable)
    {
        if (this.connectionStatus != newConnectionStatus)
        {
            if (throwable == null)
            {
                log.info("Updating transport status to new status {} with reason {}", newConnectionStatus, reason);
            }
            else if (this.getDefaultConfig() != null
                    && !this.getDefaultConfig().isLoggingRoutineDisconnectsAsErrors()
                    && newConnectionStatus == IotHubConnectionStatus.DISCONNECTED_RETRYING
                    && reason == IotHubConnectionStatusChangeReason.EXPIRED_SAS_TOKEN
                    && (protocol == IotHubClientProtocol.MQTT || protocol == IotHubClientProtocol.MQTT_WS))
            {
                // This is a special case where the user has opted out of treating the routine
                // MQTT/MQTT_WS SAS token disconnects as an error for logging purposes. As such,
                // log at the debug level instead of warn or error level.
                log.info("Updating transport status to new status {} with reason {}", newConnectionStatus, reason);
            }
            else
            {
                log.warn("Updating transport status to new status {} with reason {}", newConnectionStatus, reason, throwable);
            }

            ConnectionStatusChangeContext connectionStatusChangeContext = new ConnectionStatusChangeContext(newConnectionStatus, this.connectionStatus, reason, throwable, null);

            this.connectionStatus = newConnectionStatus;
            this.connectionStatusLastException = throwable;

            this.deviceIOConnectionStatusChangeCallback.onStatusChanged(connectionStatusChangeContext);

            //invoke connection status callbacks
            log.debug("Invoking connection status callbacks with new status details");

            if (!isMultiplexing || newConnectionStatus != IotHubConnectionStatus.CONNECTED)
            {
                // When multiplexing, a different method will notify each device-specific callback when that device is online,
                // but in cases when the tcp connection is lost and everything is disconnected retrying or disconnected, this is where the
                // callback should be fired
                invokeConnectionStatusChangeCallback(newConnectionStatus, reason, throwable);

                for (ClientConfiguration config : deviceClientConfigs.values())
                {
                    MultiplexedDeviceState deviceState = multiplexedDeviceConnectionStates.get(config.getDeviceId());
                    deviceState.setConnectionStatus(newConnectionStatus);
                    deviceState.setReconnectionAttemptNumber(0);
                }
            }

            // If multiplexing, fire the multiplexing state callback as long as it was set.
            if (isMultiplexing && this.multiplexingStateCallback != null)
            {
                this.multiplexingStateCallback.onStatusChanged(connectionStatusChangeContext);
            }

            if (newConnectionStatus == IotHubConnectionStatus.CONNECTED)
            {
                try
                {
                    correlationCallbackCleanupThread.start();
                }
                catch (IllegalThreadStateException e)
                {
                    // Thread has already started. No need to report this exception
                }

                try
                {
                    // 0 means that the user doesn't want to ever run this check
                    if (messageExpirationCheckPeriod != 0)
                    {
                        expiredMessagesCleanupThread.start();
                    }
                }
                catch (IllegalThreadStateException e)
                {
                    // Thread has already started. No need to report this exception
                }
            }
            else if (newConnectionStatus == IotHubConnectionStatus.DISCONNECTED)
            {
                correlationCallbackCleanupThread.interrupt();
                expiredMessagesCleanupThread.interrupt();
            }
        }
    }