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 */
018
019package org.apache.hadoop.yarn.api.records;
020
021import org.apache.hadoop.classification.InterfaceAudience.Public;
022import org.apache.hadoop.classification.InterfaceStability.Stable;
023import org.apache.hadoop.yarn.util.Records;
024
025/**
026 * The priority assigned to a ResourceRequest or Application or Container 
027 * allocation 
028 *
029 */
030@Public
031@Stable
032public abstract class Priority implements Comparable<Priority> {
033
034  public static final Priority UNDEFINED = newInstance(-1);
035
036  @Public
037  @Stable
038  public static Priority newInstance(int p) {
039    Priority priority = Records.newRecord(Priority.class);
040    priority.setPriority(p);
041    return priority;
042  }
043
044  /**
045   * Get the assigned priority
046   * @return the assigned priority
047   */
048  @Public
049  @Stable
050  public abstract int getPriority();
051  
052  /**
053   * Set the assigned priority
054   * @param priority the assigned priority
055   */
056  @Public
057  @Stable
058  public abstract void setPriority(int priority);
059  
060  @Override
061  public int hashCode() {
062    final int prime = 517861;
063    int result = 9511;
064    result = prime * result + getPriority();
065    return result;
066  }
067
068  @Override
069  public boolean equals(Object obj) {
070    if (this == obj)
071      return true;
072    if (obj == null)
073      return false;
074    if (getClass() != obj.getClass())
075      return false;
076    Priority other = (Priority) obj;
077    if (getPriority() != other.getPriority())
078      return false;
079    return true;
080  }
081
082  @Override
083  public int compareTo(Priority other) {
084    return other.getPriority() - this.getPriority();
085  }
086
087  @Override
088  public String toString() {
089    return "{Priority: " + getPriority() + "}";
090  }
091}