Partager via


InternalClient Class

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

public class InternalClient

Method Summary

Modifier and Type Method and Description
void close()
void closeNow()
DeviceClientConfig getConfig()

Getter for the device client config.

ProductInfo getProductInfo()
boolean isMultiplexed()

Returns if this client is or ever was registered to a MultiplexingClient instance.

void open()
void registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)

Registers a callback to be executed when the connection status of the device changes.

void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext)

Asynchronously sends an event message to the IoT Hub.

void sendEventBatchAsync(List<Message> messages, IotHubEventCallback callback, Object callbackContext)

Asynchronously sends a batch of messages to the IoT Hub HTTPS messages will be sent in a single batch and MQTT and AMQP messages will be sent individually.

void sendReportedProperties(ReportedPropertiesParameters reportedPropertiesParameters)

Sends reported properties

void sendReportedProperties(Set<DeviceTwin.Property> reportedProperties)

Sends reported properties

void sendReportedProperties(Set<DeviceTwin.Property> reportedProperties, int version)

Sends reported properties

void sendReportedProperties(Set<DeviceTwin.Property> reportedProperties, Integer version, CorrelatingMessageCallback correlatingMessageCallback, Object correlatingMessageCallbackContext, IotHubEventCallback reportedPropertiesCallback, Object reportedPropertiesCallbackContext)

Sends reported properties

protected void setAsMultiplexed()
void setOperationTimeout(long timeout)

Set the length of time, in milliseconds, that any given operation will expire in.

void setOption(String optionName, Object value)

Sets a runtime option identified by parameter optionName to value.

void setProxySettings(ProxySettings proxySettings)

Set the proxy settings for this client to connect through.

void setRetryPolicy(RetryPolicy retryPolicy)

Sets the given retry policy on the underlying transport See more details about the default retry policy and about using custom retry policies here

void subscribeToDesiredProperties(Map<DeviceTwin.Property,DeviceTwin.Pair<DeviceTwin.PropertyCallBack<String,Object>,Object>> onDesiredPropertyChange)

Subscribes to desired properties.

void subscribeToTwinDesiredProperties(Map<DeviceTwin.Property,DeviceTwin.Pair<DeviceTwin.TwinPropertyCallBack,Object>> onDesiredPropertyChange)

Subscribes to desired properties

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

Throws:

java.io.IOException

closeNow

public void closeNow()

Throws:

java.io.IOException

getConfig

public DeviceClientConfig getConfig()

Getter for the device client config.

Returns:

the value of the config.

getProductInfo

public ProductInfo getProductInfo()

isMultiplexed

public boolean isMultiplexed()

Returns if this client is or ever was registered to a MultiplexingClient instance. Device clients that were cannot be used in non-multiplexed connections. Device clients that aren't registered to any multiplexing client will still return true.

Returns:

true if this client is or ever was registered to a MultiplexingClient instance, false otherwise.

open

public void open()

Throws:

java.io.IOException

registerConnectionStatusChangeCallback

public void registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)

Registers a callback to be executed when the connection status of the device changes. The callback will be fired with a status and a reason why the device's status changed. When the callback is fired, the provided context will be provided alongside the status and reason.

Note that the thread used to deliver this callback should not be used to call open()/closeNow() on the client that this callback belongs to. All open()/closeNow() operations should be done on a separate thread

Parameters:

callback - The callback to be fired when the connection status of the device changes. Can be null to unset this listener as long as the provided callbackContext is also null.
callbackContext - a context to be passed to the callback. Can be null.

Throws:

java.lang.IllegalArgumentException - if provided callback is null

sendEventAsync

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

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.

sendEventBatchAsync

public void sendEventBatchAsync(List messages, IotHubEventCallback callback, Object callbackContext)

Asynchronously sends a batch of messages to the IoT Hub HTTPS messages will be sent in a single batch and MQTT and AMQP messages will be sent individually. In case of HTTPS, This API call is an all-or-nothing single HTTPS message and the callback will be triggered only once. Maximum payload size for HTTPS is 255KB

Parameters:

messages - the list of 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.

sendReportedProperties

public void sendReportedProperties(ReportedPropertiesParameters reportedPropertiesParameters)

Sends reported properties

Parameters:

reportedPropertiesParameters - Container for the reported properties parameters

Throws:

java.io.IOException - if called when client is not opened or called before starting twin.
java.lang.IllegalArgumentException - if called when client is not opened or called before starting twin.

sendReportedProperties

public void sendReportedProperties(Set reportedProperties)

Sends reported properties

Parameters:

reportedProperties - the Set for desired properties and their corresponding callback and context. Cannot be null.

Throws:

java.io.IOException - if called when client is not opened or called before starting twin.
java.lang.IllegalArgumentException - if called when client is not opened or called before starting twin.

sendReportedProperties

public void sendReportedProperties(Set reportedProperties, int version)

Sends reported properties

Parameters:

reportedProperties - the Set for desired properties and their corresponding callback and context. Cannot be null.
version - the Reported property version. Cannot be negative.

Throws:

java.io.IOException - if called when client is not opened or called before starting twin.
java.lang.IllegalArgumentException - if called when client is not opened or called before starting twin.

sendReportedProperties

