Split out TransactionContext classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ClusterWrapperImpl.java
index 142aacde65c32f1050846810c8d33b1c9122be55..d7bfae1b42b88a36be7a9e29124af53231111757 100644 (file)
@@ -10,20 +10,35 @@ 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;
 
 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");
+
         cluster = Cluster.get(actorSystem);
-        currentMemberName = (String) cluster.getSelfRoles().toArray()[0];
 
+        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 = 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(),
             ClusterEvent.MemberEvent.class,
             ClusterEvent.UnreachableMember.class);
@@ -32,4 +47,8 @@ public class ClusterWrapperImpl implements ClusterWrapper {
     public String getCurrentMemberName() {
         return currentMemberName;
     }
+
+    public Address getSelfAddress() {
+        return selfAddress;
+    }
 }