public class IotHubTransport extends java.lang.Object implements IotHubListener
| Modifier and Type | Class and Description |
|---|---|
static class |
IotHubTransport.MessageRetryRunnable
Task for adding a packet back to the waiting queue.
|
| Constructor and Description |
|---|
IotHubTransport(ClientConfiguration defaultConfig,
IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback,
boolean isMultiplexing)
Constructor for an IotHubTransport object with default values
|
IotHubTransport(java.lang.String hostName,
IotHubClientProtocol protocol,
javax.net.ssl.SSLContext sslContext,
ProxySettings proxySettings,
IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback,
int keepAliveInterval,
int sendInterval,
boolean useIdentifiableThreadNames,
java.lang.String threadNamePrefix,
java.lang.String threadNameSuffix) |
| Modifier and Type | Method and Description |
|---|---|
void |
addMessage(Message message,
MessageSentCallback callback,
java.lang.Object callbackContext,
java.lang.String deviceId)
Adds a message to the transport queue.
|
void |
close(IotHubConnectionStatusChangeReason reason,
java.lang.Throwable cause)
Closes all resources used to communicate with an IoT Hub.
|
IotHubClientProtocol |
getProtocol() |
java.util.concurrent.Semaphore |
getReceiveThreadSemaphore() |
java.util.concurrent.Semaphore |
getReconnectThreadSemaphore() |
java.util.concurrent.Semaphore |
getSendThreadSemaphore() |
void |
handleMessage()
Invokes the message callback if a message is found and
responds to the IoT Hub on how the processed message should be
handled by the IoT Hub.
|
boolean |
hasCallbacksToExecute() |
boolean |
hasMessagesToSend() |
boolean |
hasReceivedMessagesToHandle() |
void |
invokeCallbacks()
Invokes the callbacks for all completed requests.
|
boolean |
isClosed() |
boolean |
isEmpty()
Returns
true if the transport has no more messages to handle,
and false otherwise. |
boolean |
needsReconnect() |
void |
onConnectionEstablished(java.lang.String connectionId)
Callback to be fired when the connection has been successfully established
|
void |
onConnectionLost(TransportException e,
java.lang.String connectionId)
Callback to be fired when connection has been lost
|
void |
onMessageReceived(IotHubTransportMessage message,
TransportException e)
Callback to be fired when a transport message has been received.
|
void |
onMessageSent(Message message,
java.lang.String deviceId,
TransportException e)
Callback to be fired when a message that the transport client sent has been acknowledged by Iot Hub
|
void |
onMultiplexedDeviceSessionEstablished(java.lang.String connectionId,
java.lang.String deviceId)
Callback to be fired when the multiplexed connection establishes a new device session.
|
void |
onMultiplexedDeviceSessionLost(TransportException e,
java.lang.String connectionId,
java.lang.String deviceId,
boolean shouldReconnect)
Callback to be fired when the multiplexed connection loses a device session.
|
void |
onMultiplexedDeviceSessionRegistrationFailed(java.lang.String connectionId,
java.lang.String deviceId,
java.lang.Exception e)
Callback to be fired when the multiplexed connection fails to register a device session.
|
void |
open(boolean withRetry)
Establishes a communication channel with an IoT Hub.
|
void |
reconnect() |
void |
registerMultiplexedDeviceClient(java.util.List<ClientConfiguration> configs,
long timeoutMilliseconds) |
void |
sendMessages()
Sends all messages on the transport queue.
|
void |
setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback,
java.lang.Object callbackContext,
java.lang.String deviceId)
Registers a callback to be executed whenever the connection status to the IoT Hub has changed.
|
void |
setMaxNumberOfMessagesSentPerSendThread(int maxNumberOfMessagesSentPerSendThread) |
void |
setMultiplexingConnectionStateCallback(IotHubConnectionStatusChangeCallback callback,
java.lang.Object callbackContext) |
void |
setMultiplexingRetryPolicy(RetryPolicy retryPolicy) |
void |
unregisterMultiplexedDeviceClient(java.util.List<ClientConfiguration> configs,
long timeoutMilliseconds) |
public IotHubTransport(ClientConfiguration defaultConfig, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback, boolean isMultiplexing) throws java.lang.IllegalArgumentException
defaultConfig - the config used for opening connections, retrieving retry policy, and checking protocoldeviceIOConnectionStatusChangeCallback - the connection status callback used to notify the DeviceIO
layer when connection events happen.isMultiplexing - true if this connection will multiplex. False otherwise.java.lang.IllegalArgumentException - if defaultConfig is nullpublic IotHubTransport(java.lang.String hostName,
IotHubClientProtocol protocol,
javax.net.ssl.SSLContext sslContext,
ProxySettings proxySettings,
IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback,
int keepAliveInterval,
int sendInterval,
boolean useIdentifiableThreadNames,
java.lang.String threadNamePrefix,
java.lang.String threadNameSuffix)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic java.util.concurrent.Semaphore getSendThreadSemaphore()
public java.util.concurrent.Semaphore getReceiveThreadSemaphore()
public java.util.concurrent.Semaphore getReconnectThreadSemaphore()
public boolean hasMessagesToSend()
public boolean hasReceivedMessagesToHandle()
public boolean hasCallbacksToExecute()
public boolean needsReconnect()
public boolean isClosed()
public void onMessageSent(Message message, java.lang.String deviceId, TransportException e)
IotHubListeneronMessageSent in interface IotHubListenermessage - The message that was acknowledgeddeviceId - The device that the message was sent frome - Null if the message was successfully acknowledged. Otherwise, this exception communicates if the message
should be resent at allpublic void onMessageReceived(IotHubTransportMessage message, TransportException e)
IotHubListeneronMessageReceived in interface IotHubListenermessage - The message that was received. May be null if e is not nulle - the exception that was encountered while receiving messages. May be null if transportMessage
is not nullpublic void onConnectionLost(TransportException e, java.lang.String connectionId)
IotHubListeneronConnectionLost in interface IotHubListenere - the cause of the connection lossconnectionId - the id of the connection this update is relevant topublic void onConnectionEstablished(java.lang.String connectionId)
IotHubListeneronConnectionEstablished in interface IotHubListenerconnectionId - the id of the connection this update is relevant topublic void onMultiplexedDeviceSessionEstablished(java.lang.String connectionId,
java.lang.String deviceId)
IotHubListeneronMultiplexedDeviceSessionEstablished in interface IotHubListenerconnectionId - the Id of the connection, used to identify which of possible many reconnection attempts
this event belongs to.deviceId - the Id of the device that the session belongs topublic void onMultiplexedDeviceSessionLost(TransportException e, java.lang.String connectionId, java.lang.String deviceId, boolean shouldReconnect)
IotHubListeneronMultiplexedDeviceSessionLost in interface IotHubListenere - The exception that caused the connection to be lost.connectionId - the Id of the connection, used to identify which of possible many reconnection attempts
this event belongs to.deviceId - the Id of the device that the session belongs toshouldReconnect - false if the disconnect was desired by the users, and true if it is the consequence of an
issue where the SDK should retry.public void onMultiplexedDeviceSessionRegistrationFailed(java.lang.String connectionId,
java.lang.String deviceId,
java.lang.Exception e)
IotHubListeneronMultiplexedDeviceSessionRegistrationFailed in interface IotHubListenerconnectionId - the Id of the connection, used to identify which of possible many reconnection attempts
this event belongs to.deviceId - the Id of the device that the session belongs toe - the throwable that explains why the registration failed.public void setMultiplexingRetryPolicy(RetryPolicy retryPolicy)
public void open(boolean withRetry)
throws TransportException,
IotHubClientException
If reconnection is occurring when this is called, this function shall block and wait for the reconnection to finish before trying to open the connection
withRetry - if true, this open call will apply the current retry policy to allow for the open call to be
retried if it fails.TransportException - if a communication channel cannot be established.IotHubClientExceptionpublic void close(IotHubConnectionStatusChangeReason reason, java.lang.Throwable cause)
close() is
called, the transport is no longer usable. If the transport is already
closed, the function shall do nothing.cause - the cause of why this connection is closing, to be reported over connection status change callbackreason - the reason to close this connection, to be reported over connection status change callbackpublic void reconnect()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void addMessage(Message message, MessageSentCallback callback, java.lang.Object callbackContext, java.lang.String deviceId)
message - the message to be sent.callback - the callback to be invoked when a response for the
message is received.callbackContext - the context to be passed in when the callback isdeviceId - the Id of the device that is sending this message.
invoked.public IotHubClientProtocol getProtocol()
public void sendMessages()
public void invokeCallbacks()
public void handleMessage()
throws TransportException
Invokes the message callback if a message is found and responds to the IoT Hub on how the processed message should be handled by the IoT Hub.
If no message callback is set, the function will do nothing.TransportException - if the server could not be reached.public boolean isEmpty()
true if the transport has no more messages to handle,
and false otherwise.true if the transport has no more messages to handle,
and false otherwise.public void setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, java.lang.Object callbackContext, java.lang.String deviceId)
callback - the callback to be called. Can be null if callbackContext is not nullcallbackContext - a context to be passed to the callback. Can be null.deviceId - the device that the connection status events being subscribed to are for.public void setMultiplexingConnectionStateCallback(IotHubConnectionStatusChangeCallback callback, java.lang.Object callbackContext)
public void registerMultiplexedDeviceClient(java.util.List<ClientConfiguration> configs, long timeoutMilliseconds) throws java.lang.InterruptedException, IotHubClientException, MultiplexingClientRegistrationException
java.lang.InterruptedExceptionIotHubClientExceptionMultiplexingClientRegistrationExceptionpublic void unregisterMultiplexedDeviceClient(java.util.List<ClientConfiguration> configs, long timeoutMilliseconds) throws java.lang.InterruptedException, IotHubClientException
java.lang.InterruptedExceptionIotHubClientExceptionpublic void setMaxNumberOfMessagesSentPerSendThread(int maxNumberOfMessagesSentPerSendThread)
Copyright © 2023. All rights reserved.