package org.cloudbus.cloudsim;

 import java.util.ArrayList;//This class provides methods to manipulate the size of the array that is used internally to store the list.
import java.util.List; /**【虚拟机】
* Vm represents a VM: 【it runs inside a Host, sharing hostList
* with other VMs. It processes cloudlets. 】This processing happens according
* to a policy, defined by the CloudletScheduler. Each VM has a owner(每个虚拟机有一个所有者), which can
* submit cloudlets to the VM to be executed
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public class Vm { /** The id. ID号*/
private int id; /** The user id. 用户编号*/
private int userId; private String uid; /** The size. 大小 */
private long size; /** The MIPS.处理速度MIPS */
private double mips; /** The PEs number. PE数*/
private int pesNumber; /** The ram. 内存*/
private int ram; /** The bw.带宽 */
private long bw; /** The vmm. 虚拟机管理程序*/
private String vmm; /** The Cloudlet scheduler. 云任务调度程序*/
private CloudletScheduler cloudletScheduler; /** The host.主机 */
private Host host; /** In migration flag. 迁移标志*/
private boolean inMigration; /** The current allocated size.当前分配大小 */
private long currentAllocatedSize; /** The current allocated ram. 当前分配内存*/
private int currentAllocatedRam; /** The current allocated bw. 当前分配带宽*/
private long currentAllocatedBw; /** The current allocated mips. 当前分配mips*/
private List<Double> currentAllocatedMips; /** The recently created. 最近创建*/
private boolean recentlyCreated; /**【虚拟机特征对象】
* Creates a new VMCharacteristics object.
*
* @param id unique ID of the VM
* @param userId ID of the VM's owner
* @param size amount of storage
* @param ram amount of ram
* @param bw amount of bandwidth
* @param pesNumber amount of CPUs CPU总和
* @param vmm virtual machine monitor 虚拟机监控器
* @param cloudletScheduler cloudletScheduler policy for cloudlets云任务调度协议
* @param priority the priority 优先权
* @param mips the mips
*
* @pre id >= 0
* @pre userId >= 0
* @pre size > 0
* @pre ram > 0
* @pre bw > 0
* @pre cpus > 0
* @pre priority >= 0
* @pre cloudletScheduler != null
* @post $none
*/
public Vm(int id, int userId, double mips, int pesNumber, int ram, long bw, long size, String vmm, CloudletScheduler cloudletScheduler) {
setId(id);
setUserId(userId);
setUid(getUid(userId, id));
setMips(mips);
setPesNumber(pesNumber);
setRam(ram);
setBw(bw);
setSize(size);
setVmm(vmm);
setCloudletScheduler(cloudletScheduler); setInMigration(false);
setRecentlyCreated(true); setCurrentAllocatedBw(0);
setCurrentAllocatedMips(null);//怎么是null
setCurrentAllocatedRam(0);
setCurrentAllocatedSize(0);
} /**【更新运行在虚拟机上云任务】
* Updates the processing of cloudlets running on this VM.
*
* @param currentTime current simulation time
* @param mipsShare array with MIPS share of each Pe available to the scheduler
*
* @return time predicted completion time【预测完成时间】 of the earliest finishing cloudlet, or 0
* if there is no next events
*
* @pre currentTime >= 0
* @post $none
*/
public double updateVmProcessing(double currentTime, List<Double> mipsShare) {
if (mipsShare != null) {
return getCloudletScheduler().updateVmProcessing(currentTime, mipsShare);
}
return 0.0;
} /**当前请求的MIPS
* Gets the current requested mips.
*
* @return the current requested mips
*/
public List<Double> getCurrentRequestedMips() {
List<Double> currentRequestedMips = getCloudletScheduler().getCurrentRequestedMips(); if (isRecentlyCreated()) {//新创建虚拟机
boolean mipsIsNull = true;
for (double mips : currentRequestedMips) {
if (mips > 0.0) {
mipsIsNull = false;
setRecentlyCreated(false);
break;
}
} //if (mipsIsNull && isRecentlyCreated()) {
if (mipsIsNull) {
currentRequestedMips = new ArrayList<Double>();
for (int i = 0; i < getPesNumber(); i++) {
currentRequestedMips.add(getMips());
}
}
} return currentRequestedMips;
} /**当前请求的MIPS总数
* Gets the current requested total mips.
*
* @return the current requested total mips
*/
public double getCurrentRequestedTotalMips() {
double totalRequestedMips = 0;
for (double mips : getCurrentRequestedMips()) {
totalRequestedMips += mips;
}
return totalRequestedMips;
} /**请求的带宽
* Gets the current requested bw.
*
* @return the current requested bw
*/
public long getCurrentRequestedBw() {
return getBw();
} /**请求的内存
* Gets the current requested ram.
*
* @return the current requested ram
*/
public int getCurrentRequestedRam() {
return getRam();
} /**CPU利用率
* Get utilization created by all clouddlets running on this VM.
*
* @param time the time
*
* @return total utilization
*/
public double getTotalUtilizationOfCpu(double time) {
return getCloudletScheduler().getTotalUtilizationOfCpu(time);
} /**MIPS利用率
* Get utilization created by all cloudlets running on this VM in MIPS.
*
* @param time the time
*
* @return total utilization
*/
public double getTotalUtilizationOfCpuMips(double time) {
return getTotalUtilizationOfCpu(time) * getMips();
} public void setUid(String uid) {
this.uid = uid;
} /**虚拟机的唯一标示
* Get unique string identificator of the VM.
*
* @return string uid
*/
public String getUid() {
return uid;
} /**生成虚拟机标示
* Generate unique string identificator of the VM.
*
* @param userId the user id
* @param vmId the vm id
*
* @return string uid
*/
public static String getUid(int userId, int vmId) {
return userId + "-" + vmId;
} /**取ID
* Gets the id.
*
* @return the id
*/
public int getId() {
return id;
} /**设置ID
* Sets the id.
*
* @param id the new id
*/
protected void setId(int id) {
this.id = id;
} /**设置用户ID
* Sets the user id.
*
* @param userId the new user id
*/
protected void setUserId(int userId) {
this.userId = userId;
} /**虚拟机所有者ID
* Gets the ID of the owner of the VM.
*
* @return VM's owner ID
*
* @pre $none
* @post $none
*/
public int getUserId() {
return userId;
} /**取MIPS
* Gets the mips.
*
* @return the mips
*/
public double getMips() {
return mips;
} /**设置MIPS
* Sets the mips.
*
* @param mips the new mips
*/
protected void setMips(double mips) {
this.mips = mips;
} /**取pe数
* Gets the pes number.
*
* @return the pes number
*/
public int getPesNumber() {
return pesNumber;
} /**设置
* Sets the pes number.
*
* @param pesNumber the new pes number
*/
protected void setPesNumber(int pesNumber) {
this.pesNumber = pesNumber;
} /**总内存
* Gets the amount of ram.
*
* @return amount of ram
*
* @pre $none
* @post $none
*/
public int getRam() {
return ram;
} /**设置内存
* Sets the amount of ram.
*
* @param ram new amount of ram
*
* @pre ram > 0
* @post $none
*/
public void setRam(int ram) {
this.ram = ram;
} /**总带宽
* Gets the amount of bandwidth.
*
* @return amount of bandwidth
*
* @pre $none
* @post $none
*/
public long getBw() {
return bw;
} /**设置带宽
* Sets the amount of bandwidth.
*
* @param bw new amount of bandwidth
*
* @pre bw > 0
* @post $none
*/
public void setBw(long bw) {
this.bw = bw;
} /**取存储
* Gets the amount of storage.
*
* @return amount of storage
*
* @pre $none
* @post $none
*/
public long getSize() {
return size;
} /**设置存储
* Sets the amount of storage.
*
* @param size new amount of storage
*
* @pre size > 0
* @post $none
*/
public void setSize(long size) {
this.size = size;
} /**取VMM
* Gets the VMM.
*
* @return VMM
*
* @pre $none
* @post $none
*/
public String getVmm(){
return vmm;
} /**设置VMM
* Sets the VMM.
*
* @param vmm the new VMM
*/
protected void setVmm(String vmm) {
this.vmm = vmm;
} /**设置主机
* Sets the host that runs this VM.
*
* @param host Host running the VM
*
* @pre host != $null
* @post $none
*/
public void setHost(Host host){
this.host = host;
} /**获取主机
* Gets the host.
*
* @return the host
*/
public Host getHost() {
return host;
} /**虚拟机调度程序
* Gets the vm scheduler.
*
* @return the vm scheduler
*/
public CloudletScheduler getCloudletScheduler() {
return cloudletScheduler;
} /**设置虚拟机调度程序
* Sets the vm scheduler.
*
* @param cloudletScheduler the new vm scheduler
*/
protected void setCloudletScheduler(CloudletScheduler cloudletScheduler) {
this.cloudletScheduler = cloudletScheduler;
} /**是否迁移
* Checks if is in migration.
*
* @return true, if is in migration
*/
public boolean isInMigration() {
return inMigration;
} /**
* Sets the in migration.
*
* @param inMigration the new in migration
*/
public void setInMigration(boolean inMigration) {
this.inMigration = inMigration;
} /**当前分配大小
* Gets the current allocated size.
*
* @return the current allocated size
*/
public long getCurrentAllocatedSize() {
return currentAllocatedSize;
} /**
* Sets the current allocated size.
*
* @param currentAllocatedSize the new current allocated size
*/
protected void setCurrentAllocatedSize(long currentAllocatedSize) {
this.currentAllocatedSize = currentAllocatedSize;
} /**取当前分配的内存
* Gets the current allocated ram.
*
* @return the current allocated ram
*/
public int getCurrentAllocatedRam() {
return currentAllocatedRam;
} /**设置当前分配的内存
* Sets the current allocated ram.
*
* @param currentAllocatedRam the new current allocated ram
*/
public void setCurrentAllocatedRam(int currentAllocatedRam) {
this.currentAllocatedRam = currentAllocatedRam;
} /**取当前分配的带宽
* Gets the current allocated bw.
*
* @return the current allocated bw
*/
public long getCurrentAllocatedBw() {
return currentAllocatedBw;
} /**设置当前分配的带宽
* Sets the current allocated bw.
*
* @param currentAllocatedBw the new current allocated bw
*/
public void setCurrentAllocatedBw(long currentAllocatedBw) {
this.currentAllocatedBw = currentAllocatedBw;
} /**取当前分配的MIPS
* Gets the current allocated mips.
*
* @return the current allocated mips
*/
public List<Double> getCurrentAllocatedMips() {
return currentAllocatedMips;
} /**设置当前分配的MIPS
* Sets the current allocated mips.
*
* @param currentAllocatedMips the new current allocated mips
*/
public void setCurrentAllocatedMips(List<Double> currentAllocatedMips) {
this.currentAllocatedMips = currentAllocatedMips;
} /**是否最近创建
* Checks if is recently created.
*
* @return true, if is recently created
*/
public boolean isRecentlyCreated() {
return recentlyCreated;
} /**
* Sets the recently created.
*
* @param recentlyCreated the new recently created
*/
public void setRecentlyCreated(boolean recentlyCreated) {
this.recentlyCreated = recentlyCreated;
} }

