BUG 5656 : Entity ownership candidates not removed consistently on leadership change
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ClusterWrapperImpl.java
index 8910137ec4583272b55ead555b0ed12e11caa02c..df0128cb56ce32e3f3deca0545915acc89c45120 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore;
 
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
+import akka.actor.Address;
 import akka.cluster.Cluster;
 import akka.cluster.ClusterEvent;
 import com.google.common.base.Preconditions;
@@ -17,6 +18,7 @@ import com.google.common.base.Preconditions;
 public class ClusterWrapperImpl implements ClusterWrapper {
     private final Cluster cluster;
     private final String currentMemberName;
+    private final Address selfAddress;
 
     public ClusterWrapperImpl(ActorSystem actorSystem){
         Preconditions.checkNotNull(actorSystem, "actorSystem should not be null");
@@ -30,19 +32,27 @@ public class ClusterWrapperImpl implements ClusterWrapper {
                 "member-3 here would be the name of the member"
         );
 
-        currentMemberName = (String) cluster.getSelfRoles().toArray()[0];
-
+        currentMemberName = cluster.getSelfRoles().iterator().next();
+        selfAddress = cluster.selfAddress();
     }
 
+    @Override
     public void subscribeToMemberEvents(ActorRef actorRef){
         Preconditions.checkNotNull(actorRef, "actorRef should not be null");
 
         cluster.subscribe(actorRef, ClusterEvent.initialStateAsEvents(),
             ClusterEvent.MemberEvent.class,
-            ClusterEvent.UnreachableMember.class);
+            ClusterEvent.UnreachableMember.class,
+            ClusterEvent.ReachableMember.class);
     }
 
+    @Override
     public String getCurrentMemberName() {
         return currentMemberName;
     }
+
+    @Override
+    public Address getSelfAddress() {
+        return selfAddress;
+    }
 }