Add sender actor to the ForwardingDataTreeChangeListener
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ForwardingDataTreeChangeListener.java
index 7ca21d4d8a6a3b9e0ba13ae783ef2468b3c2c383..82a30b6c4050e59c02e6c873717f11023e51eebb 100644 (file)
@@ -7,13 +7,18 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import java.util.Collection;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
+import org.opendaylight.controller.cluster.datastore.messages.OnInitialData;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Internal implementation of a {@link DOMDataTreeChangeListener} which
@@ -21,14 +26,31 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
  * message and forwards them towards the client's {@link DataTreeChangeListenerActor}.
  */
 final class ForwardingDataTreeChangeListener implements DOMDataTreeChangeListener {
+    private static final Logger LOG = LoggerFactory.getLogger(ForwardingDataTreeChangeListener.class);
+
     private final ActorSelection actor;
+    private final ActorRef sendingActor;
+
+    ForwardingDataTreeChangeListener(final ActorSelection actor, @Nullable final ActorRef sendingActor) {
+        this.actor = requireNonNull(actor, "actor should not be null");
+        this.sendingActor = sendingActor;
+    }
 
-    ForwardingDataTreeChangeListener(final ActorSelection actor) {
-        this.actor = Preconditions.checkNotNull(actor, "actor should not be null");
+    @Override
+    public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
+        LOG.debug("Sending DataTreeChanged to {}", actor);
+        actor.tell(new DataTreeChanged(changes), sendingActor);
+    }
+
+    @Override
+    public void onInitialData() {
+        LOG.debug("Sending OnInitialData to {}", actor);
+        actor.tell(OnInitialData.INSTANCE, sendingActor);
     }
 
     @Override
-    public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
-        actor.tell(new DataTreeChanged(changes), ActorRef.noSender());
+    public String toString() {
+        return "ForwardingDataTreeChangeListener [actor=" + actor
+            + ", sending actor=" + (sendingActor != null ? sendingActor : "NO_SENDER") + "]";
     }
 }