Class CloudletSchedulerAbstract

java.lang.Object
org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerAbstract
All Implemented Interfaces:
Serializable, CloudletScheduler
Direct Known Subclasses:
CloudletSchedulerSpaceShared, CloudletSchedulerTimeShared

public abstract class CloudletSchedulerAbstract extends Object implements CloudletScheduler
An abstract class for implementing CloudletSchedulers representing scheduling policies performed by a Vm to run its Cloudlets. Each VM must have its own instance of a CloudletScheduler.
Since:
CloudSim Toolkit 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
See Also:
  • Constructor Details

    • CloudletSchedulerAbstract

      protected CloudletSchedulerAbstract()
      Creates a CloudletScheduler.
  • Method Details

    • setPreviousTime

      public final void setPreviousTime(double previousTime)
      Description copied from interface: CloudletScheduler
      Sets the previous time when the scheduler updated the processing of the cloudlets it is managing.
      Specified by:
      setPreviousTime in interface CloudletScheduler
      Parameters:
      previousTime - the new previous time
    • setCurrentMipsShare

      protected void setCurrentMipsShare(@NonNull @NonNull MipsShare currentMipsShare)
      Sets current MIPS share available for the VM using the scheduler.
      Parameters:
      currentMipsShare - the new current MIPS share
      See Also:
      • invalid reference
        #getCurrentMipsShare()
    • getAvailableMipsByPe

      public double getAvailableMipsByPe()
      Gets the amount of MIPS available (free) for each Processor PE, considering the currently executing cloudlets in this processor and the number of PEs these cloudlets require. This is the amount of MIPS that each Cloudlet is allowed to use, since the processor is shared among all executing cloudlets.

      In the case of space shared schedulers, there is no concurrency for PEs because some cloudlets may wait in a queue until there are available PEs to be used exclusively by them.

      Returns:
      the amount of available MIPS for each Processor PE.
    • getCloudletExecList

      public List<CloudletExecution> getCloudletExecList()
      Specified by:
      getCloudletExecList in interface CloudletScheduler
      Returns:
      a read-only List of cloudlets being executed on the VM.
    • getCloudletSubmittedList

      public <T extends Cloudlet> List<T> getCloudletSubmittedList()
      Description copied from interface: CloudletScheduler
      Gets the list of all Cloudlets submitted for a VM so far. This can be used at the end of the simulation to know which Cloudlets have been sent to a VM.

      NOTE: The history in this List is just kept if CloudletScheduler.enableCloudletSubmittedList() is called.

      Specified by:
      getCloudletSubmittedList in interface CloudletScheduler
      Type Parameters:
      T - the class of Cloudlets inside the list
      Returns:
      the list of all submitted Cloudlets
    • enableCloudletSubmittedList

      public CloudletScheduler enableCloudletSubmittedList()
      Description copied from interface: CloudletScheduler
      Enables the history of all Cloudlets submitted so far.
      Specified by:
      enableCloudletSubmittedList in interface CloudletScheduler
      See Also:
    • addCloudletToWaitingList

      protected void addCloudletToWaitingList(CloudletExecution cle)
    • getCloudletWaitingList

      public List<CloudletExecution> getCloudletWaitingList()
      Specified by:
      getCloudletWaitingList in interface CloudletScheduler
      Returns:
      a read-only List of cloudlet waiting to be executed on the VM.
    • sortCloudletWaitingList

      protected void sortCloudletWaitingList(Comparator<CloudletExecution> comparator)
      Sorts the cloudletWaitingList using a given Comparator.
      Parameters:
      comparator - the Comparator to sort the Waiting Cloudlets List
    • cloudletSubmit

      public final double cloudletSubmit(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Receives a cloudlet to be executed in the VM managed by this scheduler.
      Specified by:
      cloudletSubmit in interface CloudletScheduler
      Parameters:
      cloudlet - the submitted cloudlet
      Returns:
      expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
    • cloudletSubmit

      public final double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime)
      Description copied from interface: CloudletScheduler
      Receives a cloudlet to be executed in the VM managed by this scheduler.
      Specified by:
      cloudletSubmit in interface CloudletScheduler
      Parameters:
      cloudlet - the submitted cloudlet
      fileTransferTime - time to move the required files from the Datacenter SAN to the VM
      Returns:
      expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
    • cloudletSubmitInternal

      protected double cloudletSubmitInternal(CloudletExecution cle, double fileTransferTime)
      Receives the execution information of a Cloudlet to be executed in the VM managed by this scheduler.
      Parameters:
      cle - the submitted cloudlet
      fileTransferTime - time required to move the required files from the SAN to the VM (in seconds)
      Returns:
      expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
      See Also:
    • addCloudletToExecList

      protected void addCloudletToExecList(CloudletExecution cle)
      Adds a Cloudlet to the list of cloudlets in execution.
      Parameters:
      cle - the Cloudlet to be added
    • hasFinishedCloudlets

      public boolean hasFinishedCloudlets()
      Description copied from interface: CloudletScheduler
      Informs if there is any cloudlet that finished executing in the VM managed by this scheduler.
      Specified by:
      hasFinishedCloudlets in interface CloudletScheduler
      Returns:
      true if there is at least one finished cloudlet; false otherwise
    • findCloudletInAllLists

      protected Optional<CloudletExecution> findCloudletInAllLists(double cloudletId)
      Search for a Cloudlet into all Cloudlet lists.
      Parameters:
      cloudletId - the id of the Cloudlet to search for
      Returns:
      an Optional value that is able to indicate if the Cloudlet was found or not
    • findCloudletInList

      protected Optional<CloudletExecution> findCloudletInList(Cloudlet cloudlet, List<CloudletExecution> list)
      Search for a Cloudlet into a given list.
      Parameters:
      cloudlet - the Cloudlet to search for
      list - the list to search the Cloudlet into
      Returns:
      an Optional value that is able to indicate if the Cloudlet was found or not
    • cloudletFinish

      protected void cloudletFinish(CloudletExecution cle)
      Processes a finished cloudlet.
      Parameters:
      cle - the finished cloudlet to process
    • cloudletReady

      public boolean cloudletReady(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Sets the status of a Cloudlet to Cloudlet.Status.READY so that it can start executing as soon as possible.
      Specified by:
      cloudletReady in interface CloudletScheduler
      Parameters:
      cloudlet - the cloudlet to be started
      Returns:
      true if cloudlet was set to ready, false otherwise
    • cloudletPause

      public boolean cloudletPause(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Pauses the execution of a cloudlet.
      Specified by:
      cloudletPause in interface CloudletScheduler
      Parameters:
      cloudlet - the cloudlet being paused
      Returns:
      true if cloudlet was paused, false otherwise
    • cloudletFail

      public Cloudlet cloudletFail(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Sets a cloudlet as failed.
      Specified by:
      cloudletFail in interface CloudletScheduler
      Parameters:
      cloudlet - cloudlet to set as failed
      Returns:
      the failed cloudlet or Cloudlet.NULL if not found
    • cloudletCancel

      public Cloudlet cloudletCancel(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Cancels the execution of a cloudlet.
      Specified by:
      cloudletCancel in interface CloudletScheduler
      Parameters:
      cloudlet - the cloudlet being canceled
      Returns:
      the canceled cloudlet or Cloudlet.NULL if not found
    • updateProcessing

      public double updateProcessing(double currentTime, MipsShare mipsShare)
      Description copied from interface: CloudletScheduler
      Updates the processing of cloudlets inside the Vm running under management of this scheduler.
      Specified by:
      updateProcessing in interface CloudletScheduler
      Parameters:
      currentTime - current simulation time
      mipsShare - MIPS share of each Pe available to the scheduler
      Returns:
      the next time to update cloudlets processing (which is a relative delay from the current simulation time), or Double.MAX_VALUE if there is no next Cloudlet to execute
    • updateCloudletProcessing

      protected double updateCloudletProcessing(CloudletExecution cle, double currentTime)
      Updates the processing of a specific cloudlet from the Vm using this scheduler.
      Parameters:
      cle - the cloudlet to be its processing updated
      currentTime - current simulation time
      Returns:
      the next time to update the cloudlet processing (which is a relative delay from the current simulation time) This will be the delay incurred in cloudlet processing caused by (i) vMem usage or (ii) BW reduction due to oversubscription. If no delay is incurred, it returns the expected cloudlet completion time.
    • addOnCloudletResourceAllocationFail

      public CloudletScheduler addOnCloudletResourceAllocationFail(EventListener<CloudletResourceAllocationFailEventInfo> listener)
      Description copied from interface: CloudletScheduler
      Adds a listener object that will be notified every time a CloudletScheduler is not able to allocate the amount of resource a Cloudlet is requesting, due to lack of available capacity.
      Specified by:
      addOnCloudletResourceAllocationFail in interface CloudletScheduler
      Parameters:
      listener - the Listener to add
      Returns:
      this scheduler
    • removeOnCloudletResourceAllocationFail

      public boolean removeOnCloudletResourceAllocationFail(EventListener<CloudletResourceAllocationFailEventInfo> listener)
      Description copied from interface: CloudletScheduler
      Removes a Listener object from the registered List.
      Specified by:
      removeOnCloudletResourceAllocationFail in interface CloudletScheduler
      Parameters:
      listener - the Listener to remove
      Returns:
      true if the Listener was removed, false otherwise
    • removeCloudletFromExecList

      protected CloudletExecution removeCloudletFromExecList(CloudletExecution cle)
      Removes a Cloudlet from the list of cloudlets in execution.
      Parameters:
      cle - the Cloudlet to be removed
      Returns:
      the removed Cloudlet or CloudletExecution.NULL if not found
    • cloudletEstimatedFinishTime

      protected double cloudletEstimatedFinishTime(CloudletExecution cle, double currentTime)
      Gets the estimated time when a given cloudlet is supposed to finish executing. It considers the amount of Vm PES and the total of PEs required by all VMs running inside the VM.
      Parameters:
      cle - cloudlet to get the estimated finish time
      currentTime - current simulation time
      Returns:
      the estimated finish time of the given cloudlet (which is a relative delay from the current simulation time)
    • moveNextCloudletsFromWaitingToExecList

      protected double moveNextCloudletsFromWaitingToExecList(double currentTime)

      Selects the next Cloudlets in the waiting list to move to the execution list to start executing them. While there are enough free PEs, the method tries to find a suitable Cloudlet in the list, until it reaches the end of such a list.

      The method might also exchange some cloudlets in the execution list with some in the waiting list. Thus, some running cloudlets may be preempted to give opportunity to previously waiting cloudlets to run. This is a process called context switch. However, each CloudletScheduler implementation decides how such a process is implemented. For instance, Space-Shared schedulers may perform context switch just after the currently running Cloudlets completely finish executing.

      This method is called internally by the updateProcessing(double,MipsShare).

      Parameters:
      currentTime - current simulation time
      Returns:
      the next time to update the cloudlet processing (which is a relative delay from the current simulation time) This will be the delay incurred in cloudlet processing caused by (i) vMem usage or (ii) BW reduction due to oversubscription. If no delay is incurred, it returns the expected cloudlet completion time.
    • findSuitableWaitingCloudlet

      protected Optional<CloudletExecution> findSuitableWaitingCloudlet()
      Try to find the first Cloudlet in the waiting list that the number of required PEs is not higher than the number of free PEs.
      Returns:
      an Optional containing the found Cloudlet or an empty Optional otherwise
    • isThereEnoughFreePesForCloudlet

      protected boolean isThereEnoughFreePesForCloudlet(CloudletExecution cle)
      Checks if the number of PEs required by a given Cloudlet is free to use.
      Parameters:
      cle - the Cloudlet to get the number of required PEs
      Returns:
      true if there is the number of free PEs, false otherwise
    • addWaitingCloudletToExecList

      protected CloudletExecution addWaitingCloudletToExecList(CloudletExecution cle)
      Removes a Cloudlet from the waiting list and adds it to the exec list.
      Parameters:
      cle - the cloudlet to add to the exec list
      Returns:
      the given cloudlet
    • setVm

      public void setVm(@NonNull @NonNull Vm vm)
      Description copied from interface: CloudletScheduler
      Sets the Vm that will use this scheduler. It is not required to manually set a Vm for the scheduler, since a Vm sets itself to the scheduler when the scheduler is assigned to the Vm.
      Specified by:
      setVm in interface CloudletScheduler
      Parameters:
      vm - the Vm to set
    • getUsedPes

      public long getUsedPes()
      Specified by:
      getUsedPes in interface CloudletScheduler
      Returns:
      the number of currently used Pe's.
    • getFreePes

      public long getFreePes()
      Specified by:
      getFreePes in interface CloudletScheduler
      Returns:
      the number of PEs currently not being used.
    • setTaskScheduler

      public void setTaskScheduler(CloudletTaskScheduler taskScheduler)
      Description copied from interface: CloudletScheduler
      Sets the CloudletTaskScheduler to process cloudlet tasks namely (i) sending or receiving VmPackets by the Vm assigned to the current CloudletScheduler, or (ii) scheduling execution tasks. The Vm from the CloudletScheduler is also set to the CloudletTaskScheduler.

      This attribute usually doesn't need to be set manually. See the note at the CloudletTaskScheduler interface for more details.

      Specified by:
      setTaskScheduler in interface CloudletScheduler
      Parameters:
      taskScheduler - the CloudletTaskScheduler to set for this CloudletScheduler, or CloudletTaskScheduler.NULL if this scheduler will not deal with packets' transmission.
    • isThereTaskScheduler

      public boolean isThereTaskScheduler()
      Description copied from interface: CloudletScheduler
      Checks if there is a CloudletTaskScheduler assigned to this CloudletScheduler to enable tasks execution and dispatching packets from and to the Vm of this CloudletScheduler.
      Specified by:
      isThereTaskScheduler in interface CloudletScheduler
      Returns:
      true if a CloudletTaskScheduler is assigned to this CloudletScheduler; false otherwise
    • getRequestedCpuPercent

      public double getRequestedCpuPercent(double time)
      Description copied from interface: CloudletScheduler
      Gets total CPU percentage requested (from MIPS capacity) from all cloudlets, according to CPU UtilizationModel of each Cloudlet.
      Specified by:
      getRequestedCpuPercent in interface CloudletScheduler
      Parameters:
      time - the time to get the current CPU utilization
      Returns:
      the total CPU percentage requested (in scale from 0 to 1, where 1 is 100%)
    • getAllocatedCpuPercent

      public double getAllocatedCpuPercent(double time)
      Description copied from interface: CloudletScheduler
      Gets total CPU utilization percentage allocated (from MIPS capacity) to all cloudlets, according to CPU UtilizationModel of each Cloudlet.
      Specified by:
      getAllocatedCpuPercent in interface CloudletScheduler
      Parameters:
      time - the time to get the current CPU utilization
      Returns:
      the total CPU utilization percentage allocated (in scale from 0 to 1, where 1 is 100%).
    • getRequestedMipsForCloudlet

      protected double getRequestedMipsForCloudlet(CloudletExecution cle, double time)
      Gets the current requested MIPS for a given cloudlet.
      Parameters:
      cle - the Cloudlet to get the requested MIPS
      time - the current simulation time
      Returns:
      the current requested MIPS for the given cloudlet
    • getAllocatedMipsForCloudlet

      public double getAllocatedMipsForCloudlet(CloudletExecution cle, double time)
      Gets the current allocated MIPS for a cloudlet.
      Parameters:
      cle - the cloudlet to get the allocated MIPS
      time - the current simulation time
      Returns:
      the current allocated mips for cloudlet
    • getAllocatedMipsForCloudlet

      public double getAllocatedMipsForCloudlet(CloudletExecution cle, double time, boolean log)
      Gets the current allocated MIPS for cloudlet.
      Parameters:
      cle - the cloudlet to get the allocated MIPS
      time - the current simulation time
      log - Indicate if a log should be issued when the requested resource is larger than the capacity
      Returns:
      the current allocated mips for cloudlet
    • getCurrentRequestedBwPercentUtilization

      public double getCurrentRequestedBwPercentUtilization()
      Description copied from interface: CloudletScheduler
      Gets the current utilization percentage of Bandwidth that the running Cloudlets are requesting (in scale from 0 to 1).
      Specified by:
      getCurrentRequestedBwPercentUtilization in interface CloudletScheduler
      Returns:
      the BW utilization percentage from 0 to 1 (where 1 is 100%)
    • getCurrentRequestedRamPercentUtilization

      public double getCurrentRequestedRamPercentUtilization()
      Description copied from interface: CloudletScheduler
      Gets the current utilization percentage of RAM that the running Cloudlets are requesting (in scale from 0 to 1).
      Specified by:
      getCurrentRequestedRamPercentUtilization in interface CloudletScheduler
      Returns:
      the RAM utilization percentage from 0 to 1 (where 1 is 100%)
    • getCloudletReturnedList

      protected Set<Cloudlet> getCloudletReturnedList()
      Returns a read-only list of Cloudlets that finished executing and were returned to the broker. A Cloudlet is returned to notify the broker about the end of its execution.
      Returns:
      a read-only list of Cloudlets that finished executing and were returned to the broker
    • addCloudletToReturnedList

      public void addCloudletToReturnedList(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Adds a Cloudlet to the list of finished Cloudlets that have been returned to its DatacenterBroker.
      Specified by:
      addCloudletToReturnedList in interface CloudletScheduler
      Parameters:
      cloudlet - the Cloudlet to be added
    • deallocatePesFromVm

      public void deallocatePesFromVm(long pesToRemove)
      Description copied from interface: CloudletScheduler
      Releases a given number of PEs from a VM.
      Specified by:
      deallocatePesFromVm in interface CloudletScheduler
      Parameters:
      pesToRemove - number of PEs to deallocate
    • getCloudletList

      public List<Cloudlet> getCloudletList()
      Specified by:
      getCloudletList in interface CloudletScheduler
      Returns:
      a read-only List of all cloudlets that are either waiting or executing on the VM.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: CloudletScheduler
      Checks if there aren't cloudlets waiting or executing inside the Vm.
      Specified by:
      isEmpty in interface CloudletScheduler
      Returns:
      true if the scheduler has no cloudlets to execute or waiting to be executed; false otherwise
    • canExecuteCloudletInternal

      protected abstract boolean canExecuteCloudletInternal(CloudletExecution cle)
      See Also:
      • canExecuteCloudlet(CloudletExecution)
    • clear

      public void clear()
      Description copied from interface: CloudletScheduler
      Clears the internal state of the scheduler
      Specified by:
      clear in interface CloudletScheduler