public class IotHubTransport extends Object implements IotHubListener
Modifier and Type | Class and Description |
---|---|
class |
IotHubTransport.MessageRetryRunnable
Task for adding a packet back to the waiting queue.
|
Constructor and Description |
---|
IotHubTransport(DeviceClientConfig defaultConfig,
IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback)
Constructor for an IotHubTransport object with default values
|
IotHubTransport(String hostName,
IotHubClientProtocol protocol,
SSLContext sslContext,
ProxySettings proxySettings,
IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback) |
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.
|
IotHubClientProtocol |
getProtocol() |
Object |
getReceiveThreadLock() |
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
true if the transport has no more messages to handle,
and false otherwise. |
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) |
public IotHubTransport(DeviceClientConfig defaultConfig, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback) throws IllegalArgumentException
defaultConfig
- the config used for opening connections, retrieving retry policy, and checking protocolIllegalArgumentException
- if defaultConfig is nullpublic IotHubTransport(String hostName, IotHubClientProtocol protocol, SSLContext sslContext, ProxySettings proxySettings, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback) throws IllegalArgumentException
IllegalArgumentException
public Object getSendThreadLock()
public Object getReceiveThreadLock()
public boolean hasMessagesToSend()
public boolean hasReceivedMessagesToHandle()
public boolean hasCallbacksToExecute()
public boolean isClosed()
public void onMessageSent(Message message, String deviceId, Throwable e)
IotHubListener
onMessageSent
in interface IotHubListener
message
- 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, Throwable e)
IotHubListener
onMessageReceived
in interface IotHubListener
message
- 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(Throwable e, String connectionId)
IotHubListener
onConnectionLost
in interface IotHubListener
e
- the cause of the connection lossconnectionId
- the id of the connection this update is relevant topublic void onConnectionEstablished(String connectionId)
IotHubListener
onConnectionEstablished
in interface IotHubListener
connectionId
- the id of the connection this update is relevant topublic void onMultiplexedDeviceSessionEstablished(String connectionId, String deviceId)
IotHubListener
onMultiplexedDeviceSessionEstablished
in interface IotHubListener
deviceId
- the Id of the device that the session belongs topublic void onMultiplexedDeviceSessionLost(Throwable e, String connectionId, String deviceId)
IotHubListener
onMultiplexedDeviceSessionLost
in interface IotHubListener
deviceId
- the Id of the device that the session belongs topublic void onMultiplexedDeviceSessionRegistrationFailed(String connectionId, String deviceId, Exception e)
IotHubListener
onMultiplexedDeviceSessionRegistrationFailed
in interface IotHubListener
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 toe
- the throwable that explains why the registration failed.public void setMultiplexingRetryPolicy(RetryPolicy retryPolicy)
public void open() throws TransportException
TransportException
- if a communication channel cannot be established.public void close(IotHubConnectionStatusChangeReason reason, Throwable cause) throws DeviceClientException
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 callbackDeviceClientException
- if an error occurs in closing the transport.public void addMessage(Message message, IotHubEventCallback callback, Object callbackContext, 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 DeviceClientException
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.DeviceClientException
- 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 registerConnectionStateCallback(IotHubConnectionStateCallback callback, Object callbackContext)
callback
- the callback to be called.callbackContext
- a context to be passed to the callback. Can be
null
if no callback is provided.public void registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext, 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
.public void registerMultiplexingConnectionStateCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)
public void registerMultiplexedDeviceClient(List<DeviceClientConfig> configs, long timeoutMilliseconds) throws InterruptedException, MultiplexingClientException
public void unregisterMultiplexedDeviceClient(List<DeviceClientConfig> configs, long timeoutMilliseconds) throws InterruptedException, MultiplexingClientException
Copyright © 2020. All rights reserved.