@Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new Pair<>(status, throwable)); } }, new Object());
public String getKey() { /* **Codes_SRS_Property_25_003: [**The function shall return the value of the key corresponding to this property.**]** */ return this.property.getKey(); }
public Object getValue() { /* **Codes_SRS_Property_25_004: [**The function shall return the value for this property.**]** */ return this.property.getValue(); }
private boolean reportPropertyCallback(Property property) { boolean reported = false; if (onDesiredPropertyChangeMap != null && onDesiredPropertyChangeMap.containsKey(property.getKey())) { Pair<PropertyCallBack<String, Object>, Object> callBackObjectPair = onDesiredPropertyChangeMap.get(property.getKey()); if (callBackObjectPair != null && callBackObjectPair.getKey() != null) { callBackObjectPair.getKey().PropertyCall(property.getKey(), property.getValue(), callBackObjectPair.getValue()); reported = true; } } if (onDesiredTwinPropertyChangeMap != null && onDesiredTwinPropertyChangeMap.containsKey(property.getKey())) { Pair<TwinPropertyCallBack, Object> callBackObjectPair = onDesiredTwinPropertyChangeMap.get(property.getKey()); if (callBackObjectPair != null && callBackObjectPair.getKey() != null) { callBackObjectPair.getKey().TwinPropertyCallBack(property, callBackObjectPair.getValue()); reported = true; } } return reported; }
public void setValue(Object newValue) { /* **Codes_SRS_Property_25_005: [**The function shall overwrite the new value for old.**]** */ this.property.setValue(newValue); }
@Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { statusUpdates.add(new Pair<>(status, throwable)); } }, new Object());
public static boolean actualStatusUpdatesContainsStatus(List<Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates, IotHubConnectionStatus status) { for (int i = 0; i < actualStatusUpdates.size(); i++) { if (actualStatusUpdates.get(i).getKey() == status) { return true; } } return false; } }
/** * Getter for the context to be passed in to the message callback. * * @param inputName the inputName that the desired callback context is tied to, or null for the default callback context * * @return the message context. */ public Object getDeviceTelemetryMessageContext(String inputName) { if (inputName == null || !this.inputChannelMessageCallbacks.containsKey(inputName)) { // Codes_SRS_DEVICECLIENTCONFIG_34_011: [If the inputName is null, or the message callbacks map does not // contain the provided inputName, this function shall return the default message callback context.] return this.defaultDeviceTelemetryMessageContext; } else { // Codes_SRS_DEVICECLIENTCONFIG_34_046: [If the message callbacks map contains the provided inputName, this function // shall return the context associated with that inputName.] return this.inputChannelMessageCallbacks.get(inputName).getValue(); } }
@Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { connectionStatusUpdates.add(new Pair<>(status, throwable)); } }, null);
/** * Getter for the message callback. * * @param inputName the inputName that the desired callback is tied to, or null for the default callback * * @return the message callback. */ public MessageCallback getDeviceTelemetryMessageCallback(String inputName) { if (inputName == null || !this.inputChannelMessageCallbacks.containsKey(inputName)) { // Codes_SRS_DEVICECLIENTCONFIG_34_010: [If the inputName is null, or the message callbacks map does not // contain the provided inputName, this function shall return the default message callback.] return this.defaultDeviceTelemetryMessageCallback; } else { // Codes_SRS_DEVICECLIENTCONFIG_34_045: [If the message callbacks map contains the provided inputName, this function // shall return the callback associated with that inputName.] return this.inputChannelMessageCallbacks.get(inputName).getKey(); } }
@Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<>(status, throwable)); } };
public static void confirmOpenStabilized(List<Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates, long timeout, InternalClient client) throws InterruptedException { long startTime = System.currentTimeMillis(); long timeElapsed; int numOfUpdates = 0; if (actualStatusUpdates != null) { while (numOfUpdates == 0 || numOfUpdates != actualStatusUpdates.size() || actualStatusUpdates.get(actualStatusUpdates.size() - 1).getKey() != IotHubConnectionStatus.CONNECTED) { numOfUpdates = actualStatusUpdates.size(); Thread.sleep(6 * 1000); timeElapsed = System.currentTimeMillis() - startTime; if (timeElapsed > timeout) { Assert.fail(buildExceptionMessage("Timed out waiting for a stable connection on first open", client)); } } } }
@Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new Pair<>(status, throwable)); } };
public void setDesiredPropertyCallback(Property desiredProp, PropertyCallBack<String, Object> desiredPropCallBack, Object desiredPropCallBackContext) { if (desiredProp == null) { /* **Codes_SRS_DEVICE_25_007: [**If the parameter desiredProp is null then this method shall throw IllegalArgumentException**]** */ throw new IllegalArgumentException("desired property cannot be null"); } /* **Codes_SRS_DEVICE_25_006: [**The function shall add the property and its callback and context pair to the user map of desired properties.**]** **Codes_SRS_DEVICE_25_008: [**This method shall add the parameters to the map even if callback and object pair are null**]** */ this.desiredProp.put(desiredProp, new Pair<>(desiredPropCallBack, desiredPropCallBackContext)); }
public void setMessageCallback(String inputName, MessageCallback callback, Object context) { if (this.inputChannelMessageCallbacks.containsKey(inputName) && callback == null) { // Codes_SRS_DEVICECLIENTCONFIG_34_058: [If the provided inputName is already saved in the message callbacks map, and the provided callback is null, this function // shall remove the inputName from the message callbacks map.] this.inputChannelMessageCallbacks.remove(inputName); } else { // Codes_SRS_DEVICECLIENTCONFIG_34_044: [The function shall map the provided inputName to the callback and context in the saved inputChannelMessageCallbacks map.] this.inputChannelMessageCallbacks.put(inputName, new Pair<>(callback, context)); } }
public Property(String key, Object value) { if (key == null || key.isEmpty()) { /* **Codes_SRS_Property_25_002: [**If the key is null or empty, the constructor shall throw an IllegalArgumentException.**] */ throw new IllegalArgumentException("Key cannot be null or empty"); } if (key.contains(" ") || key.contains("$") || key.contains(".")) { /* **Codes_SRS_Property_25_006: [**If the key contains illegal unicode control characters i.e ' ', '.', '$', the constructor shall throw an IllegalArgumentException.**]** */ throw new IllegalArgumentException("Key cannot contain illegal unicode control characters '.', '$', ' '"); } /* **Codes_SRS_Property_25_001: [**The constructor shall save the key and value representing this property.**]** */ this.property = new Pair<>(key, value); }
@Test public void testSubscribeToDesiredPropertiesWithVersion() throws IOException, InterruptedException, IotHubException { // arrange deviceUnderTest.sCDeviceForTwin.clearTwin(); deviceUnderTest.dCDeviceForTwin.getDesiredProp().clear(); Map<Property, Pair<TwinPropertyCallBack, Object>> desiredPropertiesCB = new HashMap<>(); for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) { PropertyState propertyState = new PropertyState(); propertyState.callBackTriggered = false; propertyState.propertyNewVersion = -1; propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; desiredPropertiesCB.put(propertyState.property, new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<TwinPropertyCallBack, Object>(deviceUnderTest.dCOnProperty, propertyState)); } // act internalClient.subscribeToTwinDesiredProperties(desiredPropertiesCB); Thread.sleep(DELAY_BETWEEN_OPERATIONS); Set<com.microsoft.azure.sdk.iot.service.devicetwin.Pair> desiredProperties = new HashSet<>(); for (int i = 0; i < MAX_PROPERTIES_TO_TEST; i++) { desiredProperties.add(new com.microsoft.azure.sdk.iot.service.devicetwin.Pair(PROPERTY_KEY + i, PROPERTY_VALUE_UPDATE + UUID.randomUUID())); } deviceUnderTest.sCDeviceForTwin.setDesiredProperties(desiredProperties); sCDeviceTwin.updateTwin(deviceUnderTest.sCDeviceForTwin); // assert waitAndVerifyTwinStatusBecomesSuccess(); waitAndVerifyDesiredPropertyCallback(PROPERTY_VALUE_UPDATE, true); }
propertyState.property = new Property(PROPERTY_KEY + i, PROPERTY_VALUE); deviceUnderTest.dCDeviceForTwin.propertyStateList[i] = propertyState; desiredPropertiesCB.put(propertyState.property, new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<TwinPropertyCallBack, Object>(deviceUnderTest.dCOnProperty, propertyState));
put(new Property("HomeTemp(F)", null), new Pair<TwinPropertyCallBack, Object>(new onHomeTempChange(), null)); put(new Property("LivingRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("BedroomRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("HomeSecurityCamera", null), new Pair<TwinPropertyCallBack, Object>(new onCameraActivity(), null));
put(new Property("HomeTemp(F)", null), new Pair<TwinPropertyCallBack, Object>(new onHomeTempChange(), null)); put(new Property("LivingRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("BedroomRoomLights", null), new Pair<TwinPropertyCallBack, Object>(new onProperty(), null)); put(new Property("HomeSecurityCamera", null), new Pair<TwinPropertyCallBack, Object>(new onCameraActivity(), null));