Remove meters when the device is removed or becomes unavailable.
Amendments:
Rename removeAllMeters to removeDeviceMetersFromBpMap.
Change-Id: I202c99f9a3fc84d5503273c62efae51fd5d6ddf7
diff --git a/app/src/main/java/org/opencord/olt/impl/Olt.java b/app/src/main/java/org/opencord/olt/impl/Olt.java
index 4775cc9..9d5240f 100644
--- a/app/src/main/java/org/opencord/olt/impl/Olt.java
+++ b/app/src/main/java/org/opencord/olt/impl/Olt.java
@@ -1751,6 +1751,7 @@
AccessDeviceEvent.Type.UNI_REMOVED, devId, p)));
programmedDevices.remove(devId);
removeAllSubscribers(devId);
+ removeDeviceMetersFromBpMap(devId);
post(new AccessDeviceEvent(
AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
null, null));
@@ -1765,6 +1766,7 @@
} else {
programmedDevices.remove(devId);
removeAllSubscribers(devId);
+ removeDeviceMetersFromBpMap(devId);
post(new AccessDeviceEvent(
AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
null, null));
@@ -1794,6 +1796,18 @@
connectPoints.forEach(cp -> programmedSubs.remove(cp));
}
+
+ private void removeDeviceMetersFromBpMap(DeviceId deviceId) {
+ bpInfoToMeter.values().forEach(meterKeys -> meterKeys.stream()
+ .filter(meterKey -> meterKey.deviceId().equals(deviceId)).findFirst().
+ ifPresent(mk -> {
+ meterKeys.remove(mk);
+ programmedMeters.remove(mk);
+ log.info("Deleted from the internal map. MeterKey {}", mk);
+ log.info("Programmed meters {}", programmedMeters);
+ }));
+ }
+
}
private class InternalMeterListener implements MeterListener {
@@ -1843,4 +1857,4 @@
}));
}
}
-}
\ No newline at end of file
+}