Add sender actor to the ForwardingDataTreeChangeListener 59/90259/1
authorTibor Král <tibor.kral@pantheon.tech>
Thu, 4 Jun 2020 16:50:51 +0000 (18:50 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 5 Jun 2020 08:24:00 +0000 (08:24 +0000)
The ForwardingDataTreeChangeListener is created when a shard
registers new listener. It then sends dataTreeChanges to said listener
but doesn't specify the sender. The RootListenerActor however needs
to know which shard produced the DataTreeChanged message.

Signed-off-by: Tibor Král <tibor.kral@pantheon.tech>
Change-Id: I4971cfaefa10c3136e0ddcc350ec7e00e68e6b42

opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ForwardingDataTreeChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ForwardingDataTreeChangeListenerTest.java

index 348b2aa..09586b2 100644 (file)
@@ -37,7 +37,7 @@ final class DataTreeChangeListenerSupport extends LeaderLocalDelegateFactory<Reg
     void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) {
         final ActorSelection listenerActor = processListenerRegistrationMessage(message);
 
-        final DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor);
+        final DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor, getSelf());
 
         LOG.debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath());
 
index 73b5623..82a30b6 100644 (file)
@@ -12,6 +12,7 @@ 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.cluster.datastore.messages.OnInitialData;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
@@ -28,25 +29,28 @@ final class ForwardingDataTreeChangeListener implements DOMDataTreeChangeListene
     private static final Logger LOG = LoggerFactory.getLogger(ForwardingDataTreeChangeListener.class);
 
     private final ActorSelection actor;
+    private final ActorRef sendingActor;
 
-    ForwardingDataTreeChangeListener(final ActorSelection actor) {
+    ForwardingDataTreeChangeListener(final ActorSelection actor, @Nullable final ActorRef sendingActor) {
         this.actor = requireNonNull(actor, "actor should not be null");
+        this.sendingActor = sendingActor;
     }
 
     @Override
     public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
         LOG.debug("Sending DataTreeChanged to {}", actor);
-        actor.tell(new DataTreeChanged(changes), ActorRef.noSender());
+        actor.tell(new DataTreeChanged(changes), sendingActor);
     }
 
     @Override
     public void onInitialData() {
         LOG.debug("Sending OnInitialData to {}", actor);
-        actor.tell(OnInitialData.INSTANCE, ActorRef.noSender());
+        actor.tell(OnInitialData.INSTANCE, sendingActor);
     }
 
     @Override
     public String toString() {
-        return "ForwardingDataTreeChangeListener [actor=" + actor + "]";
+        return "ForwardingDataTreeChangeListener [actor=" + actor
+            + ", sending actor=" + (sendingActor != null ? sendingActor : "NO_SENDER") + "]";
     }
 }
index f9804c9..14a0c3a 100644 (file)
@@ -24,7 +24,7 @@ public class ForwardingDataTreeChangeListenerTest extends AbstractActorTest {
         final ActorRef actorRef = getSystem().actorOf(MessageCollectorActor.props());
 
         ForwardingDataTreeChangeListener forwardingListener = new ForwardingDataTreeChangeListener(
-                getSystem().actorSelection(actorRef.path()));
+                getSystem().actorSelection(actorRef.path()), ActorRef.noSender());
 
         Collection<DataTreeCandidate> expected = Arrays.asList(Mockito.mock(DataTreeCandidate.class));
         forwardingListener.onDataTreeChanged(expected);

©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.