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