2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.master
;
20 import java
.io
.Serializable
;
21 import java
.util
.Comparator
;
23 import org
.apache
.hadoop
.hbase
.ServerName
;
24 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
25 import org
.apache
.yetus
.audience
.InterfaceAudience
;
26 import org
.apache
.yetus
.audience
.InterfaceStability
;
29 * Stores the plan for the move of an individual region.
31 * Contains info for the region being moved, info for the server the region
32 * should be moved from, and info for the server the region should be moved
35 * The comparable implementation of this class compares only the region
36 * information and not the source/dest server info.
38 @InterfaceAudience.LimitedPrivate("Coprocessors")
39 @InterfaceStability.Evolving
40 public class RegionPlan
implements Comparable
<RegionPlan
> {
41 private final RegionInfo hri
;
42 private final ServerName source
;
43 private ServerName dest
;
45 public static class RegionPlanComparator
implements Comparator
<RegionPlan
>, Serializable
{
46 private static final long serialVersionUID
= 4213207330485734853L;
49 public int compare(RegionPlan l
, RegionPlan r
) {
50 return RegionPlan
.compareTo(l
, r
);
55 * Instantiate a plan for a region move, moving the specified region from
56 * the specified source server to the specified destination server.
58 * Destination server can be instantiated as null and later set
59 * with {@link #setDestination(ServerName)}.
61 * @param hri region to be moved
62 * @param source regionserver region should be moved from
63 * @param dest regionserver region should be moved to
65 public RegionPlan(final RegionInfo hri
, ServerName source
, ServerName dest
) {
72 * Set the destination server for the plan for this region.
74 public void setDestination(ServerName dest
) {
79 * Get the source server for the plan for this region.
80 * @return server info for source
82 public ServerName
getSource() {
87 * Get the destination server for the plan for this region.
88 * @return server info for destination
90 public ServerName
getDestination() {
95 * Get the encoded region name for the region this plan is for.
96 * @return Encoded region name
98 public String
getRegionName() {
99 return this.hri
.getEncodedName();
102 public RegionInfo
getRegionInfo() {
107 * Compare the region info.
108 * @param other region plan you are comparing against
111 public int compareTo(RegionPlan other
) {
112 return compareTo(this, other
);
115 private static int compareTo(RegionPlan left
, RegionPlan right
) {
116 int result
= compareServerName(left
.source
, right
.source
);
120 if (left
.hri
== null) {
121 if (right
.hri
!= null) {
124 } else if (right
.hri
== null) {
127 result
= RegionInfo
.COMPARATOR
.compare(left
.hri
, right
.hri
);
132 return compareServerName(left
.dest
, right
.dest
);
135 private static int compareServerName(ServerName left
, ServerName right
) {
137 return right
== null?
0: -1;
138 } else if (right
== null) {
141 return left
.compareTo(right
);
145 public int hashCode() {
146 final int prime
= 31;
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());
155 public boolean equals(Object obj
) {
162 if (getClass() != obj
.getClass()) {
165 RegionPlan other
= (RegionPlan
) obj
;
167 if (other
.dest
!= null) {
170 } else if (!dest
.equals(other
.dest
)) {
174 if (other
.hri
!= null) {
177 } else if (!hri
.equals(other
.hri
)) {
180 if (source
== null) {
181 if (other
.source
!= null) {
184 } else if (!source
.equals(other
.source
)) {
191 public String
toString() {
192 return "hri=" + this.hri
.getEncodedName() + ", source=" +
193 (this.source
== null?
"": this.source
.toString()) +
194 ", destination=" + (this.dest
== null?
"": this.dest
.toString());