/** * Puts DeviceDescription, merging annotations as necessary. * * @param newDesc new DeviceDescription * @return previous DeviceDescription */ public synchronized DeviceDescription putDeviceDesc(DeviceDescription newDesc) { DeviceDescription oldOne = deviceDesc.get(); DeviceDescription newOne = newDesc; if (oldOne != null) { SparseAnnotations merged = union(oldOne.annotations(), newDesc.annotations()); newOne = new DefaultDeviceDescription(newOne, merged); } return deviceDesc.getAndSet(newOne); }
boolean descriptionChanged = lastDescription == null || (!Objects.equals(thisDescription, lastDescription) || !Objects.equals(thisDescription.annotations(), lastDescription.annotations())); if (descriptionChanged || !deviceService.isAvailable(did)) { resetDeviceState(did);
@Override public DeviceDescription combine(DeviceId deviceId, DeviceDescription descr, Optional<Config> prevConfig) { DeviceAnnotationConfig cfg = lookupConfig(deviceId); if (cfg == null) { return descr; } Map<String, String> annotations = cfg.annotations(); Builder builder = DefaultAnnotations.builder(); builder.putAll(descr.annotations()); if (prevConfig.isPresent()) { DeviceAnnotationConfig prevDeviceAnnotationConfig = (DeviceAnnotationConfig) prevConfig.get(); for (String key : prevDeviceAnnotationConfig.annotations().keySet()) { if (!annotations.containsKey(key)) { builder.remove(key); } } } builder.putAll(annotations); return DefaultDeviceDescription.copyReplacingAnnotation(descr, builder.build()); }
ChassisId chassisId = base.chassisId(); DefaultAnnotations annotations = DefaultAnnotations.builder().build(); annotations = merge(annotations, base.annotations()); annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
SparseAnnotations sa = combine(cfg, descr.annotations()); return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer, hwVersion, swVersion,