RecordFactory.java 中内容,实现对record实例的初始化
@LimitedPrivate({ "MapReduce", "YARN" })
@Unstablepublic interface RecordFactory {
public <T> T newRecordInstance(Class<T> clazz);
}
Record.java
/**
* Convenient API record utils
*/
@LimitedPrivate({ "MapReduce", "YARN" })
@Unstable
public class Records {
// The default record factory
private static final RecordFactory factory =
RecordFactoryProvider.getRecordFactory(null);//构造静态的factory对象
public static <T> T newRecord(Class<T> cls) {
return factory.newRecordInstance(cls);//构造新的record对象并返回之
}
@Public
@Stable
public abstract class Resource implements Comparable<Resource> {
@Public
@Stable
public static Resource newInstance(int memory, int vCores) {
Resource resource = Records.newRecord(Resource.class);//通过records类来实例化resource对象。
resource.setMemory(memory);//设置该分布式系统中的内存
resource.setVirtualCores(vCores);//设置该分布式系统中虚拟的cpu个数
return resource;//返回resource对象
}
/**
* Get <em>memory</em> of the resource.
* @return <em>memory</em> of the resource
*/
@Public
@Stable
public abstract int getMemory();//得到内存数
/**
* Set <em>memory</em> of the resource.
* @param memory <em>memory</em> of the resource
*/
@Public
@Stable
public abstract void setMemory(int memory);//设置内存大小
/**
* Get <em>number of virtual cpu cores</em> of the resource.
*
* Virtual cores are a unit for expressing CPU parallelism. A node's capacity
* should be configured with virtual cores equal to its number of physical cores.
* A container should be requested with the number of cores it can saturate, i.e.
* the average number of threads it expects to have runnable at a time.
*
* @return <em>num of virtual cpu cores</em> of the resource
*/
@Public
@Evolving
public abstract int getVirtualCores();
/**
* Set <em>number of virtual cpu cores</em> of the resource.
*
* Virtual cores are a unit for expressing CPU parallelism. A node's capacity
* should be configured with virtual cores equal to its number of physical cores.
* A container should be requested with the number of cores it can saturate, i.e.
* the average number of threads it expects to have runnable at a time.
*
* @param vCores <em>number of virtual cpu cores</em> of the resource
*/
@Public
@Evolving
public abstract void setVirtualCores(int vCores);//设置虚拟CPU的个数
@Override
public int hashCode() {
final int prime = 263167;
int result = 3571;
result = 939769357 + getMemory(); // prime * result = 939769357 initially
result = prime * result + getVirtualCores();
return result;
}
@Override
public boolean equals(Object obj) {//判断两者对象资源是否相等
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Resource))
return false;
Resource other = (Resource) obj;
if (getMemory() != other.getMemory() ||
getVirtualCores() != other.getVirtualCores()) {
return false;
}
return true;
}
@Override
public String toString() {
return "<memory:" + getMemory() + ", vCores:" + getVirtualCores() + ">";
}
}