Rename ActorContext to ActorUtils
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataTreeChangeListenerActor.java
index 902156f3468867df4986bc159407fc139072a282..c72de945b15154c67c4c1002cd736a72d56aabaa 100644 (file)
@@ -12,8 +12,11 @@ import com.google.common.base.Preconditions;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
 import org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged;
 import org.opendaylight.controller.cluster.datastore.messages.DataTreeChangedReply;
+import org.opendaylight.controller.cluster.datastore.messages.DataTreeListenerInfo;
 import org.opendaylight.controller.cluster.datastore.messages.EnableNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
+import org.opendaylight.controller.cluster.datastore.messages.GetInfo;
+import org.opendaylight.controller.cluster.datastore.messages.OnInitialData;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 /**
@@ -24,6 +27,7 @@ final class DataTreeChangeListenerActor extends AbstractUntypedActor {
     private final DOMDataTreeChangeListener listener;
     private final YangInstanceIdentifier registeredPath;
     private boolean notificationsEnabled = false;
+    private long notificationCount;
     private String logContext = "";
 
     private DataTreeChangeListenerActor(final DOMDataTreeChangeListener listener,
@@ -36,13 +40,29 @@ final class DataTreeChangeListenerActor extends AbstractUntypedActor {
     protected void handleReceive(final Object message) {
         if (message instanceof DataTreeChanged) {
             dataChanged((DataTreeChanged)message);
+        } else if (message instanceof OnInitialData) {
+            onInitialData();
         } else if (message instanceof EnableNotification) {
             enableNotification((EnableNotification) message);
+        } else if (message instanceof GetInfo) {
+            getSender().tell(new DataTreeListenerInfo(listener.toString(), registeredPath.toString(),
+                    notificationsEnabled, notificationCount), getSelf());
         } else {
             unknownMessage(message);
         }
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void onInitialData() {
+        LOG.debug("{}: Notifying onInitialData to listener {}", logContext, listener);
+
+        try {
+            this.listener.onInitialData();
+        } catch (Exception e) {
+            LOG.error("{}: Error notifying listener {}", logContext, this.listener, e);
+        }
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     private void dataChanged(final DataTreeChanged message) {
         // Do nothing if notifications are not enabled
@@ -55,6 +75,8 @@ final class DataTreeChangeListenerActor extends AbstractUntypedActor {
         LOG.debug("{}: Sending {} change notification(s) {} to listener {}", logContext, message.getChanges().size(),
                 message.getChanges(), listener);
 
+        notificationCount++;
+
         try {
             this.listener.onDataTreeChanged(message.getChanges());
         } catch (Exception e) {