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