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
47 private static final long serialVersionUID = 4213207330485734853L;
48
49 @Override
50 public int compare(RegionPlan l, RegionPlan r) {
51 long diff = r.getRegionInfo().getRegionId() - l.getRegionInfo().getRegionId();
52 if (diff < 0) return -1;
53 if (diff > 0) return 1;
54 return 0;
55 }
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69 public RegionPlan(final HRegionInfo hri, ServerName source, ServerName dest) {
70 this.hri = hri;
71 this.source = source;
72 this.dest = dest;
73 }
74
75
76
77
78 public void setDestination(ServerName dest) {
79 this.dest = dest;
80 }
81
82
83
84
85
86 public ServerName getSource() {
87 return source;
88 }
89
90
91
92
93
94 public ServerName getDestination() {
95 return dest;
96 }
97
98
99
100
101
102 public String getRegionName() {
103 return this.hri.getEncodedName();
104 }
105
106 public HRegionInfo getRegionInfo() {
107 return this.hri;
108 }
109
110
111
112
113
114 @Override
115 public int compareTo(RegionPlan o) {
116 return getRegionName().compareTo(o.getRegionName());
117 }
118
119 @Override
120 public int hashCode() {
121 return getRegionName().hashCode();
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (this == obj) {
127 return true;
128 }
129 if (obj == null || getClass() != obj.getClass()) {
130 return false;
131 }
132 RegionPlan other = (RegionPlan) obj;
133 return compareTo(other) == 0;
134 }
135
136 @Override
137 public String toString() {
138 return "hri=" + this.hri.getRegionNameAsString() + ", src=" +
139 (this.source == null? "": this.source.toString()) +
140 ", dest=" + (this.dest == null? "": this.dest.toString());
141 }
142 }