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 @InterfaceAudience.Public
33 @InterfaceStability.Evolving
34 public class HRegionLocation implements Comparable<HRegionLocation> {
35 private final HRegionInfo regionInfo;
36 private final ServerName serverName;
37 private final long seqNum;
38
39 private String cachedString = null;
40
41 private String cachedHostnamePort;
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 synchronized String toString() {
58 if (this.cachedString == null) {
59 this.cachedString = "region=" + this.regionInfo.getRegionNameAsString() +
60 ", hostname=" + this.serverName + ", seqNum=" + seqNum;
61 }
62 return this.cachedString;
63 }
64
65
66
67
68 @Override
69 public boolean equals(Object o) {
70 if (this == o) {
71 return true;
72 }
73 if (o == null) {
74 return false;
75 }
76 if (!(o instanceof HRegionLocation)) {
77 return false;
78 }
79 return this.compareTo((HRegionLocation)o) == 0;
80 }
81
82
83
84
85 @Override
86 public int hashCode() {
87 return this.serverName.hashCode();
88 }
89
90
91 public HRegionInfo getRegionInfo(){
92 return regionInfo;
93 }
94
95 public String getHostname() {
96 return this.serverName.getHostname();
97 }
98
99 public int getPort() {
100 return this.serverName.getPort();
101 }
102
103 public long getSeqNum() {
104 return seqNum;
105 }
106
107
108
109
110 public synchronized String getHostnamePort() {
111 if (this.cachedHostnamePort == null) {
112 this.cachedHostnamePort =
113 Addressing.createHostAndPortStr(this.getHostname(), this.getPort());
114 }
115 return this.cachedHostnamePort;
116 }
117
118 public ServerName getServerName() {
119 return serverName;
120 }
121
122 public int compareTo(HRegionLocation o) {
123 return serverName.compareTo(o.getServerName());
124 }
125 }