



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package org.cloudbus.cloudsim;import java.util.ArrayList;/Resizable-array implementation of the List interface import java.util.HashMap;/散列表要解决的一个问题就是散列值的冲突问题,通常是两种方法:链表法和开放地址法。链表法就是将相同hash值的对象组织成一个链表放在hash值对应的槽位 (来源:/news/1012/527961.html)import java.util.List;/An ordered collection (also known as a sequence)import java.util.Map;/An object that maps keys to valuesimport org.cloudbus.cloudsim.core.CloudSim;/* * VmAllocationPolicySimple is an VmAllocationPolicy that * chooses, as the host for a VM, (the host with * less PEs in use.) * * authorRodrigo N. Calheiros * authorAnton Beloglazov * sinceCloudSim Toolkit 1.0 */public class VmAllocationPolicySimple extends VmAllocationPolicy /* The vm table. 虚拟机表*/private Map vmTable;/* The used pes. 已使用的PE*/private Map usedPes;/* The free pes.空闲的PE */private List freePes;/*创建新的对象 * Creates the new VmAllocationPolicySimple object. * * param list the list * * pre $none * post $none */public VmAllocationPolicySimple(List list) super(list);setFreePes(new ArrayList();for (Host host : getHostList() getFreePes().add(host.getPesNumber();setVmTable(new HashMap();setUsedPes(new HashMap();/*分配一主机给指定的VM * Allocates a host for a given VM. * * param vm VM specification * * return $true if the host could be allocated; $false otherwise * * pre $none * post $none */Overridepublic boolean allocateHostForVm(Vm vm) /implements org.cloudbus.cloudsim.VmAllocationPolicy.allocateHostForVmint requiredPes = vm.getPesNumber();boolean result = false;int tries = 0;List freePesTmp = new ArrayList();for (Integer freePes : getFreePes() freePesTmp.add(freePes);if (!getVmTable().containsKey(vm.getUid() /if this vm was not created虚拟机没创建do /we still trying until we find a host or until we try all of themint moreFree = Integer.MIN_VALUE;int idx = -1;/we want the host with less pes in use较少的pe使用for (int i=0; i moreFree) /moreFree = Integer.MIN_VALUE最小值moreFree = freePesTmp.get(i);idx = i;Host host = getHostList().get(idx);result = host.vmCreate(vm);if (result) /if vm were succesfully created in the host虚拟机已成功创建/Log.printLine(VmAllocationPolicy: VM #+vm.getVmId()+ Chosen host: #+host.getMachineID()+ idx:+idx);getVmTable().put(vm.getUid(), host);getUsedPes().put(vm.getUid(), requiredPes);getFreePes().set(idx, getFreePes().get(idx) - requiredPes);result = true;break; else freePesTmp.set(idx, Integer.MIN_VALUE);tries+; while (!result & tries getFreePes().size();return result;/*释放主机 * Releases the host used by a VM. * * param vm the vm * * pre $none * post none */Overridepublic void deallocateHostForVm(Vm vm) /implements org.cloudbus.cloudsim.VmAllocationPolicy.deallocateHostForVmHost host = getVmTable().remove(vm.getUid();int idx = getHostList().indexOf(host);int pes = getUsedPes().remove(vm.getUid();if (host != null) host.vmDestroy(vm);getFreePes().set(idx, getFreePes().get(idx) + pes);/*属于特定用户指定虚拟机的主机 * Gets the host that is executing the given VM belonging to the * given user. * * param vm the vm * * return the Host with the given vmID and userID; $null if not found * * pre $none * post $none */Overridepublic Host getHost(Vm vm) /implements org.cloudbus.cloudsim.VmAllocationPolicy.getHostreturn getVmTable().get(vm.getUid();/*与上面有什么不同 * Gets the host that is executing the given VM belonging to the * given user. * * param vmId the vm id * param userId the user id * * return the Host with the given vmID and userID; $null if not found * * pre $none * post $none */Overridepublic Host getHost(int vmId, int userId) /implements org.cloudbus.cloudsim.VmAllocationPolicy.getHostreturn getVmTable().get(Vm.getUid(userId, vmId);/*获取vm表 * Gets the vm table. * * return the vm table */public Map getVmTable() return vmTable;/*设置vm表 * Sets the vm table. * * param vmTable the vm table */protected void setVmTable(Map vmTable) this.vmTable = vmTable;/*已使用的PE * Gets the used pes. * * return the used pes */protected Map getUsedPes() return usedPes;/*设置已使用的pe * Sets the used pes. * * param usedPes the used pes */protected void setUsedPes(Map usedPes) this.usedPes = usedPes;/*空闲的pe * Gets the free pes. * * return the free pes */protected List getFreePes() return freePes;/*设置空闲pe * Sets the free pes. * * param freePes the new free pes */protected void setFreePes(List freePes) this.freePes = freePes;/以下不知道具体作用!/* (non-Javadoc) * see cloudsim.VmAllocationPolicy#optimizeAllocation(double, cloudsim.VmList, double) */Overridepublic ListMap optimizeAllocation(List vmList) / TODO Auto-generated method stubreturn null;/* (non-Javadoc) * see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm, org.cloudbus.cloudsim.Host) */Overridepublic boolean allocateHostForVm(Vm vm, Ho
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 12月输电带电作业理论知识试题库及参考答案
- 2025农产品种子购销合同(大豆)
- 2025安全工作年终总结汇编(第十四篇)
- 大学毕业论文致谢词范文8篇
- 标准日本语初级下册第32課 今度のにちようびにゆうえんちへ行くつもりです教案
- 2025关于农村信用社融资租赁合同的范本
- 第8课 机器人走迷宫说课稿-2023-2024学年初中信息技术(信息科技)九年级下册川教版(旧版)
- 苏教版七年级生物上册1.1.1我们周围的生物说课稿
- 病房无障碍设施改造与适老化设计方案
- 2025设备租赁合同范本全新示例
- 桥梁基本知识-桥梁养护课件
- 外科学-腹外疝
- 华为供应链管理(6版)
- 幼儿园秋季传染病预防知识课件
- 化工原理-传热课件
- 劳务派遣劳务外包服务方案(技术方案)
- 第09章资本市场有效性理论及其实证分析
- 《商务分析方法与工具》课程教学大纲
- 模块化硬件设计方案
- 高中日语开学第一课导入课课件
- 关键工序质量控制表
评论
0/150
提交评论