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 | |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 6 | import com.google.common.base.MoreObjects; |
Yuta HIGUCHI | 40d0177 | 2014-10-21 00:08:44 -0700 | [diff] [blame] | 7 | import com.google.common.collect.ImmutableList; |
| 8 | |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 9 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 10 | * An immutable container for role information for a device, |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 11 | * within the current cluster. Role attributes include current |
| 12 | * master and a preference-ordered list of backup nodes. |
| 13 | */ |
| 14 | public 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 HIGUCHI | 40d0177 | 2014-10-21 00:08:44 -0700 | [diff] [blame] | 20 | this.backups = ImmutableList.copyOf(backups); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | public NodeId master() { |
| 24 | return master; |
| 25 | } |
| 26 | |
| 27 | public List<NodeId> backups() { |
Ayaka Koshibe | adb2d3c | 2014-10-20 23:39:51 -0700 | [diff] [blame] | 28 | return backups; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 29 | } |
| 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 Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 56 | return MoreObjects.toStringHelper(this.getClass()) |
| 57 | .add("master", master) |
| 58 | .add("backups", backups) |
| 59 | .toString(); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 60 | } |
| 61 | } |