Search in sources :

Example 6 with ModuleClient

use of com.microsoft.azure.sdk.iot.device.ModuleClient in project azure-iot-sdk-java by Azure.

the class DeviceTwinCommon method setUpTwin.

protected void setUpTwin(DeviceState deviceState, boolean openDeviceClient, InternalClient client) throws IOException, IotHubException, InterruptedException {
    // set up twin on DeviceClient
    deviceState.dCDeviceForTwin = new DeviceExtension();
    if ((this.testInstance.protocol == AMQPS || this.testInstance.protocol == AMQPS_WS) && this.testInstance.authenticationType == SAS) {
        client.setOption("SetAmqpOpenAuthenticationSessionTimeout", AMQP_AUTHENTICATION_SESSION_TIMEOUT_SECONDS);
        client.setOption("SetAmqpOpenDeviceSessionsTimeout", AMQP_DEVICE_SESSION_TIMEOUT_SECONDS);
    }
    if (openDeviceClient) {
        client.open();
        if (client instanceof DeviceClient) {
            ((DeviceClient) client).startDeviceTwin(new DeviceTwinStatusCallBack(), deviceState, deviceState.dCDeviceForTwin, deviceState);
        } else {
            ((ModuleClient) client).startTwin(new DeviceTwinStatusCallBack(), deviceState, deviceState.dCDeviceForTwin, deviceState);
        }
    }
    deviceState.deviceTwinStatus = IotHubStatusCode.ERROR;
    // set up twin on ServiceClient
    if (testInstance.twinServiceClient != null) {
        if (testInstance.clientType == ClientType.DEVICE_CLIENT) {
            deviceState.sCDeviceForTwin = new DeviceTwinDevice(deviceState.sCDeviceForRegistryManager.getDeviceId());
        } else {
            deviceState.sCDeviceForTwin = new DeviceTwinDevice(deviceState.sCDeviceForRegistryManager.getDeviceId(), deviceState.sCModuleForRegistryManager.getId());
        }
        testInstance.twinServiceClient.getTwin(deviceState.sCDeviceForTwin);
        Thread.sleep(DELAY_BETWEEN_OPERATIONS);
    }
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) ModuleClient(com.microsoft.azure.sdk.iot.device.ModuleClient)

Aggregations

ModuleClient (com.microsoft.azure.sdk.iot.device.ModuleClient)6 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)4 Device (com.microsoft.azure.sdk.iot.service.Device)2 Module (com.microsoft.azure.sdk.iot.service.Module)2 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)2 ArrayList (java.util.ArrayList)2 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)1 Pair (com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair)1 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)1 TwinPropertiesCallback (com.microsoft.azure.sdk.iot.device.DeviceTwin.TwinPropertiesCallback)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 Message (com.microsoft.azure.sdk.iot.service.Message)1 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)1 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SSLContext (javax.net.ssl.SSLContext)1 Test (org.junit.Test)1 Success (tests.integration.com.microsoft.azure.sdk.iot.helpers.Success)1 TestModuleIdentity (tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity)1