Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cluster; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 2 | |
| 3 | import java.util.Collections; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 4 | import java.util.List; |
| 5 | import java.util.Objects; |
| 6 | |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 7 | /** |
| 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 | */ |
| 12 | public 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 Koshibe | adb2d3c | 2014-10-20 23:39:51 -0700 | [diff] [blame^] | 18 | this.backups = Collections.unmodifiableList(backups); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | public NodeId master() { |
| 22 | return master; |
| 23 | } |
| 24 | |
| 25 | public List<NodeId> backups() { |
Ayaka Koshibe | adb2d3c | 2014-10-20 23:39:51 -0700 | [diff] [blame^] | 26 | return backups; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 27 | } |
| 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 Koshibe | adb2d3c | 2014-10-20 23:39:51 -0700 | [diff] [blame^] | 55 | builder.append("master:").append(master).append(","); |
| 56 | builder.append("backups:"); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 57 | for (NodeId n : backups) { |
Ayaka Koshibe | adb2d3c | 2014-10-20 23:39:51 -0700 | [diff] [blame^] | 58 | builder.append(" ").append(n); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 59 | } |
| 60 | return builder.toString(); |
| 61 | } |
| 62 | } |