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