blob: bf7442ee0adf281af2693b7a1afd3469540cba85 [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;
4import java.util.LinkedList;
5import java.util.List;
6import java.util.Objects;
7
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07008import static com.google.common.base.Preconditions.checkNotNull;
9
10/**
11 * A container for detailed role information for a device,
12 * within the current cluster. Role attributes include current
13 * master and a preference-ordered list of backup nodes.
14 */
15public class RoleInfo {
16 private final NodeId master;
17 private final List<NodeId> backups;
18
19 public RoleInfo(NodeId master, List<NodeId> backups) {
20 this.master = master;
21 this.backups = new LinkedList<>();
22
23 this.backups.addAll(checkNotNull(backups));
24 }
25
26 public NodeId master() {
27 return master;
28 }
29
30 public List<NodeId> backups() {
31 return Collections.unmodifiableList(backups);
32 }
33
34 @Override
35 public boolean equals(Object other) {
36 if (other == null) {
37 return false;
38 }
39 if (!(other instanceof RoleInfo)) {
40 return false;
41 }
42 RoleInfo that = (RoleInfo) other;
43 if (!Objects.equals(this.master, that.master)) {
44 return false;
45 }
46 if (!Objects.equals(this.backups, that.backups)) {
47 return false;
48 }
49 return true;
50 }
51
52 @Override
53 public int hashCode() {
54 return Objects.hash(master, backups.hashCode());
55 }
56
57 @Override
58 public String toString() {
59 final StringBuilder builder = new StringBuilder();
60 builder.append("master: \n\t").append(master).append("\n");
61 builder.append("backups: \n");
62 for (NodeId n : backups) {
63 builder.append("\t").append(n).append("\n");
64 }
65 return builder.toString();
66 }
67}