blob: 751361a5f5d4c42c8c9c38a2a70d4fe3e3db2a13 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.mastership;
Yuta HIGUCHI080d7842014-09-25 13:53:15 -070017
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070018import java.util.Objects;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cluster.NodeId;
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070021
Yuta HIGUCHIa9700c72014-10-24 22:12:03 -070022import com.google.common.base.MoreObjects;
23
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070024public final class MastershipTerm {
25
26 private final NodeId master;
Madan Jampani15d773c2015-02-25 15:31:55 -080027 private final long termNumber;
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070028
Madan Jampani15d773c2015-02-25 15:31:55 -080029 private MastershipTerm(NodeId master, long term) {
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070030 this.master = master;
31 this.termNumber = term;
32 }
33
Madan Jampani15d773c2015-02-25 15:31:55 -080034 public static MastershipTerm of(NodeId master, long term) {
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070035 return new MastershipTerm(master, term);
36 }
37
38 public NodeId master() {
39 return master;
40 }
41
Madan Jampani15d773c2015-02-25 15:31:55 -080042 public long termNumber() {
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070043 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 Koshibe48239b02014-09-25 17:12:31 -070053 if (this == other) {
54 return true;
55 }
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070056 if (other instanceof MastershipTerm) {
57 MastershipTerm that = (MastershipTerm) other;
Yuta HIGUCHIdfe6e3b2014-10-30 11:31:51 -070058 return Objects.equals(this.master, that.master) &&
59 Objects.equals(this.termNumber, that.termNumber);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070060 }
61 return false;
62 }
Yuta HIGUCHIa9700c72014-10-24 22:12:03 -070063
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 HIGUCHI080d7842014-09-25 13:53:15 -070071}