From a8349006607d36efd79fa58448cf8887c9fdbcf0 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 17 Jul 2017 14:57:08 +0200 Subject: [PATCH] Simplify QuarantinedMonitorActor 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 --- .../common/actor/QuarantinedMonitorActor.java | 36 ++++++------------- .../actor/QuarantinedMonitorActorTest.java | 3 +- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActor.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActor.java index 519fcd071c..2ed5a24f53 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActor.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActor.java @@ -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(); } } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActorTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActorTest.java index bf5b9fca52..f3a453bf4f 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActorTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActorTest.java @@ -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(); } -- 2.36.6