CloudSim源代码学习——虚拟机(VM)的更多相关文章

  1. CloudSim源代码学习——服务代理商(DatacenterBroker)

    DatacenterBroker.java文件如下: (其中,相关语句已经做好标注) /* * Title: CloudSim Toolkit * Description: CloudSim (Clo ...

  2. CloudSim源代码学习——云数据中心(Datacenter)

    package org.cloudbus.cloudsim; import java.text.DecimalFormat;//十进制 import java.util.ArrayList; impo ...

  3. CloudSim源代码学习——任务单元(Cloudlet)

    /* * Title: CloudSim Toolkit * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Sim ...

  4. Docker学习笔记之-在虚拟机VM上安装CentOS 7.8

    虚拟机VM版本:VMware Workstation Pro 16 中文虚拟机软件专业版 到官网下载即可,或者也可以通过下边链接下载 下载地址: http://www.epinv.com/post/1 ...

  5. struts2源代码学习之初始化(一)

    看struts2源代码已有一段时日,从今天開始,就做一个总结吧. 首先,先看看怎么调试struts2源代码吧,主要是下面步骤: 使用Myeclipse创建一个webproject 导入struts2须 ...

  6. [Java] LinkedList / Queue - 源代码学习笔记

    简单地画了下 LinkedList 的继承关系,如下图.只是画了关注的部分,并不是完整的关系图.本博文涉及的是 Queue, Deque, LinkedList 的源代码阅读笔记.关于 List 接口 ...

  7. 开源中国安卓client源代码学习(一) 渐变启动界面

    开源中国安卓client源代码学习(一) 渐变启动界面 准备学习安卓开发, 看到网上有人推荐开源中国安卓client的源代码, 说里面包括了大部分技术, 于是准备好好研究研究. 特开通此系列博客来记录 ...

  8. 读Flask源代码学习Python--config原理

    读Flask源代码学习Python--config原理 个人学习笔记,水平有限.如果理解错误的地方,请大家指出来,谢谢!第一次写文章,发现好累--!. 起因   莫名其妙在第一份工作中使用了从来没有接 ...

  9. nginx源代码学习资源(不断更新)

    nginx源代码学习是一个痛苦又快乐的过程,以下列出了一些nginx的学习资源. 首先要做的当然是下载一份nginx源代码,能够从nginx官方站点下载一份最新的. 看了nginx源代码,发现这是一份 ...

随机推荐

  1. hystrix降级初步学习

    通过hystrix可以进行服务的限流.熔断.降级 配置 服务端Eureka server: port: 8761 # 指定该Eureka实例的端口 eureka: client: registerWi ...

  2. 深度学习笔记(七)SSD 论文阅读笔记

    一. 算法概述 本文提出的SSD算法是一种直接预测目标类别和bounding box的多目标检测算法.与faster rcnn相比,该算法没有生成 proposal 的过程,这就极大提高了检测速度.针 ...

  3. java main()线程是不是最后一个退出的(相比较main中创建的其他多个线程)

    JVM会在所有的非守护线程(用户线程)执行完毕后退出: main线程是用户线程: 仅有main线程一个用户线程执行完毕,不能决定JVM是否退出,也即是说main线程并不一定是最后一个退出的线程. pu ...

  4. [视频]K8飞刀 S2-020 exploit getshell 动画教程

    [视频]K8飞刀 S2-020 exploit getshell 动画教程 链接:https://pan.baidu.com/s/1G5x7Dcu6pzHz6ZfSCDDmKA 提取码:05kw

  5. web自动化测试(java)---测试过程中遇到的错误合集

    摸索测试,不管是安装.调测第一个用例都会遇到各种各样的问题,或是自己的问题或是程序本身设置问题 只有把所有问题记录下来,才对得起自己的经历 1.设置firefox的执行文件错误 Exception i ...

  6. 删除.svn 脱离svn版本控制器

    1.for /r . %%a in (.) do @if exist "%%a\.svn" rd /s /q "%%a\.svn" 复制到记事本,将记事本保存为 ...

  7. 829. 连续整数求和-leetcode

    题目:给定一个正整数 N,试求有多少组连续正整数满足所有数字之和为 N? 示例 1: 输入: 5 输出: 2 解释: 5 = 5 = 2 + 3,共有两组连续整数([5],[2,3])求和后为 5. ...

  8. springboot json返回null问题处理

    在开发过程中,我们需要统一返回前端json格式的数据,但有些接口的返回值存在 null或者""这种没有意义的字段.以上不仅影响理解,还浪费带宽,这时我们可以统一做一下处理:不返回空 ...

  9. 如何在Lua与C/C++之间实现table数据的交换

    之前在<C/C++和Lua是如何进行通信的?>一文中简单的介绍了lua与宿主之间的通信.简单的说两种不同的语言之间数据类型不一样又如何进行数据交换呢?那就是lua_State虚拟栈,通过栈 ...

  10. MySQL 进阶之索引

    一,索引前传 在了解数据库索引之前,首先有必要了解一下数据库索引的数据结构基础,那么什么样的数据结构可以作为索引呢? B-tree是最常用的用于索引的数据结构.因为它们是时间复杂度低, 查找.删除.插 ...