public void run()

in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubReconnectTask.java [41:106]


    public void run()
    {
        String threadName = "";
        if (this.useIdentifiableThreadNames)
        {
            String deviceClientId = this.transport.getDeviceClientUniqueIdentifier();
            String connectionId = transport.getTransportConnectionId();
            threadName += deviceClientId + "-" + "Cxn" + connectionId + "-" + THREAD_NAME;
        }
        else
        {
            if (this.threadNamePrefix != null && !this.threadNamePrefix.isEmpty())
            {
                threadName += this.threadNamePrefix;
            }

            threadName += THREAD_NAME;

            if (this.threadNameSuffix != null && !this.threadNameSuffix.isEmpty())
            {
                threadName += this.threadNameSuffix;
            }
        }

        Thread.currentThread().setName(threadName);

        try
        {
            try
            {
                if (!transport.needsReconnect())
                {
                    // IotHubTransport layer will make this semaphore available to acquire only once a disconnection
                    // event occurs. Once it is made available to acquire, this thread will wake up and run the reconnection
                    // logic.
                    //
                    // Note that this thread is not expected to release the semaphore once it is done reconnecting.
                    // This semaphore is not acquired to safely modify shared resources, but instead is used to signal
                    // when to start working. It is more akin to the basic Java wait/notify pattern, but without the
                    // order of operations dependency that wait/notify has.
                    this.reconnectThreadSemaphore.acquire();
                }
            }
            catch (InterruptedException e)
            {
                // likely means the client is shutting down, so no need to worry about handling disconnection events anymore.
                log.trace("Interrupted while waiting for disconnection events. Thread is now ending.");
                return;
            }

            try
            {
                log.debug("Starting reconnection process");
                this.transport.reconnect();
            }
            catch (InterruptedException e)
            {
                // likely means the client is shutting down, and any reconnection attempts should be abandoned
                log.trace("Interrupted while reconnecting. Thread is now ending.");
            }
        }
        catch (Throwable e)
        {
            log.warn("Reconnect task encountered exception while reconnecting", e);
        }
    }