private Map<AlertTargetEntity, List<AlertNoticeEntity>> getGroupedNotices() {
    List<AlertNoticeEntity> pending = m_dao.findPendingNotices();
    if (pending.size() == 0) {
      return Collections.EMPTY_MAP;
    }

    LOG.info("There are {} pending alert notices about to be dispatched...",
        pending.size());

    Map<AlertTargetEntity, List<AlertNoticeEntity>> aggregateMap = new HashMap<>(pending.size());

    // combine all histories by target
    for (AlertNoticeEntity notice : pending) {
      AlertTargetEntity target = notice.getAlertTarget();

      List<AlertNoticeEntity> notices = aggregateMap.get(target);
      if (null == notices) {
        notices = new ArrayList<>();
        aggregateMap.put(target, notices);
      }

      // at this point, notices have been processed but not yet delivered
      notice.setNotifyState(NotificationState.DISPATCHED);
      notice = m_dao.merge(notice);

      notices.add(notice);
    }
    return aggregateMap;
  }
Retrieves all pending notices to dispatch and groups them by target.
@return grouped notices.
ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java