Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.mastership; |
Yuta HIGUCHI | 080d784 | 2014-09-25 13:53:15 -0700 | [diff] [blame] | 17 | |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
| 19 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.cluster.NodeId; |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 21 | |
Yuta HIGUCHI | a9700c7 | 2014-10-24 22:12:03 -0700 | [diff] [blame] | 22 | import com.google.common.base.MoreObjects; |
| 23 | |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 24 | public final class MastershipTerm { |
| 25 | |
| 26 | private final NodeId master; |
Madan Jampani | 15d773c | 2015-02-25 15:31:55 -0800 | [diff] [blame] | 27 | private final long termNumber; |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 28 | |
Madan Jampani | 15d773c | 2015-02-25 15:31:55 -0800 | [diff] [blame] | 29 | private MastershipTerm(NodeId master, long term) { |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 30 | this.master = master; |
| 31 | this.termNumber = term; |
| 32 | } |
| 33 | |
Madan Jampani | 15d773c | 2015-02-25 15:31:55 -0800 | [diff] [blame] | 34 | public static MastershipTerm of(NodeId master, long term) { |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 35 | return new MastershipTerm(master, term); |
| 36 | } |
| 37 | |
| 38 | public NodeId master() { |
| 39 | return master; |
| 40 | } |
| 41 | |
Madan Jampani | 15d773c | 2015-02-25 15:31:55 -0800 | [diff] [blame] | 42 | public long termNumber() { |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 43 | return termNumber; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public int hashCode() { |
| 48 | return Objects.hash(master, termNumber); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public boolean equals(Object other) { |
Ayaka Koshibe | 48239b0 | 2014-09-25 17:12:31 -0700 | [diff] [blame] | 53 | if (this == other) { |
| 54 | return true; |
| 55 | } |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 56 | if (other instanceof MastershipTerm) { |
| 57 | MastershipTerm that = (MastershipTerm) other; |
Yuta HIGUCHI | dfe6e3b | 2014-10-30 11:31:51 -0700 | [diff] [blame] | 58 | return Objects.equals(this.master, that.master) && |
| 59 | Objects.equals(this.termNumber, that.termNumber); |
Ayaka Koshibe | b70d34b | 2014-09-25 15:43:01 -0700 | [diff] [blame] | 60 | } |
| 61 | return false; |
| 62 | } |
Yuta HIGUCHI | a9700c7 | 2014-10-24 22:12:03 -0700 | [diff] [blame] | 63 | |
| 64 | @Override |
| 65 | public String toString() { |
| 66 | return MoreObjects.toStringHelper(getClass()) |
| 67 | .add("master", this.master) |
| 68 | .add("termNumber", this.termNumber) |
| 69 | .toString(); |
| 70 | } |
Yuta HIGUCHI | 080d784 | 2014-09-25 13:53:15 -0700 | [diff] [blame] | 71 | } |