IotHubTransport Class
- java.
lang. Object - com.
microsoft. azure. sdk. iot. device. transport. IotHubTransport
- com.
Implements
public class IotHubTransport
implements IotHubListener
Manages queueing of message sending, receiving and callbacks. Manages notifying users of connection status change updates
Constructor Summary
Constructor | Description | |
---|---|---|
IotHubTransport(DeviceClientConfig defaultConfig, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback, boolean isMultiplexing) |
Constructor for an Iot |
|
IotHubTransport(String hostName, IotHubClientProtocol protocol, SSLContext sslContext, ProxySettings proxySettings, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback) |
Method Summary
Modifier and Type | Method and Description |
---|---|
void |
addMessage(Message message, IotHubEventCallback callback, Object callbackContext, String deviceId)
Adds a message to the transport queue. |
void |
close(IotHubConnectionStatusChangeReason reason, Throwable cause)
Closes all resources used to communicate with an IoT Hub. |
Iot |
getProtocol() |
java.lang.Object | getReceiveThreadLock() |
java.lang.Object | getSendThreadLock() |
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 |
void |
onConnectionEstablished(String connectionId)
Callback to be fired when the connection has been successfully established |
void |
onConnectionLost(Throwable e, String connectionId)
Callback to be fired when connection has been lost |
void |
onMessageReceived(IotHubTransportMessage message, Throwable e)
Callback to be fired when a transport message has been received. |
void |
onMessageSent(Message message, String deviceId, Throwable e)
Callback to be fired when a message that the transport client sent has been acknowledged by Iot Hub |
void |
onMultiplexedDeviceSessionEstablished(String connectionId, String deviceId)
Callback to be fired when the multiplexed connection establishes a new device session. |
void |
onMultiplexedDeviceSessionLost(Throwable e, String connectionId, String deviceId)
Callback to be fired when the multiplexed connection loses a device session. |
void |
onMultiplexedDeviceSessionRegistrationFailed(String connectionId, String deviceId, Exception e)
Callback to be fired when the multiplexed connection fails to register a device session. |
void |
open()
Establishes a communication channel with an IoT Hub. |
void |
registerConnectionStateCallback(IotHubConnectionStateCallback callback, Object callbackContext)
Registers a callback to be executed whenever the connection to the IoT Hub is lost or established. |
void |
registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext, String deviceId)
Registers a callback to be executed whenever the connection status to the IoT Hub has changed. |
void | registerMultiplexedDeviceClient(List<DeviceClientConfig> configs, long timeoutMilliseconds) |
void | registerMultiplexingConnectionStateCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext) |
void |
sendMessages()
Sends all messages on the transport queue. |
void | setMultiplexingRetryPolicy(RetryPolicy retryPolicy) |
void | unregisterMultiplexedDeviceClient(List<DeviceClientConfig> configs, long timeoutMilliseconds) |
Methods inherited from java.lang.Object
Constructor Details
IotHubTransport
public IotHubTransport(DeviceClientConfig defaultConfig, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback, boolean isMultiplexing)
Constructor for an IotHubTransport object with default values
Parameters:
Throws:
IotHubTransport
public IotHubTransport(String hostName, IotHubClientProtocol protocol, SSLContext sslContext, ProxySettings proxySettings, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback)
Parameters:
Throws:
Method Details
addMessage
public void addMessage(Message message, IotHubEventCallback callback, Object callbackContext, String deviceId)
Adds a message to the transport queue.
Parameters:
close
public void close(IotHubConnectionStatusChangeReason reason, Throwable cause)
Closes all resources used to communicate with an IoT Hub. Once close()
is called, the transport is no longer usable. If the transport is already closed, the function shall do nothing.
Parameters:
Throws:
getProtocol
public IotHubClientProtocol getProtocol()
getReceiveThreadLock
public Object getReceiveThreadLock()
getSendThreadLock
public Object getSendThreadLock()
handleMessage
public 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.
If no message callback is set, the function will do nothing.
Throws:
hasCallbacksToExecute
public boolean hasCallbacksToExecute()
hasMessagesToSend
public boolean hasMessagesToSend()
hasReceivedMessagesToHandle
public boolean hasReceivedMessagesToHandle()
invokeCallbacks
public void invokeCallbacks()
Invokes the callbacks for all completed requests.
isClosed
public boolean isClosed()
isEmpty
public boolean isEmpty()
Returns true
if the transport has no more messages to handle, and false
otherwise.
Returns:
true
if the transport has no more messages to handle,
and false
otherwise.onConnectionEstablished
public void onConnectionEstablished(String connectionId)
Callback to be fired when the connection has been successfully established
Parameters:
onConnectionLost
public void onConnectionLost(Throwable e, String connectionId)
Callback to be fired when connection has been lost
Parameters:
onMessageReceived
public void onMessageReceived(IotHubTransportMessage message, Throwable e)
Callback to be fired when a transport message has been received.
Parameters:
onMessageSent
public void onMessageSent(Message message, String deviceId, Throwable e)
Callback to be fired when a message that the transport client sent has been acknowledged by Iot Hub
Parameters:
onMultiplexedDeviceSessionEstablished
public void onMultiplexedDeviceSessionEstablished(String connectionId, String deviceId)
Callback to be fired when the multiplexed connection establishes a new device session.
Parameters:
onMultiplexedDeviceSessionLost
public void onMultiplexedDeviceSessionLost(Throwable e, String connectionId, String deviceId)
Callback to be fired when the multiplexed connection loses a device session.
Parameters:
onMultiplexedDeviceSessionRegistrationFailed
public void onMultiplexedDeviceSessionRegistrationFailed(String connectionId, String deviceId, Exception e)
Callback to be fired when the multiplexed connection fails to register a device session.
Parameters:
open
public void open()
Establishes a communication channel with an IoT Hub. If a channel is already open, the function shall do nothing.
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
Throws:
registerConnectionStateCallback
public void registerConnectionStateCallback(IotHubConnectionStateCallback callback, Object callbackContext)
Registers a callback to be executed whenever the connection to the IoT Hub is lost or established.
Parameters:
null
if no callback is provided.
registerConnectionStatusChangeCallback
public void registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext, String deviceId)
Registers a callback to be executed whenever the connection status to the IoT Hub has changed.
Parameters:
null
.
registerMultiplexedDeviceClient
public void registerMultiplexedDeviceClient(List
Parameters:
Throws:
registerMultiplexingConnectionStateCallback
public void registerMultiplexingConnectionStateCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)
Parameters:
sendMessages
public void sendMessages()
Sends all messages on the transport queue. If a previous send attempt had failed, the function will attempt to resend the messages in the previous attempt.
setMultiplexingRetryPolicy
public void setMultiplexingRetryPolicy(RetryPolicy retryPolicy)
Parameters:
unregisterMultiplexedDeviceClient
public void unregisterMultiplexedDeviceClient(List
Parameters:
Throws:
Applies to
Azure SDK for Java