use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class HttpsTransport method addMessage.
/**
* Adds a message to the transport queue.
*
* @param message the message to be sent.
* @param callback the callback to be invoked when a response for the
* message is received.
* @param callbackContext the context to be passed in when the callback is
* invoked.
*
* @throws IllegalStateException if the transport has not been opened or is
* already closed.
*/
public void addMessage(Message message, IotHubEventCallback callback, Object callbackContext) {
// Codes_SRS_HTTPSTRANSPORT_11_027: [If the transport is closed, the function shall throw an IllegalStateException.]
if (this.state == HttpsTransportState.CLOSED) {
throw new IllegalStateException("Cannot add a message to an HTTPS transport that is closed.");
}
// Codes_SRS_HTTPSTRANSPORT_11_003: [The function shall add a packet containing the message, callback, and callback context to the transport queue.]
IotHubOutboundPacket packet = new IotHubOutboundPacket(message, callback, callbackContext);
this.waitingList.add(packet);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class HttpsTransport method moveWaitingListToInProgressList.
/**
* Moves as many messages as can be sent in one HTTPS request from the
* waiting list to the in-progress list. If a single message is moved to the
* in-progress list, this indicates that the message is to be sent in the
* un-batched message format.
*/
private void moveWaitingListToInProgressList() {
HttpsBatchMessage batch = new HttpsBatchMessage();
while (!this.waitingList.isEmpty()) {
IotHubOutboundPacket packet = this.waitingList.peek();
try {
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(packet.getMessage());
batch.addMessage(httpsMsg);
} catch (SizeLimitExceededException e) {
break;
}
this.waitingList.remove();
this.inProgressList.add(packet);
}
if (!this.waitingList.isEmpty() && batch.numMessages() <= 0) {
IotHubOutboundPacket packet = this.waitingList.remove();
this.inProgressList.add(packet);
}
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class HttpsTransport method addMessage.
/**
* Adds a message to the transport queue.
*
* @param message the message to be sent.
* @param callback the callback to be invoked when a response for the
* message is received.
* @param callbackContext the context to be passed in when the callback is
* invoked.
*
* @throws IllegalStateException if the transport has not been opened or is
* already closed.
*/
public void addMessage(Message message, IotHubResponseCallback callback, Object callbackContext) {
// Codes_SRS_HTTPSTRANSPORT_21_018: [If the transport is closed, the function shall throw an IllegalStateException.]
if (this.state == HttpsTransportState.CLOSED) {
throw new IllegalStateException("Cannot add a message to an HTTPS transport that is closed.");
}
// Codes_SRS_HTTPSTRANSPORT_21_017: [The function shall add a packet containing the message, callback, and callback context to the transport queue.]
IotHubOutboundPacket packet = new IotHubOutboundPacket(message, callback, callbackContext);
this.waitingList.add(packet);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class HttpsTransport method close.
/**
* Closes all resources used to communicate with an IoT Hub. Once {@code close()} is
* called, the transport is no longer usable. If the transport is already
* closed, the function shall do nothing.
*
* @throws IOException if an error occurs in closing the transport.
*/
public void close() throws IOException {
// Codes_SRS_HTTPSTRANSPORT_99_036: [The method will remove all the messages which are in progress or waiting to be sent and add them to the callback list.]
while (!this.waitingList.isEmpty()) {
IotHubOutboundPacket packet = this.waitingList.remove();
ResponseMessage responseMessage = new ResponseMessage(new byte[] {}, IotHubStatusCode.MESSAGE_CANCELLED_ONCLOSE);
addOutboundPacketToCallbackList(packet, responseMessage);
}
while (!this.inProgressList.isEmpty()) {
IotHubOutboundPacket packet = this.inProgressList.remove();
ResponseMessage responseMessage = new ResponseMessage(new byte[] {}, IotHubStatusCode.MESSAGE_CANCELLED_ONCLOSE);
addOutboundPacketToCallbackList(packet, responseMessage);
}
// Codes_SRS_HTTPSTRANSPORT_99_037: [The method will invoke all the callbacks]
invokeCallbacks();
// the HTTPS connection does not contain state
// that needs to be explicitly destroyed.
// Codes_SRS_HTTPSTRANSPORT_11_035: [The function shall mark the transport as being closed.]
this.state = HttpsTransportState.CLOSED;
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class MqttTransport method close.
/**
* Closes all resources used to communicate with an IoT Hub. Once {@code close()} is
* called, the transport is no longer usable. If the transport is already
* closed, the function shall do nothing.
*/
public void close() throws IOException {
// Codes_SRS_MQTTTRANSPORT_15_006: [If the MQTT connection is closed, the function shall do nothing.]
if (this.state == State.CLOSED) {
return;
}
// Codes_SRS_MQTTTRANSPORT_99_020: [The method will remove all the messages which are in progress or waiting to be sent and add them to the callback list.]
while (!this.waitingList.isEmpty()) {
IotHubOutboundPacket packet = this.waitingList.remove();
IotHubCallbackPacket callbackPacket = new IotHubCallbackPacket(IotHubStatusCode.MESSAGE_CANCELLED_ONCLOSE, packet.getCallback(), packet.getContext());
this.callbackList.add(callbackPacket);
}
// Codes_SRS_MQTTTRANSPORT_99_021: [The method will invoke the callback list]
invokeCallbacks();
// Codes_SRS_MQTTTRANSPORT_15_005: [The function shall close the MQTT connection
// with the IoT Hub given in the configuration.]
this.mqttIotHubConnection.close();
this.state = State.CLOSED;
}
Aggregations