Leadership construct includes List of NodeIds to describe current
leader/backups (candidates) for a topic. This includes removing the RoleInfo in
LeadershipEvent, to deduplicate information.
RoleInfo is also made a bit saner with the Optional leader field.
part of: Device Mastership store on top of LeadershipService
Reference: ONOS-76
Change-Id: I957c4d79125873d5a7280f60231d26d2806ab27f
diff --git a/core/api/src/main/java/org/onosproject/cluster/RoleInfo.java b/core/api/src/main/java/org/onosproject/cluster/RoleInfo.java
index a02cda9..f7ffc9b 100644
--- a/core/api/src/main/java/org/onosproject/cluster/RoleInfo.java
+++ b/core/api/src/main/java/org/onosproject/cluster/RoleInfo.java
@@ -17,6 +17,7 @@
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
@@ -27,21 +28,22 @@
* master and a preference-ordered list of backup nodes.
*/
public class RoleInfo {
- private final NodeId master;
+ private final Optional<NodeId> master;
private final List<NodeId> backups;
public RoleInfo(NodeId master, List<NodeId> backups) {
- this.master = master;
+ this.master = Optional.ofNullable(master);
this.backups = ImmutableList.copyOf(backups);
}
public RoleInfo() {
- this.master = null;
+ this.master = Optional.empty();
this.backups = ImmutableList.of();
}
+ // This will return a Optional<NodeId> in the future.
public NodeId master() {
- return master;
+ return master.orElseGet(() -> null);
}
public List<NodeId> backups() {
@@ -74,7 +76,7 @@
@Override
public String toString() {
return MoreObjects.toStringHelper(this.getClass())
- .add("master", master)
+ .add("master", master.orElseGet(() -> null))
.add("backups", backups)
.toString();
}