blob: 767884db08947452622f0d5c9ec92f0e49762d26 [file] [log] [blame]
Ayaka Koshibeabedb092014-10-20 17:01:31 -07001package org.onlab.onos.cluster;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07002
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07003import java.util.List;
4import java.util.Objects;
5
Ayaka Koshibefc981cf2014-10-21 12:44:17 -07006import com.google.common.base.MoreObjects;
Yuta HIGUCHI40d01772014-10-21 00:08:44 -07007import com.google.common.collect.ImmutableList;
8
Ayaka Koshibe67af1f42014-10-20 15:26:37 -07009/**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070010 * An immutable container for role information for a device,
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070011 * within the current cluster. Role attributes include current
12 * master and a preference-ordered list of backup nodes.
13 */
14public class RoleInfo {
15 private final NodeId master;
16 private final List<NodeId> backups;
17
18 public RoleInfo(NodeId master, List<NodeId> backups) {
19 this.master = master;
Yuta HIGUCHI40d01772014-10-21 00:08:44 -070020 this.backups = ImmutableList.copyOf(backups);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070021 }
22
23 public NodeId master() {
24 return master;
25 }
26
27 public List<NodeId> backups() {
Ayaka Koshibeadb2d3c2014-10-20 23:39:51 -070028 return backups;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070029 }
30
31 @Override
32 public boolean equals(Object other) {
33 if (other == null) {
34 return false;
35 }
36 if (!(other instanceof RoleInfo)) {
37 return false;
38 }
39 RoleInfo that = (RoleInfo) other;
40 if (!Objects.equals(this.master, that.master)) {
41 return false;
42 }
43 if (!Objects.equals(this.backups, that.backups)) {
44 return false;
45 }
46 return true;
47 }
48
49 @Override
50 public int hashCode() {
51 return Objects.hash(master, backups.hashCode());
52 }
53
54 @Override
55 public String toString() {
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070056 return MoreObjects.toStringHelper(this.getClass())
57 .add("master", master)
58 .add("backups", backups)
59 .toString();
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070060 }
61}