Eliminate dead letters message when there's no sender 41/41241/2
authorTom Pantelis <tpanteli@brocade.com>
Thu, 23 Jun 2016 18:15:17 +0000 (14:15 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 5 Jul 2016 17:20:23 +0000 (17:20 +0000)
When sending a message to close a DTCL or DCL registration, if the caller
isn't interested in the reply, it passes ActorRef.noSender() (ie null). Internally
akka translates this to the dead letters actor so you see log messages
of the form "Message [...CloseDataTreeChangeListenerRegistrationReply]
from Actor[...] to Actor[akka://opendaylight-cluster-data/deadLetters] was not
delivered. [1] dead letters encountered.".

To alleviate this we should check if the sender is the dead letters actor
before sending the reply.

Change-Id: Idfaf280acf720cf5727393262638a7783c1af539
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerRegistrationActor.java

index dffb610..ca303a5 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.controller.cluster.common.actor;
 
+import akka.actor.ActorRef;
 import akka.actor.UntypedActor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,4 +43,10 @@ public abstract class AbstractUntypedActor extends UntypedActor {
         LOG.debug("Received unhandled message {}", message);
         unhandled(message);
     }
+
+    protected boolean isValidSender(ActorRef sender) {
+        // If the caller passes in a null sender (ActorRef.noSender()), akka translates that to the
+        // deadLetters actor.
+        return sender != null && !getContext().system().deadLetters().equals(sender);
+    }
 }
index 7f98526..d572beb 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
 import org.opendaylight.controller.cluster.datastore.messages.DataChanged;
 import org.opendaylight.controller.cluster.datastore.messages.DataChangedReply;
 import org.opendaylight.controller.cluster.datastore.messages.EnableNotification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -72,9 +73,7 @@ public class DataChangeListener extends AbstractUntypedActor {
             LOG.error( String.format( "Error notifying listener %s", this.listener ), e );
         }
 
-        // It seems the sender is never null but it doesn't hurt to check. If the caller passes in
-        // a null sender (ActorRef.noSender()), akka translates that to the deadLetters actor.
-        if(getSender() != null && !getContext().system().deadLetters().equals(getSender())) {
+        if(isValidSender(getSender())) {
             getSender().tell(DataChangedReply.INSTANCE, getSelf());
         }
     }
index 2632498..29e4a1a 100644 (file)
@@ -45,7 +45,11 @@ public class DataChangeListenerRegistrationActor extends AbstractUntypedActor {
 
     private void closeListenerRegistration() {
         registration.close();
-        getSender().tell(CloseDataChangeListenerRegistrationReply.INSTANCE, getSelf());
+
+        if(isValidSender(getSender())) {
+            getSender().tell(CloseDataChangeListenerRegistrationReply.INSTANCE, getSelf());
+        }
+
         getSelf().tell(PoisonPill.getInstance(), getSelf());
     }
 
index 2a106b4..5994f30 100644 (file)
@@ -32,7 +32,10 @@ public final class DataTreeChangeListenerRegistrationActor extends AbstractUntyp
     protected void handleReceive(Object message) throws Exception {
         if (message instanceof CloseDataTreeChangeListenerRegistration) {
             registration.close();
-            getSender().tell(CloseDataTreeChangeListenerRegistrationReply.getInstance(), getSelf());
+            if(isValidSender(getSender())) {
+                getSender().tell(CloseDataTreeChangeListenerRegistrationReply.getInstance(), getSelf());
+            }
+
             getSelf().tell(PoisonPill.getInstance(), getSelf());
         } else {
             unknownMessage(message);