public final class HttpsTransport extends Object implements IotHubTransport
An HTTPS transport. Contains functionality for adding messages and sending batched messages to an IoT Hub. Buffers unsent messages until they are received by an IoT Hub. A transport is bound at construction to the following parameters: IoT Hub name, device ID, device key, and message valid seconds.
The transport can also poll an IoT Hub for messages and invoke a user-defined message callback if a message and callback is found.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
HttpsTransport.HttpsTransportState
The state of the HTTPS transport.
|
| Modifier and Type | Field and Description |
|---|---|
protected Queue<IotHubCallbackPacket> |
callbackList
Messages whose callbacks that are waiting to be invoked.
|
protected DeviceClientConfig |
config |
protected HttpsIotHubConnection |
connection
The underlying HTTPS connection.
|
protected Queue<IotHubOutboundPacket> |
inProgressList
Messages that are waiting for a response from an IoT Hub.
|
protected HttpsTransport.HttpsTransportState |
state |
protected Queue<IotHubOutboundPacket> |
waitingList
Messages waiting to be sent to an IoT Hub.
|
| Constructor and Description |
|---|
HttpsTransport(DeviceClientConfig config)
Constructs an instance from the given
DeviceClientConfig
object. |
| Modifier and Type | Method and Description |
|---|---|
void |
addMessage(Message message,
IotHubEventCallback callback,
Object callbackContext)
Adds a message to the transport queue.
|
void |
close()
Closes all resources used to communicate with an IoT Hub.
|
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.
|
protected HttpsMessage |
inProgressListToMessage()
Generates the message, possibly batched, to be sent using the messages in
the in-progress list.
|
void |
invokeCallbacks()
Invokes the callbacks for all completed requests.
|
boolean |
isEmpty()
Returns true if the transport has no more messages to handle, and false
otherwise.
|
protected void |
moveInProgressListToCallbackList(IotHubStatusCode status)
Moves messages from the in progress list to the callback list, updating
the message packets with the status code from the response.
|
protected void |
moveWaitingListToInProgressList()
Moves as many messages as can be sent in one HTTPS request from the
waiting list to the in-progress list.
|
void |
open()
Establishes a communication channel with an IoT Hub.
|
void |
sendMessages()
Sends all messages on the transport queue as a batched request.
|
protected HttpsTransport.HttpsTransportState state
protected HttpsIotHubConnection connection
protected final Queue<IotHubOutboundPacket> waitingList
protected final Queue<IotHubOutboundPacket> inProgressList
protected final Queue<IotHubCallbackPacket> callbackList
protected final DeviceClientConfig config
public HttpsTransport(DeviceClientConfig config)
DeviceClientConfig
object.config - configuration parameters for an IoT Hub connection.public void open()
throws IOException
open in interface IotHubTransportIOException - if a communication channel cannot be established.public void close()
throws IOException
close() is
called, the transport is no longer usable. If the transport is already
closed, the function shall do nothing.close in interface IotHubTransportclose in interface Closeableclose in interface AutoCloseableIOException - if an error occurs in closing the transport.public void addMessage(Message message, IotHubEventCallback callback, Object callbackContext)
addMessage in interface IotHubTransportmessage - 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
invoked.IllegalStateException - if the transport has not been opened or is
already closed.public void sendMessages()
throws IOException
sendMessages in interface IotHubTransportIOException - if the server could not be reached.IllegalStateException - if the transport has not been opened or is
already closed.public void invokeCallbacks()
invokeCallbacks in interface IotHubTransportIllegalStateException - if the transport has not been opened or is
already closed.public void handleMessage()
throws IOException
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.handleMessage in interface IotHubTransportIOException - if the server could not be reached, or if the
response from sending the IoT Hub message result does not have
status code IotHubStatusCode.OK_EMPTY.IllegalStateException - if the transport has not been opened or is
already closed.public boolean isEmpty()
isEmpty in interface IotHubTransportprotected void moveWaitingListToInProgressList()
protected HttpsMessage inProgressListToMessage() throws SizeLimitExceededException
SizeLimitExceededException - if the messages in inProgressList
exceed the service-bound message size limit of 255 kb.NoSuchElementException - if inProgressList is empty.protected void moveInProgressListToCallbackList(IotHubStatusCode status)
status - the status code returned by the IoT Hub.Copyright © 2017. All rights reserved.