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);
}
}
Aggregations