Bug 7521: Convert byte[] to ShardManagerSnapshot in DatastoreSnapshot
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataChangeListenerRegistrationActor.java
index bbeb13f936aebf59d4eea6f0eefa2fef72256d49..89062dc83c1735545b612ed767846688017a6567 100644 (file)
@@ -11,8 +11,8 @@ package org.opendaylight.controller.cluster.datastore;
 import akka.actor.PoisonPill;
 import akka.actor.Props;
 import akka.japi.Creator;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
-
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration;
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistrationReply;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
@@ -31,29 +31,35 @@ public class DataChangeListenerRegistrationActor extends AbstractUntypedActor {
     }
 
     @Override
-    public void handleReceive(Object message) throws Exception {
-        if (message.getClass().equals(CloseDataChangeListenerRegistration.SERIALIZABLE_CLASS)) {
-            closeListenerRegistration(
-                new CloseDataChangeListenerRegistration());
+    public void handleReceive(Object message) {
+        if (message instanceof CloseDataChangeListenerRegistration) {
+            closeListenerRegistration();
+        } else {
+            unknownMessage(message);
         }
     }
 
-    public static Props props(
-        final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>> registration) {
+    public static Props props(final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
+            NormalizedNode<?, ?>>> registration) {
         return Props.create(new DataChangeListenerRegistrationCreator(registration));
     }
 
-    private void closeListenerRegistration(
-        CloseDataChangeListenerRegistration message) {
+    private void closeListenerRegistration() {
         registration.close();
-        getSender()
-            .tell(new CloseDataChangeListenerRegistrationReply().toSerializable(), getSelf());
+
+        if (isValidSender(getSender())) {
+            getSender().tell(CloseDataChangeListenerRegistrationReply.INSTANCE, getSelf());
+        }
+
         getSelf().tell(PoisonPill.getInstance(), getSelf());
     }
 
     private static class DataChangeListenerRegistrationCreator
                                             implements Creator<DataChangeListenerRegistrationActor> {
         private static final long serialVersionUID = 1L;
+
+        @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but we don't "
+                + "create remote instances of this actor and thus don't need it to be Serializable.")
         final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
                                                            NormalizedNode<?, ?>>> registration;