com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iot-service-client Show documentation
Show all versions of iot-service-client Show documentation
The Microsoft Azure IoT Service SDK for Java
The newest version!
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package com.microsoft.azure.sdk.iot.service.digitaltwin;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinGetHeaders;
import com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinUpdateHeaders;
import com.microsoft.azure.sdk.iot.service.digitaltwin.generated.DigitalTwins;
import com.microsoft.azure.sdk.iot.service.digitaltwin.generated.models.DigitalTwinInvokeRootLevelCommandHeaders;
import com.microsoft.azure.sdk.iot.service.digitaltwin.models.DigitalTwinCommandResponse;
import com.microsoft.azure.sdk.iot.service.digitaltwin.models.DigitalTwinInvokeCommandHeaders;
import com.microsoft.azure.sdk.iot.service.digitaltwin.models.DigitalTwinInvokeCommandRequestOptions;
import com.microsoft.azure.sdk.iot.service.digitaltwin.models.DigitalTwinUpdateRequestOptions;
import com.microsoft.rest.ServiceResponseWithHeaders;
import java.util.List;
/**
*
* The Digital Twins Service Client contains methods to retrieve and update digital twin information, and invoke commands on a digital twin device.
*
* */
public class DigitalTwinClient {
private final DigitalTwinAsyncClient digitalTwinAsyncClient;
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
* @param connectionString The IoT Hub connection string
*/
public DigitalTwinClient(String connectionString) {
this(connectionString, DigitalTwinClientOptions.builder().build());
}
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
* @param connectionString The IoT Hub connection string
* @param options The optional settings for this client. May not be null.
*/
public DigitalTwinClient(String connectionString, DigitalTwinClientOptions options) {
digitalTwinAsyncClient = new DigitalTwinAsyncClient(connectionString, options);
}
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
*
* @param hostName The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
* @param credential The custom {@link TokenCredential} that will provide authentication tokens to
* this library when they are needed.
*/
public DigitalTwinClient(String hostName, TokenCredential credential) {
this(hostName, credential, DigitalTwinClientOptions.builder().build());
}
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
*
* @param hostName The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
* @param credential The custom {@link TokenCredential} that will provide authentication tokens to
* this library when they are needed.
* @param options The optional settings for this client. May not be null.
*/
public DigitalTwinClient(String hostName, TokenCredential credential, DigitalTwinClientOptions options) {
digitalTwinAsyncClient = new DigitalTwinAsyncClient(hostName, credential, options);
}
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
*
* @param hostName The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
* @param azureSasCredential The SAS token provider that will be used for authentication.
*/
public DigitalTwinClient(String hostName, AzureSasCredential azureSasCredential) {
this(hostName, azureSasCredential, DigitalTwinClientOptions.builder().build());
}
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
*
* @param hostName The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
* @param azureSasCredential The SAS token provider that will be used for authentication.
* @param options The optional settings for this client. May not be null.
*/
public DigitalTwinClient(String hostName, AzureSasCredential azureSasCredential, DigitalTwinClientOptions options) {
digitalTwinAsyncClient = new DigitalTwinAsyncClient(hostName, azureSasCredential, options);
}
/**
* Creates an implementation instance of {@link DigitalTwins} that is used to invoke the Digital Twin features
* @param connectionString The IoT Hub connection string
* @return The instantiated DigitalTwinClient.
*/
public static DigitalTwinClient createFromConnectionString(String connectionString)
{
return new DigitalTwinClient(connectionString);
}
/**
* Gets a digital twin.
* @param digitalTwinId The Id of the digital twin.
* @param clazz The class to deserialize the application/json into.
* @param The generic type to deserialize the application/json into.
* @return The application/json of the digital twin.
*/
public T getDigitalTwin(String digitalTwinId, Class clazz)
{
return getDigitalTwinWithResponse(digitalTwinId, clazz).body();
}
/**
* Gets a digital twin.
* @param digitalTwinId The Id of the digital twin.
* @param clazz The class to deserialize the application/json into.
* @param The generic type to deserialize the application/json into.
* @return A {@link ServiceResponseWithHeaders} representing deserialized application/json of the digital twin with {@link DigitalTwinGetHeaders}.
*/
public ServiceResponseWithHeaders getDigitalTwinWithResponse(String digitalTwinId, Class clazz)
{
return digitalTwinAsyncClient.getDigitalTwinWithResponse(digitalTwinId, clazz)
.toBlocking().single();
}
/**
* Updates a digital twin.
* @param digitalTwinId The Id of the digital twin.
* @param digitalTwinUpdateOperations The JSON patch to apply to the specified digital twin. This argument can be created using {@link UpdateOperationUtility}.
* @return void.
*/
public Void updateDigitalTwin(String digitalTwinId, List