NormalizedNodeAggregator should also report empty
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ClusterWrapperImpl.java
index 857510ad4b5360ef3870ac16bce00e188cee88a7..be162d9304ee205d5fde8afee03f72d822d81296 100644 (file)
@@ -5,50 +5,51 @@
  * 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.datastore;
 
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 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;
+import org.opendaylight.controller.cluster.access.concepts.MemberName;
 
 public class ClusterWrapperImpl implements ClusterWrapper {
     private final Cluster cluster;
-    private final String currentMemberName;
-    private final String selfAddress;
-
-    public ClusterWrapperImpl(ActorSystem actorSystem){
-        Preconditions.checkNotNull(actorSystem, "actorSystem should not be null");
+    private final MemberName currentMemberName;
+    private final Address selfAddress;
 
-        cluster = Cluster.get(actorSystem);
+    public ClusterWrapperImpl(final ActorSystem actorSystem) {
+        cluster = Cluster.get(requireNonNull(actorSystem, "actorSystem should not be null"));
 
-        Preconditions.checkState(cluster.getSelfRoles().size() > 0,
-            "No akka roles were specified\n" +
-                "One way to specify the member name is to pass a property on the command line like so\n" +
-                "   -Dakka.cluster.roles.0=member-3\n" +
-                "member-3 here would be the name of the member"
-        );
-
-        currentMemberName = (String) cluster.getSelfRoles().toArray()[0];
-        selfAddress = cluster.selfAddress().toString();
+        checkState(cluster.getSelfRoles().size() > 0,
+            "No akka roles were specified.\n"
+            + "One way to specify the member name is to pass a property on the command line like so\n"
+            + "   -Dakka.cluster.roles.0=member-3\n"
+            + "member-3 here would be the name of the member");
 
+        currentMemberName = MemberName.forName(cluster.getSelfRoles().iterator().next());
+        selfAddress = cluster.selfAddress();
     }
 
-    public void subscribeToMemberEvents(ActorRef actorRef){
-        Preconditions.checkNotNull(actorRef, "actorRef should not be null");
-
-        cluster.subscribe(actorRef, ClusterEvent.initialStateAsEvents(),
+    @Override
+    public void subscribeToMemberEvents(final ActorRef actorRef) {
+        cluster.subscribe(requireNonNull(actorRef, "actorRef should not be null"), ClusterEvent.initialStateAsEvents(),
             ClusterEvent.MemberEvent.class,
-            ClusterEvent.UnreachableMember.class);
+            ClusterEvent.UnreachableMember.class,
+            ClusterEvent.ReachableMember.class);
     }
 
-    public String getCurrentMemberName() {
+    @Override
+    public MemberName getCurrentMemberName() {
         return currentMemberName;
     }
 
-    public String getSelfAddress() {
+    @Override
+    public Address getSelfAddress() {
         return selfAddress;
     }
 }