View Javadoc

1   /**
2    * Copyright 2010 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.master;
21  
22  import org.apache.hadoop.hbase.HRegionInfo;
23  import org.apache.hadoop.hbase.HServerAddress;
24  import org.apache.hadoop.hbase.util.Bytes;
25  
26  
27  /** Describes a meta region and its server */
28  public class MetaRegion implements Comparable<MetaRegion> {
29    private final HServerAddress server;
30    private HRegionInfo regionInfo;
31  
32    MetaRegion(final HServerAddress server, HRegionInfo regionInfo) {
33      if (server == null) {
34        throw new IllegalArgumentException("server cannot be null");
35      }
36      this.server = server;
37      if (regionInfo == null) {
38        throw new IllegalArgumentException("regionInfo cannot be null");
39      }
40      this.regionInfo = regionInfo;
41    }
42  
43    @Override
44    public String toString() {
45      return "{server: " + this.server.toString() + ", regionname: " +
46          regionInfo.getRegionNameAsString() + ", startKey: <" +
47          Bytes.toString(regionInfo.getStartKey()) + ">}";
48    }
49  
50    /** @return the regionName */
51    public byte [] getRegionName() {
52      return regionInfo.getRegionName();
53    }
54  
55    /** @return the server */
56    public HServerAddress getServer() {
57      return server;
58    }
59  
60    /** @return the startKey */
61    public byte [] getStartKey() {
62      return regionInfo.getStartKey();
63    }
64  
65  
66    /** @return the endKey */
67    public byte [] getEndKey() {
68      return regionInfo.getEndKey();
69    }
70  
71  
72    public HRegionInfo getRegionInfo() {
73      return regionInfo;
74    }
75  
76    @Override
77    public boolean equals(Object o) {
78      return o instanceof MetaRegion && this.compareTo((MetaRegion)o) == 0;
79    }
80  
81    @Override
82    public int hashCode() {
83      return regionInfo.hashCode();
84    }
85  
86    // Comparable
87  
88    public int compareTo(MetaRegion other) {
89      int cmp = regionInfo.compareTo(other.regionInfo);
90      if(cmp == 0) {
91        // Might be on different host?
92        cmp = this.server.compareTo(other.server);
93      }
94      return cmp;
95    }
96  }