Vmscheduler. Java

Source: Internet
Author: User
/** Title: cloudsim toolkit * Description: cloudsim (cloud simulation) Toolkit for modeling and simulation of clouds * Licence: GPL-http://www.gnu.org/copyleft/gpl.html ** copyright (c) 2009-2010, the University of Melbourne, Australia */package Org. cloudid. cloudsim; import Java. util. hashmap; import Java. util. list; import Java. util. map; import Org. cloudid. cloudsim. lists. pelist;/*** VM scheduling policy (space and time) * Vmscheduler is an abstract class that represents the * policy used by a vmm to share processing power among VMS running * in a host. ** @ authorrodrigo n. calheiros * @ authoranton beloglazov * @ sincecloudsim toolkit 1.0 */public abstract class vmscheduler {/** the pelist. each host has a PE list */private list <? Extends PE> pelist;/** the MIPs that are currently allocated to the VMS. * record the MIPs allocated to each VM **/private Map <string, list <double> mipsmap;/** the total available MIPS. */private double availablemips;/*** creates a new hostallocationpolicy. ** @ Param pelist the pelist ** @ pre pelist! = $ Null * @ post $ none */Public vmscheduler (list <? Extends PE> pelist) {setpelist (pelist); setmipsmap (New hashmap <string, list <double> (); setavailablemips (pelist. gettotalmips (getpelist ();}/*** allocates PES for a VM. ** @ Param vm The VM * @ Param mipsshare the MIPs share ** @ return $ true if this policy allows a new VM in the host, $ false otherwise ** @ pre $ none * @ post $ none */Public Abstract Boolean allocatepesforvm (Vm, list <double> MIPss Hare);/*** releases PES allocated to a VM. ** @ Param vm The VM ** @ pre $ none * @ post $ none */public abstract void deallocatepesforvm (Vm VM);/*** reclaim the MIPs of all VMS. * 1. Perform all PE operations on the host * 2. Perform all VM operations on each Pe * releases PES allocated to all the VMS. ** @ Param vm The VM ** @ pre $ none * @ post $ none */Public void deallocatepesforallvms () {getmipsmap (). clear (); setavailablemips (pelist. gettotalmips (getpelist (); // all the mipsfor (PE: getpelist () {PE. getpeprovisioner (). deallocatemipsforallvms (); // reclaim all MIPS for each PE}/*** returns the MIPs share of each PE that is allocated A given VM. * return the MIPs list used by a specific VM * @ Param vm The VM ** @ return an array containing the amount of MIPs of each PE that is available to the VM ** @ pre $ none * @ post $ none */public list <double> getallocatedmipsforvm (Vm VM) {return getmipsmap (). get (VM. getuid ();}/*** gets the total allocated MIPS for a VM over all the PES. * The MIPs occupied by a VM * @ Param vm The VM ** @ return the allocated MIPS for VM */pub LIC double gettotalallocatedmipsforvm (Vm VM) {double allocated = 0; List <double> mipsmap = getallocatedmipsforvm (VM); If (mipsmap! = NULL) {for (double MIPS: mipsmap) {allocated + = MIPS;} return allocated;}/*** returns maximum available MIPS among all the PES. * returns the maximum available MIPS * @ return Max MIPS */Public double getmaxavailablemips () {If (getpelist () = NULL) {log. printline ("PE list is empty"); Return 0;} double max = 0.0; For (PE: getpelist () {double TMP = PE. getpeprovisioner (). getavailablemips (); If (TMP> MAX) {max = TMP ;}} return Max ;}/ *** returns PE capacity in MIPS. * MIPS * @ return MIPS */Public double getpecapacity () {If (getpelist () = NULL) {log of the first PE. printline ("PE list is empty"); Return 0;} return getpelist (). get (0 ). getmips ();}/*** gets the VM list. * VM scheduling is actually the PE allocation policy in the Host * returns the PE list * @ return the VM list */@ suppresswarnings ("unchecked ") public <t extends PE> List <t> getpelist () {return (list <t>) pelist;}/*** sets the VM list. ** @ Param pelist the PE list */protected <t extends PE> void setpelist (list <t> pelist) {This. pelist = pelist;}/*** gets the MIPs map. * obtain the list of PES in use. pelist * @ return the MIPs map */protected Map <string, list <double> getmipsmap () {return mipsmap ;} /*** sets the MIPs map. ** @ Param mipsmap the MIPs map */protected void setmipsmap (Map <string, list <double> mipsmap) {This. mipsmap = mipsmap;}/*** gets the free MIPS. ** @ return the free MIPS */Public double getavailablemips () {return availablemips;}/*** sets the free MIPS. ** @ Param availablemips the new free MIPS */protected void setavailablemips (double availablemips) {This. availablemips = availablemips ;}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.