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.api.AMRMProtocol; 024 025/** 026 * <p><code>Resource</code> models a set of computer resources in the 027 * cluster.</p> 028 * 029 * <p>Currrently it only models <em>memory</em>.</p> 030 * 031 * <p>Typically, applications request <code>Resource</code> of suitable 032 * capability to run their component tasks.</p> 033 * 034 * @see ResourceRequest 035 * @see AMRMProtocol#allocate(org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest) 036 */ 037@Public 038@Stable 039public abstract class Resource implements Comparable<Resource> { 040 041 /** 042 * Get <em>memory</em> of the resource. 043 * @return <em>memory</em> of the resource 044 */ 045 @Public 046 @Stable 047 public abstract int getMemory(); 048 049 /** 050 * Set <em>memory</em> of the resource. 051 * @param memory <em>memory</em> of the resource 052 */ 053 @Public 054 @Stable 055 public abstract void setMemory(int memory); 056 057 @Override 058 public int hashCode() { 059 final int prime = 31; 060 int result = 1; 061 result = prime * result + getMemory(); 062 return result; 063 } 064 065 @Override 066 public boolean equals(Object obj) { 067 if (this == obj) 068 return true; 069 if (obj == null) 070 return false; 071 if (getClass() != obj.getClass()) 072 return false; 073 Resource other = (Resource) obj; 074 if (getMemory() != other.getMemory()) 075 return false; 076 return true; 077 } 078 079 @Override 080 public String toString() { 081 return "memory: " + getMemory(); 082 } 083}