CloudSim源代码学习之虚拟机分配策略.doc_第1页
CloudSim源代码学习之虚拟机分配策略.doc_第2页
CloudSim源代码学习之虚拟机分配策略.doc_第3页
CloudSim源代码学习之虚拟机分配策略.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

package org.cloudbus.cloudsim;import java.util.List;/An ordered collection (also known as a sequence)import java.util.Map;/【补充:针对java.util.Map的Value做排序 来源:360doc】针对java.util.Map的Value做排序:/Map的特性:/Map内涵数据是Key - Value的架构集合体,而Key是属于Set的架构集合体,也就是说Key的值是唯一的,而Value的值可以重复。一般常用的对象是HashMap或TreeMap,如果考虑效能的话,建议使用HashMap,如果希望Key值有顺序性,就使用TreeMap吧!所以Map的集合体,数据的摆放方式是没有顺序性的,我们需要借助有顺序性的集合体List来帮忙。/范例数据如下定义:/Map map_Data = new HashMap();/map_Data.put(A, 98);/map_Data.put(B, 50);/map_Data.put(C, 76);/map_Data.put(D, 23);/map_Data.put(E, 85);/System.out.println(map_Data);现在将Map集合体转换成List集合体,而List对象使用ArrayList来实做如下:/将map_Data由Map型态转成List型态的list_Data,以便进行排序/ListMap.Entry list_Data = new ArrayListMap.Entry(map_Data.entrySet();/透过Collections.sort(List l, Comparator c)方法来做排序的动作,由传入参数可以了解List l就是要排序的数据结构体,另外还需要一个Comparator c对象,此对象是用来评估List l中的任两对象的大小值,实做如下:/排序/Collections.sort(list_Data, new ComparatorMap.Entry()/ /public int compare(Map.Entry o1, Map.Entry o2)/ /return (o2.getValue() - o1.getValue();/);/上方的Comparator c参数是使用匿名类别的方式来实做的。所以排序完成的数据内容在list_Data这个对象中,将其印出来看结果:/System.out.println(list_Data); /*【VmAllocationPolicy 抽象类 代表数据中心主机到虚拟机的供应协议】 * VmAllocationPolicy is an abstract class that represents the provisioning * policy of hosts to virtual machines in a Datacentre. It supports【 two-stage * commit of reservation of hosts】: first, we reserve the host and, once * commited by the user, it is effectivelly allocated to he/she * * authorRodrigo N. Calheiros * authorAnton Beloglazov * sinceCloudSim Toolkit 1.0 */public abstract class VmAllocationPolicy /* The host list. 主机列表*/private List hostList;/限制泛型/*分配一新的VmAllocationPolicy对象 * Allocates a new VmAllocationPolicy object. * * param list Machines available in this Datacentre * * pre $none * post $none */public VmAllocationPolicy(List list) setHostList(list);/*分配主机给一特定虚拟机 * Allocates a host for a given VM. The host to be allocated is the one * that was already reserved. * * param vm virtual machine which the host is reserved to * * return $true if the host could be allocated; $false otherwise * * pre $none * post $none */public abstract boolean allocateHostForVm(Vm vm);/*分配一特定主机给指定虚拟机 * Allocates a specified host for a given VM. * * param vm virtual machine which the host is reserved to * * return $true if the host could be allocated; $false otherwise * * pre $none * post $none */public abstract boolean allocateHostForVm(Vm vm, Host host);/*【根据当前利用率最优虚拟机分配】 * Optimize allocation of the VMs according to current utilization. * * param vmList the vm list * param utilizationBound the utilization bound * param time the time * * return the array list hash map */public abstract ListMap optimizeAllocation(List vmList);/*释放主机 * Releases the host used by a VM. * * param vm the vm * * pre $none * post $none */public abstract void deallocateHostForVm(Vm vm);/*指定用户指定虚拟机上的主机 * Get 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 */public abstract Host getHost(Vm vm);/* 与上面同样的功能 ? * Get 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 */public abstract Host getHost(int vmId, int userId);/*设置主机列表 * Sets the host list. * * param hostList the new host list */protected void setH

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论