Simplify QuarantinedMonitorActor 84/60484/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Jul 2017 12:57:08 +0000 (14:57 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Tue, 18 Jul 2017 14:23:09 +0000 (14:23 +0000)
As per the comments, upstream has provided a dedicated event, hence
use that instead of digging inside akka internals.

Change-Id: I4731dfbbdd228d562ddd32ec5fd3d0e9af0855d0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActor.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActorTest.java

index 519fcd0..2ed5a24 100644 (file)
@@ -11,9 +11,7 @@ package org.opendaylight.controller.cluster.common.actor;
 import akka.actor.Props;
 import akka.actor.UntypedActor;
 import akka.japi.Effect;
-import akka.remote.AssociationErrorEvent;
-import akka.remote.InvalidAssociation;
-import akka.remote.RemotingLifecycleEvent;
+import akka.remote.ThisActorSystemQuarantinedEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,12 +32,12 @@ public class QuarantinedMonitorActor extends UntypedActor {
     private final Effect callback;
     private boolean quarantined;
 
-    protected QuarantinedMonitorActor(Effect callback) {
+    protected QuarantinedMonitorActor(final Effect callback) {
         this.callback = callback;
 
         LOG.debug("Created QuarantinedMonitorActor");
 
-        getContext().system().eventStream().subscribe(getSelf(), RemotingLifecycleEvent.class);
+        getContext().system().eventStream().subscribe(getSelf(), ThisActorSystemQuarantinedEvent.class);
     }
 
     @Override
@@ -48,36 +46,22 @@ public class QuarantinedMonitorActor extends UntypedActor {
     }
 
     @Override
-    public void onReceive(Object message) throws Exception {
+    public void onReceive(final Object message) throws Exception {
         final String messageType = message.getClass().getSimpleName();
         LOG.trace("onReceive {} {}", messageType, message);
 
         // check to see if we got quarantined by another node
-
         if (quarantined) {
             return;
         }
 
-        // TODO: follow https://github.com/akka/akka/issues/18758 to see if Akka adds a named
-        // exception for quarantine detection
-        if (message instanceof AssociationErrorEvent) {
-            AssociationErrorEvent event = (AssociationErrorEvent) message;
-            Throwable cause = event.getCause();
-            if (cause instanceof InvalidAssociation) {
-                Throwable cause2 = ((InvalidAssociation) cause).getCause();
-                if (cause2.getMessage().contains("quarantined this system")) {
-                    quarantined = true;
-
-                    LOG.warn("Got quarantined by {}", event.getRemoteAddress());
+        if (message instanceof ThisActorSystemQuarantinedEvent) {
+            final ThisActorSystemQuarantinedEvent event = (ThisActorSystemQuarantinedEvent) message;
+            LOG.warn("Got quarantined by {}", event.remoteAddress());
+            quarantined = true;
 
-                    // execute the callback
-                    callback.apply();
-                } else {
-                    LOG.debug("received AssociationErrorEvent, cause: InvalidAssociation", cause2);
-                }
-            } else {
-                LOG.debug("received AssociationErrorEvent", cause);
-            }
+            // execute the callback
+            callback.apply();
         }
     }
 
index bf5b9fc..f3a453b 100644 (file)
@@ -18,6 +18,7 @@ import akka.event.Logging;
 import akka.japi.Effect;
 import akka.remote.AssociationErrorEvent;
 import akka.remote.InvalidAssociation;
+import akka.remote.ThisActorSystemQuarantinedEvent;
 import akka.testkit.JavaTestKit;
 import org.junit.After;
 import org.junit.Before;
@@ -52,7 +53,7 @@ public class QuarantinedMonitorActorTest {
     public void testOnReceiveQuarantined() throws Exception {
         final Throwable t = new RuntimeException("Remote has quarantined this system");
         final InvalidAssociation cause = InvalidAssociation.apply(LOCAL, REMOTE, t, Option.apply(null));
-        final AssociationErrorEvent event = new AssociationErrorEvent(cause, LOCAL, REMOTE, true, Logging.ErrorLevel());
+        final ThisActorSystemQuarantinedEvent event = new ThisActorSystemQuarantinedEvent(LOCAL, REMOTE);
         actor.tell(event, ActorRef.noSender());
         verify(callback, timeout(1000)).apply();
     }

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