001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.master.balancer;
019
020import java.io.Serializable;
021import org.apache.hadoop.hbase.ServerName;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * Data structure that holds servername and 'load'.
026 */
027@InterfaceAudience.Private
028class ServerAndLoad implements Comparable<ServerAndLoad>, Serializable {
029  private static final long serialVersionUID = 2735470854607296965L;
030  private final ServerName sn;
031  private final int load;
032
033  ServerAndLoad(final ServerName sn, final int load) {
034    this.sn = sn;
035    this.load = load;
036  }
037
038  ServerName getServerName() {
039    return this.sn;
040  }
041
042  int getLoad() {
043    return this.load;
044  }
045
046  @Override
047  public int compareTo(ServerAndLoad other) {
048    int diff = this.load - other.load;
049    return diff != 0 ? diff : this.sn.compareTo(other.getServerName());
050  }
051
052  @Override
053  public int hashCode() {
054    int result = load;
055    result = 31 * result + ((sn == null) ? 0 : sn.hashCode());
056    return result;
057  }
058
059  @Override
060  public boolean equals(Object o) {
061    if (o instanceof ServerAndLoad) {
062      ServerAndLoad sl = (ServerAndLoad) o;
063      return this.compareTo(sl) == 0;
064    }
065    return false;
066  }
067
068  @Override
069  public String toString() {
070    return "server=" + sn + " , load=" + load;
071  }
072}