Search in sources :

Example 1 with InboxListener

use of org.eclipse.smarthome.config.discovery.inbox.InboxListener in project smarthome by eclipse.

the class PersistentInbox method notifyListeners.

private void notifyListeners(DiscoveryResult result, EventType type) {
    for (InboxListener listener : this.listeners) {
        try {
            switch(type) {
                case added:
                    listener.thingAdded(this, result);
                    break;
                case removed:
                    listener.thingRemoved(this, result);
                    break;
                case updated:
                    listener.thingUpdated(this, result);
                    break;
            }
        } catch (Exception ex) {
            String errorMessage = String.format("Cannot notify the InboxListener '%s' about a Thing %s event!", listener.getClass().getName(), type.name());
            logger.error(errorMessage, ex);
        }
    }
    // in case of EventType added/updated the listeners might have modified the result in the discoveryResultStorage
    DiscoveryResult resultForEvent = type == EventType.removed ? result : get(result.getThingUID());
    postEvent(resultForEvent, type);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) InboxListener(org.eclipse.smarthome.config.discovery.inbox.InboxListener)

Aggregations

DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)1 InboxListener (org.eclipse.smarthome.config.discovery.inbox.InboxListener)1