blob: c370ab52563b3f9711f0f4055d630129b111e6f9 [file] [log] [blame]
Madan Jampani1d3494e2014-11-20 11:24:22 -08001package org.onlab.onos.cluster;
2
3import java.util.Objects;
4
5import com.google.common.base.MoreObjects;
6
7/**
8 * Abstract leadership concept.
9 */
10public class Leadership {
11
12 private final String topic;
13 private final ControllerNode leader;
14 private final long term;
15
16 public Leadership(String topic, ControllerNode leader, long term) {
17 this.topic = topic;
18 this.leader = leader;
19 this.term = term;
20 }
21
22 /**
23 * The topic for which this leadership applies.
24 * @return leadership topic.
25 */
26 public String topic() {
27 return topic;
28 }
29
30 /**
31 * The leader for this topic.
32 * @return leader node.
33 */
34 public ControllerNode leader() {
35 return leader;
36 }
37
38 /**
39 * The term number associated with this leadership.
40 * @return leadership term
41 */
42 public long term() {
43 return term;
44 }
45
46 @Override
47 public int hashCode() {
48 return Objects.hash(topic, leader, term);
49 }
50
51 @Override
52 public String toString() {
53 return MoreObjects.toStringHelper(this.getClass())
54 .add("topic", topic)
55 .add("leader", leader)
56 .add("term", term)
57 .toString();
58 }
59}