1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master;
19
20 import java.io.Serializable;
21 import java.util.Comparator;
22
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.ServerName;
27
28
29
30
31
32
33
34
35
36
37
38 @InterfaceAudience.LimitedPrivate("Coprocessors")
39 @InterfaceStability.Evolving
40 public class RegionPlan implements Comparable<RegionPlan> {
41 private final HRegionInfo hri;
42 private final ServerName source;
43 private ServerName dest;
44
45 public static class RegionPlanComparator implements Comparator<RegionPlan>, Serializable {
46 private static final long serialVersionUID = 4213207330485734853L;
47
48 @Override
49 public int compare(RegionPlan l, RegionPlan r) {
50 return RegionPlan.compareTo(l, r);
51 }
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65 public RegionPlan(final HRegionInfo hri, ServerName source, ServerName dest) {
66 this.hri = hri;
67 this.source = source;
68 this.dest = dest;
69 }
70
71
72
73
74 public void setDestination(ServerName dest) {
75 this.dest = dest;
76 }
77
78
79
80
81
82 public ServerName getSource() {
83 return source;
84 }
85
86
87
88
89
90 public ServerName getDestination() {
91 return dest;
92 }
93
94
95
96
97
98 public String getRegionName() {
99 return this.hri.getEncodedName();
100 }
101
102 public HRegionInfo getRegionInfo() {
103 return this.hri;
104 }
105
106
107
108
109
110 @Override
111 public int compareTo(RegionPlan other) {
112 return compareTo(this, other);
113 }
114
115 private static int compareTo(RegionPlan left, RegionPlan right) {
116 int result = compareServerName(left.source, right.source);
117 if (result != 0) {
118 return result;
119 }
120 if (left.hri == null) {
121 if (right.hri != null) {
122 return -1;
123 }
124 } else if (right.hri == null) {
125 return +1;
126 } else {
127 result = left.hri.compareTo(right.hri);
128 }
129 if (result != 0) {
130 return result;
131 }
132 return compareServerName(left.dest, right.dest);
133 }
134
135 private static int compareServerName(ServerName left, ServerName right) {
136 if (left == null) {
137 return right == null? 0: -1;
138 } else if (right == null) {
139 return +1;
140 }
141 return left.compareTo(right);
142 }
143
144 @Override
145 public int hashCode() {
146 final int prime = 31;
147 int result = 1;
148 result = prime * result + ((dest == null) ? 0 : dest.hashCode());
149 result = prime * result + ((hri == null) ? 0 : hri.hashCode());
150 result = prime * result + ((source == null) ? 0 : source.hashCode());
151 return result;
152 }
153
154 @Override
155 public boolean equals(Object obj) {
156 if (this == obj) {
157 return true;
158 }
159 if (obj == null) {
160 return false;
161 }
162 if (getClass() != obj.getClass()) {
163 return false;
164 }
165 RegionPlan other = (RegionPlan) obj;
166 if (dest == null) {
167 if (other.dest != null) {
168 return false;
169 }
170 } else if (!dest.equals(other.dest)) {
171 return false;
172 }
173 if (hri == null) {
174 if (other.hri != null) {
175 return false;
176 }
177 } else if (!hri.equals(other.hri)) {
178 return false;
179 }
180 if (source == null) {
181 if (other.source != null) {
182 return false;
183 }
184 } else if (!source.equals(other.source)) {
185 return false;
186 }
187 return true;
188 }
189
190 @Override
191 public String toString() {
192 return "hri=" + this.hri.getRegionNameAsString() + ", src=" +
193 (this.source == null? "": this.source.toString()) +
194 ", dest=" + (this.dest == null? "": this.dest.toString());
195 }
196 }