in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubSendTask.java [45:99]
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
{
if (!this.transport.hasMessagesToSend() && !this.transport.hasCallbacksToExecute() && !this.transport.isClosed())
{
// IotHubTransport layer will make this semaphore available to acquire only once a message is ready to
// be sent or a callback is ready to be executed. Once it is made available to acquire, this thread will
// wake up, send the messages and invoke the callbacks. Until then, do nothing.
//
// Note that this thread is not expected to release the semaphore once it is done sending messages.
// 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.sendThreadSemaphore.acquire();
}
this.transport.sendMessages();
this.transport.invokeCallbacks();
}
catch (InterruptedException e)
{
// Typically happens if a disconnection event occurs and the DeviceIO layer cancels the send/receive threads
// while the reconnection takes place.
log.trace("Interrupted while waiting for work. Thread is now ending.");
}
catch (Throwable e)
{
log.warn("Send task encountered exception while sending messages", e);
}
}