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=ed0c10a7172b8edeb759819f8ddf1dc861b87ea1;hb=HEAD;hp=598dfb1fe827fe8b03234003dc5d0bdf7c750223;hpb=6dcee56392712348b1abdcdc0d1d5f94dfcf505c;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 598dfb1fe8..ed0c10a717 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,31 +5,31 @@ * 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.ActorPath; import akka.actor.ActorRef; import akka.actor.Props; 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 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 final String memberId; - private final Map registeredListeners = Maps.newHashMap(); + 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; } @@ -45,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 @@ -63,7 +63,7 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos getSender().tell(new RegisterRoleChangeListenerReply(), getSelf()); - if(latestLeaderStateChanged != null) { + if (latestLeaderStateChanged != null) { getSender().tell(latestLeaderStateChanged, getSelf()); } @@ -72,9 +72,8 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos } - } 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()); @@ -83,20 +82,22 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos new RoleChangeNotification(roleChanged.getMemberId(), roleChanged.getOldRole(), roleChanged.getNewRole()); - for (ActorRef listener: registeredListeners.values()) { + for (ActorRef listener : registeredListeners.values()) { listener.tell(latestRoleChangeNotification, getSelf()); } - } else if (message instanceof LeaderStateChanged) { - latestLeaderStateChanged = (LeaderStateChanged)message; + } else if (message instanceof LeaderStateChanged leaderStateChanged) { + latestLeaderStateChanged = leaderStateChanged; - for (ActorRef listener: registeredListeners.values()) { + for (ActorRef listener : registeredListeners.values()) { listener.tell(latestLeaderStateChanged, getSelf()); } + } else { + unknownMessage(message); } } @Override - public void close() throws Exception { + public void close() { registeredListeners.clear(); } }