Search in sources :

Example 6 with Alert

use of org.codice.ddf.system.alerts.Alert in project ddf by codice.

the class AlertListener method handleEvent.

/**
 * Processes alert events and stores them in the persistent store. Because this handler 'squashes'
 * alerts into one entry it needs to be synchronized to be thread safe.
 *
 * @param event The osgi alert event
 * @throws IllegalArgumentException
 */
@Override
public synchronized void handleEvent(Event event) throws IllegalArgumentException {
    if (Alert.ALERT_DISMISS_TOPIC.equals(event.getTopic())) {
        dismissAlert(event);
        return;
    }
    // need source to lookup previous alerts
    if (event.getProperty(Alert.SYSTEM_NOTICE_SOURCE_KEY) == null) {
        return;
    }
    LOGGER.debug("Received alert event on topic {}", event.getTopic());
    Alert alert = getAlertFromEvent(event);
    Alert existingAlert = getAlertBySource(alert.getSource());
    if (existingAlert != null) {
        Map<String, Object> properties = alert.getProperties();
        properties.put(Alert.SYSTEM_NOTICE_ID_KEY, existingAlert.getId());
        properties.put(Alert.ALERT_COUNT, existingAlert.getCount() + 1);
        properties.put(Alert.SYSTEM_NOTICE_TIME_KEY, existingAlert.getTime());
        alert = new Alert(properties);
    }
    addAlertToStore(alert);
}
Also used : Alert(org.codice.ddf.system.alerts.Alert)

Aggregations

Alert (org.codice.ddf.system.alerts.Alert)6 HashSet (java.util.HashSet)3 PersistentItem (org.codice.ddf.persistence.PersistentItem)3 Test (org.junit.Test)3 Event (org.osgi.service.event.Event)3 HashMap (java.util.HashMap)2 SystemNotice (org.codice.ddf.system.alerts.SystemNotice)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PersistenceException (org.codice.ddf.persistence.PersistenceException)1