package org.opendaylight.controller.cluster.common.actor;
+import akka.actor.Address;
import akka.actor.Props;
import akka.actor.UntypedAbstractActor;
import akka.japi.Effect;
+import akka.remote.AssociationErrorEvent;
+import akka.remote.RemotingLifecycleEvent;
import akka.remote.ThisActorSystemQuarantinedEvent;
+import java.util.HashSet;
+import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
*/
public class QuarantinedMonitorActor extends UntypedAbstractActor {
+ public static final String ADDRESS = "quarantined-monitor";
private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActor.class);
-
- public static final String ADDRESS = "quarantined-monitor";
+ private static final Integer MESSAGE_THRESHOLD = 10;
private final Effect callback;
private boolean quarantined;
+ private Set<Address> addressSet = new HashSet<>();
+ private int count = 0;
+
protected QuarantinedMonitorActor(final Effect callback) {
this.callback = callback;
LOG.debug("Created QuarantinedMonitorActor");
- getContext().system().eventStream().subscribe(getSelf(), ThisActorSystemQuarantinedEvent.class);
+ getContext().system().eventStream().subscribe(getSelf(), RemotingLifecycleEvent.class);
}
@Override
// execute the callback
callback.apply();
+ } else if (message instanceof AssociationErrorEvent) {
+ String errorMessage = message.toString();
+ LOG.trace("errorMessage:{}", errorMessage);
+ if (errorMessage.contains("The remote system has a UID that has been quarantined")) {
+ Address address = ((AssociationErrorEvent) message).getRemoteAddress();
+ addressSet.add(address);
+ count++;
+ LOG.trace("address:{} addressSet: {} count:{}", address, addressSet, count);
+ if (count >= MESSAGE_THRESHOLD && addressSet.size() > 1) {
+ count = 0;
+ addressSet.clear();
+ final AssociationErrorEvent event = (AssociationErrorEvent) message;
+ LOG.warn("Got quarantined via AssociationEvent by {}", event.remoteAddress());
+ quarantined = true;
+
+ // execute the callback
+ callback.apply();
+ }
+ } else if (errorMessage.contains("The remote system explicitly disassociated")) {
+ count = 0;
+ addressSet.clear();
+ }
}
}