// called under "this" lock @Override public synchronized Alert[] getAlertsByGroupUid(String groupUid) { for (AlertGroup alertGroup : alertGroupList) { if (alertGroup.getGroupUid().equals(groupUid)) { return alertGroup.toArray(); } } return new Alert[0]; }
// called under "this" lock private void mapAlertByGroupUid(Alert alert) { AlertGroup alertGroup = alertGroupByGroupUidMapping.get(alert.getGroupUid()); boolean needsNewAlertGroup = (alertGroup != null && alertGroup.isResolved()); if (alertGroup == null || needsNewAlertGroup) { alertGroup = new AlertGroup(); alertGroup.addAlert(alert); alertGroupByGroupUidMapping.put(alert.getGroupUid(), alertGroup); alertGroupList.addFirst(alertGroup); } else { alertGroup.addAlert(alert); alertGroupList.remove(alertGroup); alertGroupList.addFirst(alertGroup); } }
// called under "this" lock private void ensureStoreLimit() { if (size() <= storeLimit) { return; } /* * Look for candidate - an alert still unresolved - we can remove only alerts inside the group. */ boolean removed = false; for (int i = (alertGroupList.size() - 1); i >= 0; --i) { AlertGroup alertGroup = alertGroupList.get(i); if (alertGroup.isUnResolved()) { /* * don't remove first and last alert! * First alert (index 0) indicates the last alert from the group. * Last alert (index size -1) indicates the first alert to open the group. */ for (int j = (alertGroup.alertsInGroupList.size() - 2); j > 0; j -= 2) { alertGroup.alertsInGroupList.remove(j); removed = true; } if (removed) { break; } } } if (!removed) { // remove whatever is in last position. AlertGroup lastAlertGroup = alertGroupList.removeLast(); /* * last alert group may differ from the mapped one since a new group may have been created * since then. Only remove if they equal! */ AlertGroup mappedAlertGroup = alertGroupByGroupUidMapping.get(lastAlertGroup.getGroupUid()); if (mappedAlertGroup == lastAlertGroup) { alertGroupByGroupUidMapping.remove(lastAlertGroup.getGroupUid()); } } }