blob: d2bee8b0911106fe9087ab9f7c8e5095c73a89d6 [file] [log] [blame]
Ayaka Koshibeabedb092014-10-20 17:01:31 -07001package org.onlab.onos.cluster;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07002
3import java.util.Collections;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07004import java.util.List;
5import java.util.Objects;
6
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07007/**
8 * A container for detailed role information for a device,
9 * within the current cluster. Role attributes include current
10 * master and a preference-ordered list of backup nodes.
11 */
12public class RoleInfo {
13 private final NodeId master;
14 private final List<NodeId> backups;
15
16 public RoleInfo(NodeId master, List<NodeId> backups) {
17 this.master = master;
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070018 this.backups = Collections.unmodifiableList(backups);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070019 }
20
21 public NodeId master() {
22 return master;
23 }
24
25 public List<NodeId> backups() {
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070026 return backups;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070027 }
28
29 @Override
30 public boolean equals(Object other) {
31 if (other == null) {
32 return false;
33 }
34 if (!(other instanceof RoleInfo)) {
35 return false;
36 }
37 RoleInfo that = (RoleInfo) other;
38 if (!Objects.equals(this.master, that.master)) {
39 return false;
40 }
41 if (!Objects.equals(this.backups, that.backups)) {
42 return false;
43 }
44 return true;
45 }
46
47 @Override
48 public int hashCode() {
49 return Objects.hash(master, backups.hashCode());
50 }
51
52 @Override
53 public String toString() {
54 final StringBuilder builder = new StringBuilder();
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070055 builder.append("master:").append(master).append(",");
56 builder.append("backups:");
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070057 for (NodeId n : backups) {
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070058 builder.append(" ").append(n);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070059 }
60 return builder.toString();
61 }
62}