tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cluster; |
| 2 | |
| 3 | import org.onlab.packet.IpPrefix; |
| 4 | |
| 5 | import java.util.Objects; |
| 6 | |
| 7 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 8 | |
| 9 | /** |
| 10 | * Default implementation of a controller instance descriptor. |
| 11 | */ |
| 12 | public class DefaultControllerNode implements ControllerNode { |
| 13 | |
| 14 | private final NodeId id; |
| 15 | private final IpPrefix ip; |
| 16 | |
tom | 2d7c65f | 2014-09-23 01:09:35 -0700 | [diff] [blame] | 17 | // For serialization |
| 18 | private DefaultControllerNode() { |
| 19 | this.id = null; |
| 20 | this.ip = null; |
| 21 | } |
| 22 | |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Creates a new instance with the specified id and IP address. |
| 25 | * |
| 26 | * @param id instance identifier |
| 27 | * @param ip instance IP address |
| 28 | */ |
| 29 | public DefaultControllerNode(NodeId id, IpPrefix ip) { |
| 30 | this.id = id; |
| 31 | this.ip = ip; |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public NodeId id() { |
| 36 | return id; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public IpPrefix ip() { |
| 41 | return ip; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public int hashCode() { |
| 46 | return Objects.hash(id); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public boolean equals(Object o) { |
| 51 | if (this == o) { |
| 52 | return true; |
| 53 | } |
| 54 | if (o instanceof DefaultControllerNode) { |
| 55 | DefaultControllerNode that = (DefaultControllerNode) o; |
| 56 | return Objects.equals(this.id, that.id); |
| 57 | } |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public String toString() { |
| 63 | return toStringHelper(this).add("id", id).add("ip", ip).toString(); |
| 64 | } |
| 65 | |
| 66 | } |