X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fcommon%2Factor%2FQuarantinedMonitorActor.java;h=52df6ab7b388314879e72160890a624fc0104529;hp=8e2693e900dea8f2d0fa7bc1750eef126667d213;hb=0f02b7edeb1454c1a568f0f1b050757e7503ddf7;hpb=d486f486b118640e67733ca9a4db51368e05cc37 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 8e2693e900..52df6ab7b3 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 @@ -9,12 +9,9 @@ package org.opendaylight.controller.cluster.common.actor; import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.japi.Creator; +import akka.actor.UntypedAbstractActor; 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; @@ -23,23 +20,24 @@ import org.slf4j.LoggerFactory; * quarantined by another. Once this node gets quarantined, restart the ActorSystem to allow this * node to rejoin the cluster. * - * @author Gary Wu + * @author Gary Wu gary.wu1@huawei.com * */ -public class QuarantinedMonitorActor extends UntypedActor { +public class QuarantinedMonitorActor extends UntypedAbstractActor { - private final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActor.class); + private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActor.class); public static final String ADDRESS = "quarantined-monitor"; 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,42 +46,26 @@ 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")) { - 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(); } } public static Props props(final Effect callback) { - return Props.create(new Creator() { - private static final long serialVersionUID = 1L; - - @Override - public QuarantinedMonitorActor create() throws Exception { - return new QuarantinedMonitorActor(callback); - } - }); + return Props.create(QuarantinedMonitorActor.class, callback); } - }