1 /**
2 * Copyright 2007 The Apache Software Foundation
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package org.apache.hadoop.hbase;
21
22 /**
23 * Contains the HRegionInfo for the region and the HServerAddress for the
24 * HRegionServer serving the region
25 */
26 public class HRegionLocation implements Comparable<HRegionLocation> {
27 private HRegionInfo regionInfo;
28 private HServerAddress serverAddress;
29
30 /**
31 * Constructor
32 *
33 * @param regionInfo the HRegionInfo for the region
34 * @param serverAddress the HServerAddress for the region server
35 */
36 public HRegionLocation(HRegionInfo regionInfo, HServerAddress serverAddress) {
37 this.regionInfo = regionInfo;
38 this.serverAddress = serverAddress;
39 }
40
41 /**
42 * @see java.lang.Object#toString()
43 */
44 @Override
45 public String toString() {
46 return "address: " + this.serverAddress.toString() + ", regioninfo: " +
47 this.regionInfo;
48 }
49
50 /**
51 * @see java.lang.Object#equals(java.lang.Object)
52 */
53 @Override
54 public boolean equals(Object o) {
55 if (this == o) {
56 return true;
57 }
58 if (o == null) {
59 return false;
60 }
61 if (!(o instanceof HRegionLocation)) {
62 return false;
63 }
64 return this.compareTo((HRegionLocation)o) == 0;
65 }
66
67 /**
68 * @see java.lang.Object#hashCode()
69 */
70 @Override
71 public int hashCode() {
72 int result = this.regionInfo.hashCode();
73 result ^= this.serverAddress.hashCode();
74 return result;
75 }
76
77 /** @return HRegionInfo */
78 public HRegionInfo getRegionInfo(){
79 return regionInfo;
80 }
81
82 /** @return HServerAddress */
83 public HServerAddress getServerAddress(){
84 return serverAddress;
85 }
86
87 //
88 // Comparable
89 //
90
91 public int compareTo(HRegionLocation o) {
92 int result = this.regionInfo.compareTo(o.regionInfo);
93 if(result == 0) {
94 result = this.serverAddress.compareTo(o.serverAddress);
95 }
96 return result;
97 }
98 }