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; |
| 4 | import java.util.LinkedList; |
| 5 | import java.util.List; |
| 6 | import java.util.Objects; |
| 7 | |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 8 | import 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 | */ |
| 15 | public 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 | } |