X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fnotifications%2FRoleChangeNotifier.java;h=01f3827da78685e7e1312d7016f3e2015d0d7156;hb=544f0ea584563a7398111d74eb7e89140ac02613;hp=a9aa56174d84a4309c27560dbd1be26c4603de34;hpb=e28a4a816d824e65d12b81a7d0e7017dd6f4c919;p=controller.git
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java
index a9aa56174d..01f3827da7 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java
@@ -5,42 +5,36 @@
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.notifications;
-import akka.actor.Actor;
import akka.actor.ActorPath;
import akka.actor.ActorRef;
import akka.actor.Props;
-import akka.japi.Creator;
import akka.serialization.Serialization;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
import java.util.Map;
import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
/**
- * The RoleChangeNotifier is responsible for receiving Raft role change messages and notifying
+ * The RoleChangeNotifier is responsible for receiving Raft role and leader state change messages and notifying
* the listeners (within the same node), which are registered with it.
- *
+ *
+ *
* The RoleChangeNotifier is instantiated by the Shard and injected into the RaftActor.
*/
public class RoleChangeNotifier extends AbstractUntypedActor implements AutoCloseable {
- private String memberId;
- private Map registeredListeners = Maps.newHashMap();
+ private final String memberId;
+ private final Map registeredListeners = new HashMap<>();
private RoleChangeNotification latestRoleChangeNotification = null;
+ private LeaderStateChanged latestLeaderStateChanged;
- public RoleChangeNotifier(String memberId) {
+ public RoleChangeNotifier(final String memberId) {
this.memberId = memberId;
}
public static Props getProps(final String memberId) {
- return Props.create(new Creator() {
- @Override
- public Actor create() throws Exception {
- return new RoleChangeNotifier(memberId);
- }
- });
+ return Props.create(RoleChangeNotifier.class, memberId);
}
@Override
@@ -51,7 +45,7 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos
}
@Override
- protected void handleReceive(Object message) throws Exception {
+ protected void handleReceive(final Object message) {
if (message instanceof RegisterRoleChangeListener) {
// register listeners for this shard
@@ -69,14 +63,17 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos
getSender().tell(new RegisterRoleChangeListenerReply(), getSelf());
+ if (latestLeaderStateChanged != null) {
+ getSender().tell(latestLeaderStateChanged, getSelf());
+ }
+
if (latestRoleChangeNotification != null) {
getSender().tell(latestRoleChangeNotification, getSelf());
}
- } else if (message instanceof RoleChanged) {
+ } else if (message instanceof RoleChanged roleChanged) {
// this message is sent by RaftActor. Notify registered listeners when this message is received.
- RoleChanged roleChanged = (RoleChanged) message;
LOG.info("RoleChangeNotifier for {} , received role change from {} to {}", memberId,
roleChanged.getOldRole(), roleChanged.getNewRole());
@@ -88,11 +85,19 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos
for (ActorRef listener: registeredListeners.values()) {
listener.tell(latestRoleChangeNotification, getSelf());
}
+ } else if (message instanceof LeaderStateChanged leaderStateChanged) {
+ latestLeaderStateChanged = leaderStateChanged;
+
+ for (ActorRef listener : registeredListeners.values()) {
+ listener.tell(latestLeaderStateChanged, getSelf());
+ }
+ } else {
+ unknownMessage(message);
}
}
@Override
- public void close() throws Exception {
+ public void close() {
registeredListeners.clear();
}
}