1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.classification.InterfaceStability;
23 import org.apache.hadoop.hbase.util.Addressing;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @InterfaceAudience.Public
39 @InterfaceStability.Evolving
40 public class HRegionLocation implements Comparable<HRegionLocation> {
41 private final HRegionInfo regionInfo;
42 private final ServerName serverName;
43 private final long seqNum;
44
45 public HRegionLocation(HRegionInfo regionInfo, ServerName serverName) {
46 this(regionInfo, serverName, HConstants.NO_SEQNUM);
47 }
48
49 public HRegionLocation(HRegionInfo regionInfo, ServerName serverName, long seqNum) {
50 this.regionInfo = regionInfo;
51 this.serverName = serverName;
52 this.seqNum = seqNum;
53 }
54
55
56
57
58 @Override
59 public String toString() {
60 return "region=" + (this.regionInfo == null ? "null" : this.regionInfo.getRegionNameAsString())
61 + ", hostname=" + this.serverName + ", seqNum=" + seqNum;
62 }
63
64
65
66
67 @Override
68 public boolean equals(Object o) {
69 if (this == o) {
70 return true;
71 }
72 if (o == null) {
73 return false;
74 }
75 if (!(o instanceof HRegionLocation)) {
76 return false;
77 }
78 return this.compareTo((HRegionLocation)o) == 0;
79 }
80
81
82
83
84 @Override
85 public int hashCode() {
86 return this.serverName.hashCode();
87 }
88
89
90 public HRegionInfo getRegionInfo(){
91 return regionInfo;
92 }
93
94 public String getHostname() {
95 return this.serverName.getHostname();
96 }
97
98 public int getPort() {
99 return this.serverName.getPort();
100 }
101
102 public long getSeqNum() {
103 return seqNum;
104 }
105
106
107
108
109 public String getHostnamePort() {
110 return Addressing.createHostAndPortStr(this.getHostname(), this.getPort());
111 }
112
113 public ServerName getServerName() {
114 return serverName;
115 }
116
117 @Override
118 public int compareTo(HRegionLocation o) {
119 return serverName.compareTo(o.getServerName());
120 }
121 }