public class InternalClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_TIMEOUT_MILLISECONDS |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the client.
|
ClientConfiguration |
getConfig()
Getter for the device client config.
|
ProductInfo |
getProductInfo() |
Twin |
getTwin()
Get the twin for this client.
|
Twin |
getTwin(int timeoutMilliseconds)
Get the twin for this client.
|
void |
getTwinAsync(GetTwinCallback twinCallback,
java.lang.Object callbackContext)
Get the twin for this client asynchronously.
|
void |
getTwinAsync(GetTwinCorrelatingMessageCallback twinCallback,
java.lang.Object callbackContext)
Get the twin for this client asynchronously.
|
void |
open(boolean withRetry)
Starts asynchronously sending and receiving messages from an IoT hub.
|
void |
sendEvent(Message message)
Synchronously sends a message to IoT hub.
|
void |
sendEvent(Message message,
int timeoutMilliseconds)
Synchronously sends a message to IoT hub.
|
void |
sendEventAsync(Message message,
MessageSentCallback callback,
java.lang.Object callbackContext)
Asynchronously sends a message to IoT hub.
|
void |
sendEvents(java.util.List<Message> messages)
Synchronously sends a batch of messages to IoT hub
This operation is only supported over HTTPS.
|
void |
sendEvents(java.util.List<Message> messages,
int timeoutMilliseconds)
Synchronously sends a batch of messages to IoT hub
This operation is only supported over HTTPS.
|
void |
sendEventsAsync(java.util.List<Message> messages,
MessagesSentCallback callback,
java.lang.Object callbackContext)
Asynchronously sends a batch of messages to the IoT hub
This operation is only supported over HTTPS.
|
void |
setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback,
java.lang.Object callbackContext)
Sets the callback to be executed when the connection status of the device changes.
|
void |
setOperationTimeout(long timeout)
Set the length of time, in milliseconds, that any given operation will expire in.
|
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(DesiredPropertiesCallback desiredPropertiesCallback,
java.lang.Object desiredPropertiesCallbackContext)
Start receiving desired property updates for this client.
|
void |
subscribeToDesiredProperties(DesiredPropertiesCallback desiredPropertiesCallback,
java.lang.Object desiredPropertiesCallbackContext,
int timeoutMilliseconds)
Start receiving desired property updates for this client.
|
void |
subscribeToDesiredPropertiesAsync(DesiredPropertiesCallback desiredPropertiesCallback,
java.lang.Object desiredPropertiesCallbackContext,
SubscriptionAcknowledgedCallback subscriptionAcknowledgedCallback,
java.lang.Object desiredPropertiesSubscriptionCallbackContext)
Start receiving desired property updates for this client asynchronously.
|
void |
subscribeToMethods(MethodCallback methodCallback,
java.lang.Object methodCallbackContext)
Subscribes to direct methods.
|
void |
subscribeToMethods(MethodCallback methodCallback,
java.lang.Object methodCallbackContext,
int timeoutMilliseconds)
Subscribes to direct methods.
|
void |
subscribeToMethodsAsync(MethodCallback methodCallback,
java.lang.Object methodCallbackContext,
SubscriptionAcknowledgedCallback methodStatusCallback,
java.lang.Object methodStatusCallbackContext)
Subscribes to direct methods.
|
ReportedPropertiesUpdateResponse |
updateReportedProperties(TwinCollection reportedProperties)
Patch this client's twin with the provided reported properties.
|
ReportedPropertiesUpdateResponse |
updateReportedProperties(TwinCollection reportedProperties,
int timeoutMilliseconds)
Patch this client's twin with the provided reported properties.
|
void |
updateReportedPropertiesAsync(TwinCollection reportedProperties,
ReportedPropertiesCallback reportedPropertiesCallback,
java.lang.Object callbackContext)
Patch this client's twin with the provided reported properties asynchronously.
|
void |
updateReportedPropertiesAsync(TwinCollection reportedProperties,
ReportedPropertiesUpdateCorrelatingMessageCallback reportedPropertiesUpdateCorrelatingMessageCallback,
java.lang.Object callbackContext)
Patch this client's twin with the provided reported properties asynchronously.
|
protected static final int DEFAULT_TIMEOUT_MILLISECONDS
public void open(boolean withRetry) throws IotHubClientException
withRetry
- if true, this open call will apply the retry policy to allow for the open call to be retried if
it fails. Both the operation timeout set in setOperationTimeout(long)
and the retry policy set in
{setRetryPolicy(RetryPolicy)
} will be respected while retrying to open the connection.IotHubClientException
- if a connection to an IoT hub cannot be established or if the connection can be
established but the service rejects it for any reason.public void close()
public void sendEvent(Message message) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
message
- the message to be sent.java.lang.InterruptedException
- if the operation is interrupted while waiting on the telemetry to be acknowledged by the service.java.lang.IllegalStateException
- if the client has not been opened yet or is already closed.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public void sendEvent(Message message, int timeoutMilliseconds) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
message
- the message to be sent.timeoutMilliseconds
- The maximum number of milliseconds to wait for the service to acknowledge this message.
If 0, then it will wait indefinitely.java.lang.InterruptedException
- if the operation is interrupted while waiting on the telemetry to be acknowledged by the service.java.lang.IllegalStateException
- if the client has not been opened yet or is already closed.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public void sendEvents(java.util.List<Message> messages) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException, java.lang.UnsupportedOperationException
messages
- the messages to be sent.java.lang.InterruptedException
- if the operation is interrupted while waiting on the telemetry to be acknowledged by the service.java.lang.IllegalStateException
- if the client has not been opened yet or is already closed.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.java.lang.UnsupportedOperationException
- if the client is not using HTTPS.public void sendEvents(java.util.List<Message> messages, int timeoutMilliseconds) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException, java.lang.UnsupportedOperationException
messages
- the messages to be sent.timeoutMilliseconds
- The maximum number of milliseconds to wait for the service to acknowledge this batch message.
If 0, then it will wait indefinitely.java.lang.InterruptedException
- if the operation is interrupted while waiting on the telemetry to be acknowledged by the service.java.lang.IllegalStateException
- if the client has not been opened yet or is already closed.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.java.lang.UnsupportedOperationException
- if the client is not using HTTPS.public void subscribeToDesiredProperties(DesiredPropertiesCallback desiredPropertiesCallback, java.lang.Object desiredPropertiesCallbackContext) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
This call can only be made after the client has been successfully opened.
This subscription is preserved between reconnect attempts. However, it is not preserved after a client has
been closed because the user called close()
or because this client lost its connection and its retry
policy was exhausted.
desiredPropertiesCallback
- The callback to execute each time a desired property update message is received
from the service. This will contain one or many properties updated at once.desiredPropertiesCallbackContext
- The context that will be included in the callback of desiredPropertiesCallback. May be null.java.lang.InterruptedException
- if the operation is interrupted while waiting on the subscription request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public void subscribeToDesiredProperties(DesiredPropertiesCallback desiredPropertiesCallback, java.lang.Object desiredPropertiesCallbackContext, int timeoutMilliseconds) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
This call can only be made after the client has been successfully opened.
This subscription is preserved between reconnect attempts. However, it is not preserved after a client has
been closed because the user called close()
or because this client lost its connection and its retry
policy was exhausted.
desiredPropertiesCallback
- The callback to execute each time a desired property update message is received
from the service. This will contain one or many properties updated at once.desiredPropertiesCallbackContext
- The context that will be included in the callback of desiredPropertiesCallback. May be null.timeoutMilliseconds
- The maximum number of milliseconds this call will wait for the service to acknowledge the subscription request. If 0,
then it will wait indefinitely.java.lang.InterruptedException
- if the operation is interrupted while waiting on the subscription request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public ReportedPropertiesUpdateResponse updateReportedProperties(TwinCollection reportedProperties) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
reportedProperties
- The reported property key/value pairs to add/update in the twin. To delete a particular
reported property, set the value to null.java.lang.InterruptedException
- if the operation is interrupted while waiting on the reported property update request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public ReportedPropertiesUpdateResponse updateReportedProperties(TwinCollection reportedProperties, int timeoutMilliseconds) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
reportedProperties
- The reported property key/value pairs to add/update in the twin. To delete a particular
reported property, set the value to null.timeoutMilliseconds
- The maximum number of milliseconds this call will wait for the service to acknowledge the reported properties update request. If 0,
then it will wait indefinitely.java.lang.InterruptedException
- if the operation is interrupted while waiting on the reported property update request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public Twin getTwin() throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
java.lang.InterruptedException
- if the operation is interrupted while waiting on the getTwin request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public Twin getTwin(int timeoutMilliseconds) throws java.lang.InterruptedException, java.lang.IllegalStateException, IotHubClientException
timeoutMilliseconds
- The maximum number of milliseconds this call will wait for the service to return the twin.
If 0, then it will wait indefinitely.java.lang.InterruptedException
- if the operation is interrupted while waiting on the getTwin request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public void subscribeToMethods(MethodCallback methodCallback, java.lang.Object methodCallbackContext) throws java.lang.IllegalStateException, java.lang.InterruptedException, IotHubClientException
This call can only be made after the client has been successfully opened.
This subscription is preserved between reconnect attempts. However, it is not preserved after a client has
been closed because the user called close()
or because this client lost its connection and its retry
policy was exhausted.
methodCallback
- Callback on which direct methods shall be invoked. Cannot be null
.methodCallbackContext
- Context for device method callback. Can be null
.java.lang.InterruptedException
- if the operation is interrupted while waiting on the subscription request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public void subscribeToMethods(MethodCallback methodCallback, java.lang.Object methodCallbackContext, int timeoutMilliseconds) throws java.lang.IllegalStateException, java.lang.InterruptedException, IotHubClientException
This call can only be made after the client has been successfully opened.
This subscription is preserved between reconnect attempts. However, it is not preserved after a client has
been closed because the user called close()
or because this client lost its connection and its retry
policy was exhausted.
methodCallback
- Callback on which direct methods shall be invoked. Cannot be null
.methodCallbackContext
- Context for device method callback. Can be null
.timeoutMilliseconds
- The maximum number of milliseconds this call will wait for the service to return the twin.
If 0, then it will wait indefinitely.java.lang.InterruptedException
- if the operation is interrupted while waiting on the subscription request to be acknowledged by the service.java.lang.IllegalStateException
- if this client is not open.IotHubClientException
- if the request is rejected by the service for any reason of if the synchronous operation times out.public void sendEventAsync(Message message, MessageSentCallback callback, java.lang.Object callbackContext) throws java.lang.IllegalStateException
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.java.lang.IllegalArgumentException
- if the message provided is null
.java.lang.IllegalStateException
- if the client has not been opened yet or is already closed.public void sendEventsAsync(java.util.List<Message> messages, MessagesSentCallback callback, java.lang.Object callbackContext) throws java.lang.IllegalStateException, java.lang.UnsupportedOperationException
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.java.lang.IllegalArgumentException
- if the message provided is null
.java.lang.IllegalStateException
- if the client has not been opened yet or is already closed.java.lang.UnsupportedOperationException
- if the client is not using HTTPS.public void subscribeToDesiredPropertiesAsync(DesiredPropertiesCallback desiredPropertiesCallback, java.lang.Object desiredPropertiesCallbackContext, SubscriptionAcknowledgedCallback subscriptionAcknowledgedCallback, java.lang.Object desiredPropertiesSubscriptionCallbackContext) throws java.lang.IllegalStateException
This call can only be made after the client has been successfully opened.
This subscription is preserved between reconnect attempts. However, it is not preserved after a client has
been closed because the user called close()
or because this client lost its connection and its retry
policy was exhausted.
subscriptionAcknowledgedCallback
- The callback to execute once the service has acknowledged the subscription request.desiredPropertiesSubscriptionCallbackContext
- The context that will be included in the callback of desiredPropertiesSubscriptionCallback. May be null.desiredPropertiesCallback
- The callback to execute each time a desired property update message is received
from the service. This will contain one or many properties updated at once.desiredPropertiesCallbackContext
- The context that will be included in each callback of desiredPropertiesCallback. May be null.java.lang.IllegalStateException
- if this client is not open.public void updateReportedPropertiesAsync(TwinCollection reportedProperties, ReportedPropertiesCallback reportedPropertiesCallback, java.lang.Object callbackContext) throws java.lang.IllegalStateException
reportedProperties
- The reported property key/value pairs to add/update in the twin. To delete a particular
reported property, set the value to null.reportedPropertiesCallback
- The callback to be executed once the reported properties update request
has been acknowledged by the service.callbackContext
- The context that will be included in the callback of reportedPropertiesCallback. May be null.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.public void updateReportedPropertiesAsync(TwinCollection reportedProperties, ReportedPropertiesUpdateCorrelatingMessageCallback reportedPropertiesUpdateCorrelatingMessageCallback, java.lang.Object callbackContext) throws java.lang.IllegalStateException
This overload utilizes a more verbose callback than updateReportedPropertiesAsync(TwinCollection, ReportedPropertiesCallback, Object)
and is only intended for users who need insight on the state of this process every step of the way.
reportedProperties
- The reported property key/value pairs to add/update in the twin. To delete a particular
reported property, set the value to null.reportedPropertiesUpdateCorrelatingMessageCallback
- The callback to be executed once the state of the reported
properties update request message has changed. This provides context on when the message is queued, sent, acknowledged, etc.callbackContext
- The context that will be included in each callback of updateReportedPropertiesCallback. May be null.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.public void getTwinAsync(GetTwinCallback twinCallback, java.lang.Object callbackContext) throws java.lang.IllegalStateException
twinCallback
- The callback to be executed once the twin is received from the service.callbackContext
- The context that will be included in the callback of twinCallback. May be null.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.public void getTwinAsync(GetTwinCorrelatingMessageCallback twinCallback, java.lang.Object callbackContext) throws java.lang.IllegalStateException
This overload utilizes a more verbose callback than getTwinAsync(GetTwinCallback, Object)
and is only intended for users who need insight on the state of this process every step of the way.
twinCallback
- The callback to be executed once the state of the getTwin request message has changed. This
provides context on when the message is queued, sent, acknowledged, etc.callbackContext
- The context that will be included in each callback of twinCallback. May be null.java.lang.IllegalStateException
- if this client is not open or if this client has not subscribed to desired properties yet.public void subscribeToMethodsAsync(MethodCallback methodCallback, java.lang.Object methodCallbackContext, SubscriptionAcknowledgedCallback methodStatusCallback, java.lang.Object methodStatusCallbackContext) throws java.lang.IllegalStateException
This call can only be made after the client has been successfully opened.
This subscription is preserved between reconnect attempts. However, it is not preserved after a client has
been closed because the user called close()
or because this client lost its connection and its retry
policy was exhausted.
methodCallback
- Callback on which direct methods shall be invoked. Cannot be null
.methodCallbackContext
- Context for device method callback. Can be null
.methodStatusCallback
- Callback for providing IotHub status for direct methods. Cannot be null
.methodStatusCallbackContext
- Context for device method status callback. Can be null
.java.lang.IllegalStateException
- if called when client is not opened.java.lang.IllegalArgumentException
- if either callback are null.public void setConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, java.lang.Object callbackContext)
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()/close() operations should be done on a separate thread
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
.public void setRetryPolicy(RetryPolicy retryPolicy)
retryPolicy
- the new interval in millisecondspublic void setOperationTimeout(long timeout) throws java.lang.IllegalArgumentException
timeout
- the length in time, in milliseconds, until a given operation shall expirejava.lang.IllegalArgumentException
- if the provided timeout is 0 or negativepublic ProductInfo getProductInfo()
public ClientConfiguration getConfig()
Copyright © 2023. All rights reserved.