1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase;
21
22 import org.apache.hadoop.hbase.util.Addressing;
23
24
25
26
27
28
29
30
31 public class HRegionLocation implements Comparable<HRegionLocation> {
32 private final HRegionInfo regionInfo;
33 private final String hostname;
34 private final int port;
35
36 private String cachedString = null;
37
38 private String cachedHostnamePort;
39
40
41
42
43
44
45
46 public HRegionLocation(HRegionInfo regionInfo, final String hostname,
47 final int port) {
48 this.regionInfo = regionInfo;
49 this.hostname = hostname;
50 this.port = port;
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.hostname + ", port=" + this.port;
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 int result = this.hostname.hashCode();
88 result ^= this.port;
89 return result;
90 }
91
92
93 public HRegionInfo getRegionInfo(){
94 return regionInfo;
95 }
96
97
98
99
100
101
102 public HServerAddress getServerAddress() {
103 return new HServerAddress(this.hostname, this.port);
104 }
105
106 public String getHostname() {
107 return this.hostname;
108 }
109
110 public int getPort() {
111 return this.port;
112 }
113
114
115
116
117 public synchronized String getHostnamePort() {
118 if (this.cachedHostnamePort == null) {
119 this.cachedHostnamePort =
120 Addressing.createHostAndPortStr(this.hostname, this.port);
121 }
122 return this.cachedHostnamePort;
123 }
124
125
126
127
128
129 public int compareTo(HRegionLocation o) {
130 int result = this.hostname.compareTo(o.getHostname());
131 if (result != 0) return result;
132 return this.port - o.getPort();
133 }
134 }