2 * Copyright (c) 2015 Huawei Technologies Co., Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.common.actor;
11 import akka.actor.Props;
12 import akka.actor.UntypedActor;
13 import akka.japi.Effect;
14 import akka.remote.ThisActorSystemQuarantinedEvent;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * This class listens to Akka RemotingLifecycleEvent events to detect when this node has been
20 * quarantined by another. Once this node gets quarantined, restart the ActorSystem to allow this
21 * node to rejoin the cluster.
23 * @author Gary Wu gary.wu1@huawei.com
26 public class QuarantinedMonitorActor extends UntypedActor {
28 private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActor.class);
30 public static final String ADDRESS = "quarantined-monitor";
32 private final Effect callback;
33 private boolean quarantined;
35 protected QuarantinedMonitorActor(final Effect callback) {
36 this.callback = callback;
38 LOG.debug("Created QuarantinedMonitorActor");
40 getContext().system().eventStream().subscribe(getSelf(), ThisActorSystemQuarantinedEvent.class);
44 public void postStop() {
45 LOG.debug("Stopping QuarantinedMonitorActor");
49 public void onReceive(final Object message) throws Exception {
50 final String messageType = message.getClass().getSimpleName();
51 LOG.trace("onReceive {} {}", messageType, message);
53 // check to see if we got quarantined by another node
58 if (message instanceof ThisActorSystemQuarantinedEvent) {
59 final ThisActorSystemQuarantinedEvent event = (ThisActorSystemQuarantinedEvent) message;
60 LOG.warn("Got quarantined by {}", event.remoteAddress());
63 // execute the callback
68 public static Props props(final Effect callback) {
69 return Props.create(QuarantinedMonitorActor.class, callback);