Bug 499: Added support for change listeners.
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / ChangeListenerNotifyTask.java
1 package org.opendaylight.controller.md.sal.dom.store.impl;
2
3 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
4 import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerRegistrationNode.DataChangeListenerRegistration;
5 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
6 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 class ChangeListenerNotifyTask implements Runnable {
11
12     private static final Logger LOG = LoggerFactory.getLogger(ChangeListenerNotifyTask.class);
13     private final Iterable<DataChangeListenerRegistration<?>> listeners;
14     private final AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> event;
15
16     public ChangeListenerNotifyTask(final Iterable<DataChangeListenerRegistration<?>> listeners,
17             final AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> event) {
18         this.listeners = listeners;
19         this.event = event;
20     }
21
22     @Override
23     public void run() {
24
25         for (DataChangeListenerRegistration<?> listener : listeners) {
26             try {
27                 listener.getInstance().onDataChanged(event);
28             } catch (Exception e) {
29                 LOG.error("Unhandled exception during invoking listener {} with event {}", listener, event, e);
30             }
31         }
32
33     }
34
35 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.