다음을 통해 공유


IotHubTransport Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.device.transport.IotHubTransport

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 IotHubTransport object with default values

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.

IotHubClientProtocol 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 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)

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

IotHubTransport

public IotHubTransport(DeviceClientConfig defaultConfig, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback, boolean isMultiplexing)

Constructor for an IotHubTransport object with default values

Parameters:

defaultConfig - the config used for opening connections, retrieving retry policy, and checking protocol
deviceIOConnectionStatusChangeCallback
isMultiplexing

Throws:

java.lang.IllegalArgumentException - if defaultConfig is null

IotHubTransport

public IotHubTransport(String hostName, IotHubClientProtocol protocol, SSLContext sslContext, ProxySettings proxySettings, IotHubConnectionStatusChangeCallback deviceIOConnectionStatusChangeCallback)

Parameters:

hostName
protocol
sslContext
proxySettings
deviceIOConnectionStatusChangeCallback

Throws:

java.lang.IllegalArgumentException

Method Details

addMessage

public void addMessage(Message message, IotHubEventCallback callback, Object callbackContext, String deviceId)

Adds a message to the transport queue.

Parameters:

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 is
deviceId - the Id of the device that is sending this message. invoked.

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:

reason - the reason to close this connection, to be reported over connection status change callback
cause - the cause of why this connection is closing, to be reported over connection status change callback

Throws:

DeviceClientException - if an error occurs in closing the transport.

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:

DeviceClientException - if the server could not be reached.

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:

connectionId

onConnectionLost

public void onConnectionLost(Throwable e, String connectionId)

Callback to be fired when connection has been lost

Parameters:

e
connectionId

onMessageReceived

public void onMessageReceived(IotHubTransportMessage message, Throwable e)

Callback to be fired when a transport message has been received.

Parameters:

message
e

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:

message
deviceId
e

onMultiplexedDeviceSessionEstablished

public void onMultiplexedDeviceSessionEstablished(String connectionId, String deviceId)

Callback to be fired when the multiplexed connection establishes a new device session.

Parameters:

connectionId
deviceId

onMultiplexedDeviceSessionLost

public void onMultiplexedDeviceSessionLost(Throwable e, String connectionId, String deviceId)

Callback to be fired when the multiplexed connection loses a device session.

Parameters:

e
connectionId
deviceId

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:

connectionId
deviceId
e

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:

TransportException - if a communication channel cannot be established.

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:

callback - the callback to be called.
callbackContext - a context to be passed to the callback. Can be 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:

callback - the callback to be called. Can be null if callbackContext is not null
callbackContext - a context to be passed to the callback. Can be null.
deviceId

registerMultiplexedDeviceClient

public void registerMultiplexedDeviceClient(List configs, long timeoutMilliseconds)

Parameters:

configs
timeoutMilliseconds

Throws:

java.lang.InterruptedException

registerMultiplexingConnectionStateCallback

public void registerMultiplexingConnectionStateCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)

Parameters:

callback
callbackContext

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:

retryPolicy

unregisterMultiplexedDeviceClient

public void unregisterMultiplexedDeviceClient(List configs, long timeoutMilliseconds)

Parameters:

configs
timeoutMilliseconds

Throws:

java.lang.InterruptedException

Applies to