public void sendReportedProperties(Set reportedProperties, Integer version, CorrelatingMessageCallback correlatingMessageCallback, Object correlatingMessageCallbackContext, IotHubEventCallback reportedPropertiesCallback, Object reportedPropertiesCallbackContext)

Sends reported properties

Parameters:

reportedProperties - the Set for desired properties and their corresponding callback and context. Cannot be null.
version - the Reported property version. Cannot be negative.
correlatingMessageCallback - the correlation callback for this message.
correlatingMessageCallbackContext - the correlation callback context for this message.
reportedPropertiesCallback - the Reported property callback to be set for this message. If set to null it will fall back to sendReportedProperties(Set<DeviceTwin.Property> reportedProperties, int version).
reportedPropertiesCallbackContext - the Reported property callback context to be set for this message.

Throws:

java.io.IOException - if called when client is not opened or called before starting twin.
java.lang.IllegalArgumentException - if called when client is not opened or called before starting twin.

setAsMultiplexed

protected void setAsMultiplexed()

setOperationTimeout

public void setOperationTimeout(long timeout)

Set the length of time, in milliseconds, that any given operation will expire in. These operations include reconnecting upon a connection drop and sending a message.

Parameters:

timeout - the length in time, in milliseconds, until a given operation shall expire

Throws:

java.lang.IllegalArgumentException - if the provided timeout is 0 or negative

setOption

public void setOption(String optionName, Object value)

Sets a runtime option identified by parameter optionName to value. The options that can be set via this API are: - SetMinimumPollingInterval - this option is applicable only when the transport configured with this client is HTTP. This option specifies the interval in milliseconds between calls to the service checking for availability of new messages. The value is expected to be of type long. - SetSendInterval - this option is applicable to all protocols. This value sets the period (in milliseconds) that this SDK spawns threads to send queued messages. Even if no message is queued, this thread will be spawned. - SetReceiveInterval - this option is applicable to all protocols in case of HTTPS protocol, this option acts the same as SetMinimumPollingInterval in case of MQTT and AMQP protocols, this option specifies the interval in milliseconds between spawning a thread that dequeues a message from the SDK's queue of received messages. - SetCertificatePath - this option is applicable only when the transport configured with this client is AMQP. This option specifies the path to the certificate used to verify peer. The value is expected to be of type String. - SetSASTokenExpiryTime - this option is applicable for HTTP/ AMQP/MQTT. This option specifies the interval in seconds after which SASToken expires. If the transport is already open then setting this option will restart the transport with the updated expiry time, and will use that expiry time length for all subsequently generated sas tokens. The value is expected to be of type long. - SetHttpsReadTimeout - this option is applicable for HTTPS. This option specifies the read timeout in milliseconds per https request made by this client. By default, this value is 4 minutes. The value is expected to be of type int. - SetHttpsConnectTimeout - this option is applicable for HTTPS. This option specifies the connect timeout in milliseconds per https request made by this client. By default, this value is 0 (no connect timeout). The value is expected to be of type int. - SetAmqpOpenAuthenticationSessionTimeout - this option is applicable for AMQP with SAS token authentication. This option specifies the timeout in seconds to wait to open the authentication session. By default, this value is 20 seconds. The value is expected to be of type int. - SetAmqpOpenDeviceSessionsTimeout - this option is applicable for AMQP. This option specifies the timeout in seconds to open the device sessions. By default, this value is 60 seconds. The value is expected to be of type int.

Parameters:

optionName - the option name to modify
value - an object of the appropriate type for the option's value

setProxySettings

public void setProxySettings(ProxySettings proxySettings)

Set the proxy settings for this client to connect through. If null then any previous settings will be erased

Parameters:

proxySettings - the settings to be used when connecting to iothub through a proxy. If null, any previously saved settings will be erased, and no proxy will be used

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)

Sets the given retry policy on the underlying transport See more details about the default retry policy and about using custom retry policies here

Parameters:

retryPolicy - the new interval in milliseconds

subscribeToDesiredProperties

public void subscribeToDesiredProperties(Map,Object>> onDesiredPropertyChange)

Subscribes to desired properties. This client will receive a callback each time a desired property is updated. That callback will either contain the full desired properties set, or only the updated desired property depending on how the desired property was changed. IoT Hub supports a PUT and a PATCH on the twin. The PUT will cause this device client to receive the full desired properties set, and the PATCH will cause this device client to only receive the updated desired properties. Similarly, the version of each desired property will be incremented from a PUT call, and only the actually updated desired property will have its version incremented from a PATCH call. The java service client library uses the PATCH call when updated desired properties, but it builds the patch such that all properties are included in the patch. As a result, the device side will receive full twin updates, not partial updates. See PUT and PATCH

Parameters:

onDesiredPropertyChange - the Map for desired properties and their corresponding callback and context. Can be null.

Throws:

java.io.IOException - if called when client is not opened or called before starting twin.

subscribeToTwinDesiredProperties

public void subscribeToTwinDesiredProperties(Map> onDesiredPropertyChange)

Subscribes to desired properties

Parameters:

onDesiredPropertyChange - the Map for desired properties and their corresponding callback and context. Can be null.

Throws:

java.io.IOException - if called when client is not opened or called before starting twin.

Applies to