Compartilhar via


DeviceIO Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.device.DeviceIO

Implements

public final class DeviceIO
implements IotHubConnectionStatusChangeCallback

The task scheduler for sending and receiving messages for the Device Client

Method Summary

Modifier and Type Method and Description
void close()

Completes all current outstanding requests and closes the IoT Hub client.

void closeWithoutWrappingException()
void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext)

Callback that is executed when the connection status of this sdk to the iot hub changes.

IotHubClientProtocol getProtocol()

Getter for the transport protocol.

long getReceivePeriodInMilliseconds()

Getter for the receive period in milliseconds.

long getSendPeriodInMilliseconds()

Getter for the send period in milliseconds.

boolean isEmpty()

Getter for the transport empty queue.

boolean isOpen()

Getter for the connection state.

void registerConnectionStateCallback(IotHubConnectionStateCallback callback, Object callbackContext)

Registers a callback with the configured transport to be executed whenever the connection to the device is lost or established.

synchronized void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext, String deviceId)

Asynchronously sends an event message to the IoT Hub.

void setReceivePeriodInMilliseconds(long newIntervalInMilliseconds)

Setter for the receive period in milliseconds.

void setSendPeriodInMilliseconds(long newIntervalInMilliseconds)

Setter for the send period in milliseconds.

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

Method Details

close

public void close()

Completes all current outstanding requests and closes the IoT Hub client. Must be called to terminate the background thread that is sending data to IoT Hub. After close() is called, the IoT Hub client is no longer usable. If the client is already closed, the function shall do nothing.

Throws:

java.io.IOException - if the connection to an IoT Hub cannot be closed.

closeWithoutWrappingException

public void closeWithoutWrappingException()

Throws:

execute

public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext)

Callback that is executed when the connection status of this sdk to the iot hub changes. Includes details for more context on why that change occurred.

Parameters:

status
statusChangeReason
throwable
callbackContext

getProtocol

public IotHubClientProtocol getProtocol()

Getter for the transport protocol.

Returns:

a protocol for transport.

getReceivePeriodInMilliseconds

public long getReceivePeriodInMilliseconds()

Getter for the receive period in milliseconds.

Returns:

a long with the number of milliseconds between receives.

getSendPeriodInMilliseconds

public long getSendPeriodInMilliseconds()

Getter for the send period in milliseconds.

Returns:

a long with the number of milliseconds between sends.

isEmpty

public boolean isEmpty()

Getter for the transport empty queue.

Returns:

a boolean true if the transport queue is empty, or false if there is messages to send.

isOpen

public boolean isOpen()

Getter for the connection state.

Returns:

a boolean true if the connection is open or reconnecting, and false otherwise.

registerConnectionStateCallback

public void registerConnectionStateCallback(IotHubConnectionStateCallback callback, Object callbackContext)

Registers a callback with the configured transport to be executed whenever the connection to the device 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.

sendEventAsync

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

Asynchronously sends an event message to the IoT Hub.

Parameters:

message - the message to be sent.
callback - the callback to be invoked when a response is received. Can be null.
callbackContext - a context to be passed to the callback. Can be null if no callback is provided.
deviceId - the id of the device sending the message

setReceivePeriodInMilliseconds

public void setReceivePeriodInMilliseconds(long newIntervalInMilliseconds)

Setter for the receive period in milliseconds.

Parameters:

newIntervalInMilliseconds - is the new interval in milliseconds.

Throws:

java.io.IOException - if the task schedule exist but there is no receive task function to call.

setSendPeriodInMilliseconds

public void setSendPeriodInMilliseconds(long newIntervalInMilliseconds)

Setter for the send period in milliseconds.

Parameters:

newIntervalInMilliseconds - is the new interval in milliseconds.

Throws:

java.io.IOException - if the task schedule exist but there is no send task function to call.

Applies to