View Javadoc

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    // TODO: Is this class necessary?  Why not just have a Pair?
28    private HRegionInfo regionInfo;
29    private HServerAddress serverAddress;
30  
31    /**
32     * Constructor
33     *
34     * @param regionInfo the HRegionInfo for the region
35     * @param serverAddress the HServerAddress for the region server
36     */
37    public HRegionLocation(HRegionInfo regionInfo, HServerAddress serverAddress) {
38      this.regionInfo = regionInfo;
39      this.serverAddress = serverAddress;
40    }
41  
42    /**
43     * @see java.lang.Object#toString()
44     */
45    @Override
46    public String toString() {
47      return "address: " + this.serverAddress.toString() + ", regioninfo: " +
48        this.regionInfo.getRegionNameAsString();
49    }
50  
51    /**
52     * @see java.lang.Object#equals(java.lang.Object)
53     */
54    @Override
55    public boolean equals(Object o) {
56      if (this == o) {
57        return true;
58      }
59      if (o == null) {
60        return false;
61      }
62      if (!(o instanceof HRegionLocation)) {
63        return false;
64      }
65      return this.compareTo((HRegionLocation)o) == 0;
66    }
67  
68    /**
69     * @see java.lang.Object#hashCode()
70     */
71    @Override
72    public int hashCode() {
73      int result = this.regionInfo.hashCode();
74      result ^= this.serverAddress.hashCode();
75      return result;
76    }
77  
78    /** @return HRegionInfo */
79    public HRegionInfo getRegionInfo(){
80      return regionInfo;
81    }
82  
83    /** @return HServerAddress */
84    public HServerAddress getServerAddress(){
85      return serverAddress;
86    }
87  
88    //
89    // Comparable
90    //
91  
92    public int compareTo(HRegionLocation o) {
93      int result = this.regionInfo.compareTo(o.regionInfo);
94      if(result == 0) {
95        result = this.serverAddress.compareTo(o.serverAddress);
96      }
97      return result;
98    }
99  }