Class DatacenterBrokerAbstract

java.lang.Object
org.cloudsimplus.core.CloudSimEntity
org.cloudsimplus.brokers.DatacenterBrokerAbstract
All Implemented Interfaces:
Comparable<SimEntity>, Runnable, DatacenterBroker, Identifiable, Nameable, SimEntity
Direct Known Subclasses:
DatacenterBrokerSimple

public abstract class DatacenterBrokerAbstract extends CloudSimEntity implements DatacenterBroker
An abstract class for implementing DatacenterBrokers.
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
  • Constructor Details

    • DatacenterBrokerAbstract

      public DatacenterBrokerAbstract(CloudSimPlus simulation, String name)
      Creates a DatacenterBroker giving a specific name.
      Parameters:
      simulation - the CloudSimPlus instance that represents the simulation the Entity is related to
      name - the DatacenterBroker name
  • Method Details

    • setSelectClosestDatacenter

      public final DatacenterBroker setSelectClosestDatacenter(boolean select)
      Description copied from interface: DatacenterBroker
      Defines if the broker has to try selecting the closest Datacenter to place Vms, based on their timezone. The default behaviour is to ignore Datacenters and Vms timezones.
      Specified by:
      setSelectClosestDatacenter in interface DatacenterBroker
      Parameters:
      select - true to try selecting the closest Datacenter, false to ignore distance
      Returns:
      this broker instance
    • submitVmList

      public DatacenterBroker submitVmList(List<? extends Vm> list, double submissionDelay)
      Description copied from interface: DatacenterBroker
      Submits a list of Vm or VmGroup to the broker so that their creation inside some Host will be requested just after a given delay. Just the VMs that don't have a delay already assigned will have its submission delay changed. All VMs will be added to the DatacenterBroker.getVmWaitingList().

      When a VmGroup is given, it will try to place all VMs from the group into the same Host.

      Specified by:
      submitVmList in interface DatacenterBroker
      Parameters:
      list - the list of Vm or VmGroup to request the creation
      submissionDelay - the delay the broker has to include when requesting the creation of VMs
      Returns:
      this broker instance
      See Also:
    • submitVmList

      public DatacenterBroker submitVmList(List<? extends Vm> list)
      Submits a list of Vm or VmGroup where their creation inside a Host will be requested to some Datacenter. The Datacenter that will be chosen to place a VM is determined by the DatacenterBroker.setDatacenterMapper(BiFunction).

      When a VmGroup is given, it will try to place all VMs from the group into the same Host.

      The individual submission delay of VMs inside a group will be ignored. Only the submission delay directly set for the VmGroup will be considered.

      If the entity already started (the simulation is running), the creation of previously submitted VMs was already requested by the CloudSimEntity.start() method, which is called just once. This way, this method will immediately request the creation of these submitted VMs in order to allow VM creation after the simulation has started. This avoids the developer to dynamically create brokers just to submit VMs or Cloudlets during simulation execution.

      Specified by:
      submitVmList in interface DatacenterBroker
      Parameters:
      list - the list of Vm or VmGroup to request the creation
      Returns:
      this broker instance
      See Also:
    • submitVm

      public DatacenterBroker submitVm(@NonNull @NonNull Vm vm)
      Description copied from interface: DatacenterBroker
      Submits a single Vm or VmGroup to the broker. When a VmGroup is given, it will try to place all VMs from the group into the same Host.
      Specified by:
      submitVm in interface DatacenterBroker
      Parameters:
      vm - the Vm or VmGroup to be submitted
      Returns:
      this broker instance
    • submitCloudlet

      public DatacenterBroker submitCloudlet(@NonNull @NonNull Cloudlet cloudlet)
      Description copied from interface: DatacenterBroker
      Submits a single Cloudlet to the broker so that it requests their creation inside some VM.
      Specified by:
      submitCloudlet in interface DatacenterBroker
      Parameters:
      cloudlet - the Cloudlet to be submitted
      Returns:
      this broker instance
      See Also:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list, double submissionDelay)
      Description copied from interface: DatacenterBroker
      Sends a list of cloudlets to the broker so that it requests their creation inside some VM just after a given delay. Just the Cloudlets that don't have a delay already assigned will have its submission delay changed. All cloudlets will be added to the DatacenterBroker.getCloudletWaitingList(), setting their submission delay to the specified value.
      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      submissionDelay - the delay the broker has to include when requesting the creation of Cloudlets
      Returns:
      this broker instance
      See Also:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list, Vm vm)
      Description copied from interface: DatacenterBroker
      Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM, following the submission delay specified in each cloudlet (if any). All cloudlets will be added to the DatacenterBroker.getCloudletWaitingList().
      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      vm - the VM to which all Cloudlets will be bound to
      Returns:
      this broker instance
      See Also:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list, Vm vm, double submissionDelay)
      Description copied from interface: DatacenterBroker
      Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM just after a given delay. Just the Cloudlets that don't have a delay already assigned will have its submission delay changed. All cloudlets will be added to the DatacenterBroker.getCloudletWaitingList(), setting their submission delay to the specified value.
      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      vm - the VM to which all Cloudlets will be bound to
      submissionDelay - the delay the broker has to include when requesting the creation of Cloudlets
      Returns:
      this broker instance
      See Also:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list)
      Sends a list of cloudlets to the broker so that it requests their creation inside some VM, following the submission delay specified in each cloudlet (if any). All cloudlets will be added to the DatacenterBroker.getCloudletWaitingList().

      If the entity already started (the simulation is running), the creation of previously submitted Cloudlets was already requested by the CloudSimEntity.start() method, which is called just once. This way, this method will immediately request the creation of these submitted Cloudlets if all submitted VMs were already created, in order to allow Cloudlet creation after the simulation has started. This avoids the developer to dynamically create brokers just to submit VMs or Cloudlets during simulation execution.

      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      Returns:
      this broker instance
      See Also:
    • bindCloudletToVm

      public boolean bindCloudletToVm(Cloudlet cloudlet, Vm vm)
      Description copied from interface: DatacenterBroker
      Specifies that an already submitted cloudlet, which is in the waiting list, must run in a specific virtual machine.
      Specified by:
      bindCloudletToVm in interface DatacenterBroker
      Parameters:
      cloudlet - the cloudlet to be bind to a given Vm
      vm - the vm to bind the Cloudlet to
      Returns:
      true if the Cloudlet was found in the waiting list and was bind to the given Vm; false if the Cloudlet was not found in such a list (that may mean it wasn't submitted yet or was already created)
    • processEvent

      public void processEvent(SimEvent evt)
      Description copied from interface: SimEntity
      Processes events or services that are available for the entity. This method is invoked, by the CloudSimPlus class, whenever there is an event in the deferred queue that needs to be processed by the entity.
      Specified by:
      processEvent in interface SimEntity
      Parameters:
      evt - information about the event just happened
    • getVmsNumber

      public int getVmsNumber()
      Description copied from interface: DatacenterBroker
      Returns the total number of VMs submitted to the broker, including created, waiting and failed VMs.
      Specified by:
      getVmsNumber in interface DatacenterBroker
      Returns:
      the total number of VMs submitted to the broker, including created, waiting and failed VMs
    • requestIdleVmDestruction

      public DatacenterBroker requestIdleVmDestruction(Vm vm)
      Description copied from interface: DatacenterBroker
      Checks if a VM is idle VM and request it to be destroyed at the time defined by the DatacenterBroker.setVmDestructionDelayFunction(Function). The request will be sent if the given delay function returns a value greater than DatacenterBroker.DEF_VM_DESTRUCTION_DELAY. Otherwise, it doesn't send the request, meaning the VM should not be destroyed according to a specific delay.
      Specified by:
      requestIdleVmDestruction in interface DatacenterBroker
      Parameters:
      vm - the VM to destroy
      Returns:
      this broker instance
      See Also:
    • requestShutdownWhenIdle

      public void requestShutdownWhenIdle()
      Description copied from interface: DatacenterBroker
      Requests the broker shutdown if it's idle.
      Specified by:
      requestShutdownWhenIdle in interface DatacenterBroker
    • requestDatacentersToCreateWaitingCloudlets

      protected void requestDatacentersToCreateWaitingCloudlets()
      Request Datacenters to create the Cloudlets in the waiting list. If there aren't available VMs to host all cloudlets, the creation of some of them will be postponed.

      This method is called after all submitted VMs are created in some Datacenter.

      See Also:
    • shutdown

      public void shutdown()
      Description copied from interface: SimEntity
      Shuts down the entity. This method is invoked by CloudSimPlus before the simulation finishes. If you want to save data in log files, this is the method in which the corresponding code may be placed.
      Specified by:
      shutdown in interface SimEntity
      Overrides:
      shutdown in class CloudSimEntity
    • startInternal

      public void startInternal()
      Description copied from class: CloudSimEntity
      Defines the logic to be performed by the entity when the simulation starts.
      Specified by:
      startInternal in class CloudSimEntity
    • getVmCreatedList

      public <T extends Vm> List<T> getVmCreatedList()
      Description copied from interface: DatacenterBroker
      Gets the list of all VMs created so far, independently if they are running yet or were already destroyed. This can be used at the end of the simulation to know which VMs have executed.
      Specified by:
      getVmCreatedList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of created VMs
      See Also:
    • getVmExecList

      public <T extends Vm> List<T> getVmExecList()
      Description copied from interface: DatacenterBroker
      Gets the list of VMs in execution, if they are running Cloudlets or not. These VMs can receive new submitted Cloudlets.
      Specified by:
      getVmExecList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of running VMs
      See Also:
    • getVmWaitingList

      public <T extends Vm> List<T> getVmWaitingList()
      Description copied from interface: DatacenterBroker
      Gets a List of VMs submitted to the broker that are waiting to be created inside some Datacenter yet.
      Specified by:
      getVmWaitingList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of waiting VMs
    • getVmFailedList

      public <T extends Vm> List<T> getVmFailedList()
      Description copied from interface: DatacenterBroker
      Gets a List of VMs submitted to the broker that have failed to be created inside some Datacenter due to lack of suitable Hosts. VMs are just moved to that list if VmCreation.isRetryFailedVms() is not enabled.
      Specified by:
      getVmFailedList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of failed VMs
      See Also:
      • invalid reference
        VmCreation#setRetryDelay(double)
    • getWaitingVm

      public Vm getWaitingVm(int index)
      Description copied from interface: DatacenterBroker
      Gets a VM from the waiting list.
      Specified by:
      getWaitingVm in interface DatacenterBroker
      Parameters:
      index - the index of the VM to get
      Returns:
      the waiting VM
    • getCloudletWaitingList

      public <T extends Cloudlet> List<T> getCloudletWaitingList()
      Description copied from interface: DatacenterBroker
      Gets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.
      Specified by:
      getCloudletWaitingList in interface DatacenterBroker
      Type Parameters:
      T - the class of Cloudlets inside the list
      Returns:
      the cloudlet waiting list
    • getCloudletFinishedList

      public <T extends Cloudlet> List<T> getCloudletFinishedList()
      Description copied from interface: DatacenterBroker
      Gets a copy of the list of cloudlets that have finished executing, to avoid the original list to be changed.
      Specified by:
      getCloudletFinishedList in interface DatacenterBroker
      Type Parameters:
      T - the class of Cloudlets inside the list
      Returns:
      the list of finished cloudlets
    • getVmFromCreatedList

      protected Vm getVmFromCreatedList(int vmIndex)
      Gets a Vm at a given index from the list of created VMs.
      Parameters:
      vmIndex - the index where a VM has to be got from the created VM list
      Returns:
      the VM at the given index or Vm.NULL if the index is invalid
    • getDatacenter

      protected Datacenter getDatacenter(Vm vm)
      Returns the Datacenter where a VM is placed.
      Parameters:
      vm - the VM to get its Datacenter
      Returns:
      the Datacenter where a VM is placed
    • addOnVmsCreatedListener

      public DatacenterBroker addOnVmsCreatedListener(@NonNull @NonNull EventListener<DatacenterBrokerEventInfo> listener)
      Description copied from interface: DatacenterBroker
      Adds an EventListener that will be notified every time all VMs in the waiting list are created (placed) in some Host.

      Events are fired according to the following conditions:

      • if all VMs are submitted before the simulation start and all those VMs are created after starting, then the event will be fired just once, in the entire simulation execution time, for every registered Listener;
      • if new VMs are submitted during simulation execution, the event may be fired multiple times. For instance, consider new VMs are submitted during simulation execution at times 10 and 20. If for every submission time, all VMs could be created, then every Listener will be notified 2 times (one for VMs submitted at time 10 and other for those at time 20).
      If all VMs submitted at a given time cannot be created due to lack of suitable Hosts, the event will not be fired for that submission.

      Specified by:
      addOnVmsCreatedListener in interface DatacenterBroker
      Parameters:
      listener - the Listener that will be notified
      Returns:
      this broker instance
      See Also:
    • removeOnVmsCreatedListener

      public DatacenterBroker removeOnVmsCreatedListener(@NonNull @NonNull EventListener<? extends EventInfo> listener)
      Description copied from interface: DatacenterBroker
      Removes an EventListener to stop it from being notified when VMs in the waiting list are all created.
      Specified by:
      removeOnVmsCreatedListener in interface DatacenterBroker
      Parameters:
      listener - the Listener that will be removed
      Returns:
      this broker instance
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setVmDestructionDelay

      public DatacenterBroker setVmDestructionDelay(double delay)
      Description copied from interface: DatacenterBroker
      Sets the delay after which an idle VM should be destroyed. Using such a method, it defines the same delay for any VM that becomes idle. If you need to define different delays for distinct VMs use the DatacenterBroker.setVmDestructionDelayFunction(Function) method.
      Specified by:
      setVmDestructionDelay in interface DatacenterBroker
      Parameters:
      delay - the time (in seconds) to wait before destroying idle VMs. A negative value indicates that NO VM should be immediately destroyed after becoming idle
      Returns:
      this broker instance
      See Also:
    • setVmDestructionDelayFunction

      public DatacenterBroker setVmDestructionDelayFunction(Function<Vm,Double> function)
      Sets a Function to define the delay after which an idle VM should be destroyed. The Function must receive a Vm and return the delay to wait (in seconds), after the VM becomes idle, to destroy it.

      By providing a Function to indicate when idle VMs should be destroyed enables you to define different delays for every VM that becomes idle, according to desired conditions.

      WARNING: The delay returned by the given function should be larger than the Simulation.getMinTimeBetweenEvents() to ensure VMs are gracefully shutdown.

      If null is given, the default VM destruction delay function will be used.

      Specified by:
      setVmDestructionDelayFunction in interface DatacenterBroker
      Parameters:
      function - the Function to set (if null is given, no idle VM will be automatically destroyed)
      Returns:
      this broker instance
      See Also:
    • defaultDatacenterMapper

      protected abstract Datacenter defaultDatacenterMapper(Datacenter lastDatacenter, Vm vm)
      Selects a Datacenter to request the creating of waiting VMs. This is the default policy used to select a Datacenter to run waiting VMs, if the selection of the closest datacenter is disabled.
      Parameters:
      lastDatacenter - the last selected Datacenter
      vm - the VM trying to be created
      Returns:
      the selected datacenter or Datacenter.NULL if no suitable Datacenter was found
      See Also:
    • closestDatacenterMapper

      protected Datacenter closestDatacenterMapper(Datacenter lastDatacenter, Vm vm)
      Selects the closest Datacenter to request the creating of waiting VMs, according to their timezone offset. This policy is just used if the selection of the closest datacenter is enabled.
      Parameters:
      lastDatacenter - the last selected Datacenter
      vm - the VM trying to be created
      Returns:
      the selected datacenter or Datacenter.NULL if no suitable Datacenter was found
      See Also:
    • defaultVmMapper

      protected abstract Vm defaultVmMapper(Cloudlet cloudlet)
      Selects a VM to execute a given Cloudlet. The method defines the default policy used to map VMs for Cloudlets that are waiting to be created.

      Since this policy can be dynamically changed by calling DatacenterBroker.setVmMapper(Function), this method will always return the default policy provided by the subclass where the method is being called.

      Parameters:
      cloudlet - the cloudlet that needs a VM to execute
      Returns:
      the selected Vm for the cloudlet or Vm.NULL if no suitable VM was found
      See Also: