Class DatacenterBrokerAbstract
- All Implemented Interfaces:
Comparable<SimEntity>,Runnable,DatacenterBroker,Identifiable,Nameable,SimEntity
- Direct Known Subclasses:
DatacenterBrokerSimple
DatacenterBrokers.- Author:
- Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cloudsimplus.core.SimEntity
SimEntity.State -
Field Summary
Fields inherited from interface org.cloudsimplus.brokers.DatacenterBroker
DEF_VM_DESTRUCTION_DELAY, LOGGER, NULL -
Constructor Summary
ConstructorsConstructorDescriptionDatacenterBrokerAbstract(CloudSimPlus simulation, String name) Creates a DatacenterBroker giving a specific name. -
Method Summary
Modifier and TypeMethodDescriptionaddOnVmsCreatedListener(@NonNull EventListener<DatacenterBrokerEventInfo> listener) Adds anEventListenerthat will be notified every time all VMs in the waiting list are created (placed) in some Host.booleanbindCloudletToVm(Cloudlet cloudlet, Vm vm) Specifies that an already submitted cloudlet, which is in thewaiting list, must run in a specific virtual machine.protected DatacenterclosestDatacenterMapper(Datacenter lastDatacenter, Vm vm) Selects the closest Datacenter to request the creating of waiting VMs, according to their timezone offset.protected abstract DatacenterdefaultDatacenterMapper(Datacenter lastDatacenter, Vm vm) Selects a Datacenter to request the creating of waiting VMs.protected abstract VmdefaultVmMapper(Cloudlet cloudlet) Selects a VM to execute a given Cloudlet.Gets a copy of the list of cloudlets that have finished executing, to avoid the original list to be changed.Gets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.protected DatacentergetDatacenter(Vm vm) Returns the Datacenter where a VM is placed.Gets the list of all VMs created so far, independently if they are running yet or were already destroyed.Gets the list of VMs in execution, if they are running Cloudlets or not.Gets a List of VMs submitted to the broker that have failed to be created inside some Datacenter due to lack of suitable Hosts.protected VmgetVmFromCreatedList(int vmIndex) Gets a Vm at a given index from thelist of created VMs.intReturns the total number of VMs submitted to the broker, including created, waiting and failed VMs.Gets a List of VMs submitted to the broker that are waiting to be created inside some Datacenter yet.getWaitingVm(int index) Gets a VM from the waiting list.voidprocessEvent(SimEvent evt) Processes events or services that are available for the entity.removeOnVmsCreatedListener(@NonNull EventListener<? extends EventInfo> listener) Removes anEventListenerto stop it from being notified when VMs in the waiting list are all created.protected voidRequest Datacenters to create the Cloudlets in thewaiting list.Checks if a VM is idle VM and request it to be destroyed at the time defined by theDatacenterBroker.setVmDestructionDelayFunction(Function).voidRequests the broker shutdown if it's idle.final DatacenterBrokersetSelectClosestDatacenter(boolean select) Defines if the broker has to try selecting the closestDatacenterto placeVms, based on their timezone.setVmDestructionDelay(double delay) Sets the delay after which an idle VM should be destroyed.setVmDestructionDelayFunction(Function<Vm, Double> function) Sets aFunctionto define the delay after which an idle VM should be destroyed.voidshutdown()Shuts down the entity.voidDefines the logic to be performed by the entity when the simulation starts.submitCloudlet(@NonNull Cloudlet cloudlet) Submits a singleCloudletto the broker so that it requests their creation inside some VM.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).submitCloudletList(List<? extends Cloudlet> list, double submissionDelay) Sends a list of cloudlets to the broker so that it requests their creation inside some VM just after a given delay.submitCloudletList(List<? extends Cloudlet> list, Vm vm) 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).submitCloudletList(List<? extends Cloudlet> list, Vm vm, double submissionDelay) Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM just after a given delay.submitVmList(List<? extends Vm> list) Submits a list ofVmorVmGroupwhere their creation inside a Host will be requested to someDatacenter.submitVmList(List<? extends Vm> list, double submissionDelay) toString()Methods inherited from class org.cloudsimplus.core.CloudSimEntity
cancelEvent, compareTo, getNextEvent, getNextEvent, isAlive, isFinished, isStarted, pause, run, run, schedule, schedule, schedule, schedule, schedule, schedule, scheduleFirst, scheduleFirst, scheduleFirstNow, scheduleFirstNow, scheduleNow, scheduleNow, selectEvent, send, send, sendNow, sendNow, setEventBuffer, setId, setName, start, waitForEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface org.cloudsimplus.brokers.DatacenterBroker
getCloudletCreatedList, getCloudletSubmittedList, getLastSelectedDc, getVmCreation, isBatchVmCreation, isSelectClosestDatacenter, isShutdownWhenIdle, setBatchVmCreation, setCloudletComparator, setDatacenterMapper, setLastSelectedDc, setShutdownWhenIdle, setVmComparator, setVmMapperMethods inherited from interface org.cloudsimplus.core.Identifiable
getIdMethods inherited from interface org.cloudsimplus.core.SimEntity
getShutdownTime, getSimulation, getStartTime, getState, isAlive, isFinished, isStarted, run, schedule, schedule, schedule, schedule, schedule, schedule, schedule, setName, setState, start
-
Constructor Details
-
DatacenterBrokerAbstract
Creates a DatacenterBroker giving a specific name.- Parameters:
simulation- theCloudSimPlusinstance that represents the simulation the Entity is related toname- the DatacenterBroker name
-
-
Method Details
-
setSelectClosestDatacenter
Description copied from interface:DatacenterBrokerDefines if the broker has to try selecting the closestDatacenterto placeVms, based on their timezone. The default behaviour is to ignoreDatacenters andVms timezones.- Specified by:
setSelectClosestDatacenterin interfaceDatacenterBroker- Parameters:
select- true to try selecting the closest Datacenter, false to ignore distance- Returns:
- this broker instance
-
submitVmList
Description copied from interface:DatacenterBrokerSubmits a list ofVmorVmGroupto 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 theDatacenterBroker.getVmWaitingList().When a
VmGroupis given, it will try to place all VMs from the group into the same Host.- Specified by:
submitVmListin interfaceDatacenterBroker- Parameters:
list- the list ofVmorVmGroupto request the creationsubmissionDelay- the delay the broker has to include when requesting the creation of VMs- Returns:
- this broker instance
- See Also:
-
submitVmList
Submits a list ofVmorVmGroupwhere their creation inside a Host will be requested to someDatacenter. The Datacenter that will be chosen to place a VM is determined by theDatacenterBroker.setDatacenterMapper(BiFunction).When a
VmGroupis 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
VmGroupwill 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:
submitVmListin interfaceDatacenterBroker- Parameters:
list- the list ofVmorVmGroupto request the creation- Returns:
- this broker instance
- See Also:
-
submitVm
Description copied from interface:DatacenterBrokerSubmits a singleVmorVmGroupto the broker. When aVmGroupis given, it will try to place all VMs from the group into the same Host.- Specified by:
submitVmin interfaceDatacenterBroker- Parameters:
vm- theVmorVmGroupto be submitted- Returns:
- this broker instance
-
submitCloudlet
Description copied from interface:DatacenterBrokerSubmits a singleCloudletto the broker so that it requests their creation inside some VM.- Specified by:
submitCloudletin interfaceDatacenterBroker- Parameters:
cloudlet- the Cloudlet to be submitted- Returns:
- this broker instance
- See Also:
-
submitCloudletList
Description copied from interface:DatacenterBrokerSends 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 theDatacenterBroker.getCloudletWaitingList(), setting their submission delay to the specified value.- Specified by:
submitCloudletListin interfaceDatacenterBroker- Parameters:
list- the list of Cloudlets to request the creationsubmissionDelay- the delay the broker has to include when requesting the creation of Cloudlets- Returns:
- this broker instance
- See Also:
-
submitCloudletList
Description copied from interface:DatacenterBrokerSends 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 theDatacenterBroker.getCloudletWaitingList().- Specified by:
submitCloudletListin interfaceDatacenterBroker- Parameters:
list- the list of Cloudlets to request the creationvm- 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:DatacenterBrokerSends 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 theDatacenterBroker.getCloudletWaitingList(), setting their submission delay to the specified value.- Specified by:
submitCloudletListin interfaceDatacenterBroker- Parameters:
list- the list of Cloudlets to request the creationvm- the VM to which all Cloudlets will be bound tosubmissionDelay- the delay the broker has to include when requesting the creation of Cloudlets- Returns:
- this broker instance
- See Also:
-
submitCloudletList
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 theDatacenterBroker.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:
submitCloudletListin interfaceDatacenterBroker- Parameters:
list- the list of Cloudlets to request the creation- Returns:
- this broker instance
- See Also:
-
bindCloudletToVm
Description copied from interface:DatacenterBrokerSpecifies that an already submitted cloudlet, which is in thewaiting list, must run in a specific virtual machine.- Specified by:
bindCloudletToVmin interfaceDatacenterBroker- Parameters:
cloudlet- the cloudlet to be bind to a given Vmvm- 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
Description copied from interface:SimEntityProcesses events or services that are available for the entity. This method is invoked, by theCloudSimPlusclass, whenever there is an event in the deferred queue that needs to be processed by the entity.- Specified by:
processEventin interfaceSimEntity- Parameters:
evt- information about the event just happened
-
getVmsNumber
public int getVmsNumber()Description copied from interface:DatacenterBrokerReturns the total number of VMs submitted to the broker, including created, waiting and failed VMs.- Specified by:
getVmsNumberin interfaceDatacenterBroker- Returns:
- the total number of VMs submitted to the broker, including created, waiting and failed VMs
-
requestIdleVmDestruction
Description copied from interface:DatacenterBrokerChecks if a VM is idle VM and request it to be destroyed at the time defined by theDatacenterBroker.setVmDestructionDelayFunction(Function). The request will be sent if the given delay function returns a value greater thanDatacenterBroker.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:
requestIdleVmDestructionin interfaceDatacenterBroker- Parameters:
vm- the VM to destroy- Returns:
- this broker instance
- See Also:
-
requestShutdownWhenIdle
public void requestShutdownWhenIdle()Description copied from interface:DatacenterBrokerRequests the broker shutdown if it's idle.- Specified by:
requestShutdownWhenIdlein interfaceDatacenterBroker
-
requestDatacentersToCreateWaitingCloudlets
protected void requestDatacentersToCreateWaitingCloudlets()Request Datacenters to create the Cloudlets in thewaiting 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:SimEntityShuts down the entity. This method is invoked byCloudSimPlusbefore 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:
shutdownin interfaceSimEntity- Overrides:
shutdownin classCloudSimEntity
-
startInternal
public void startInternal()Description copied from class:CloudSimEntityDefines the logic to be performed by the entity when the simulation starts.- Specified by:
startInternalin classCloudSimEntity
-
getVmCreatedList
Description copied from interface:DatacenterBrokerGets 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:
getVmCreatedListin interfaceDatacenterBroker- Type Parameters:
T- the class of VMs inside the list- Returns:
- the list of created VMs
- See Also:
-
getVmExecList
Description copied from interface:DatacenterBrokerGets the list of VMs in execution, if they are running Cloudlets or not. These VMs can receive new submitted Cloudlets.- Specified by:
getVmExecListin interfaceDatacenterBroker- Type Parameters:
T- the class of VMs inside the list- Returns:
- the list of running VMs
- See Also:
-
getVmWaitingList
Description copied from interface:DatacenterBrokerGets a List of VMs submitted to the broker that are waiting to be created inside some Datacenter yet.- Specified by:
getVmWaitingListin interfaceDatacenterBroker- Type Parameters:
T- the class of VMs inside the list- Returns:
- the list of waiting VMs
-
getVmFailedList
Description copied from interface:DatacenterBrokerGets 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 ifVmCreation.isRetryFailedVms()is not enabled.- Specified by:
getVmFailedListin interfaceDatacenterBroker- Type Parameters:
T- the class of VMs inside the list- Returns:
- the list of failed VMs
- See Also:
-
getWaitingVm
Description copied from interface:DatacenterBrokerGets a VM from the waiting list.- Specified by:
getWaitingVmin interfaceDatacenterBroker- Parameters:
index- the index of the VM to get- Returns:
- the waiting VM
-
getCloudletWaitingList
Description copied from interface:DatacenterBrokerGets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.- Specified by:
getCloudletWaitingListin interfaceDatacenterBroker- Type Parameters:
T- the class of Cloudlets inside the list- Returns:
- the cloudlet waiting list
-
getCloudletFinishedList
Description copied from interface:DatacenterBrokerGets a copy of the list of cloudlets that have finished executing, to avoid the original list to be changed.- Specified by:
getCloudletFinishedListin interfaceDatacenterBroker- Type Parameters:
T- the class of Cloudlets inside the list- Returns:
- the list of finished cloudlets
-
getVmFromCreatedList
Gets a Vm at a given index from thelist 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.NULLif the index is invalid
-
getDatacenter
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:DatacenterBrokerAdds anEventListenerthat 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).
- Specified by:
addOnVmsCreatedListenerin interfaceDatacenterBroker- 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:DatacenterBrokerRemoves anEventListenerto stop it from being notified when VMs in the waiting list are all created.- Specified by:
removeOnVmsCreatedListenerin interfaceDatacenterBroker- Parameters:
listener- the Listener that will be removed- Returns:
- this broker instance
- See Also:
-
toString
-
setVmDestructionDelay
Description copied from interface:DatacenterBrokerSets 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 theDatacenterBroker.setVmDestructionDelayFunction(Function)method.- Specified by:
setVmDestructionDelayin interfaceDatacenterBroker- 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
Sets aFunctionto define the delay after which an idle VM should be destroyed. The Function must receive aVmand return the delay to wait (in seconds), after the VM becomes idle, to destroy it.By providing a
Functionto 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:
setVmDestructionDelayFunctionin interfaceDatacenterBroker- Parameters:
function- theFunctionto set (if null is given, no idle VM will be automatically destroyed)- Returns:
- this broker instance
- See Also:
-
defaultDatacenterMapper
Selects a Datacenter to request the creating of waiting VMs. This is the default policy used to select a Datacenter to runwaiting VMs, if theselection of the closest datacenteris disabled.- Parameters:
lastDatacenter- the last selected Datacentervm- the VM trying to be created- Returns:
- the selected datacenter or
Datacenter.NULLif no suitable Datacenter was found - See Also:
-
closestDatacenterMapper
Selects the closest Datacenter to request the creating of waiting VMs, according to their timezone offset. This policy is just used if theselection of the closest datacenteris enabled.- Parameters:
lastDatacenter- the last selected Datacentervm- the VM trying to be created- Returns:
- the selected datacenter or
Datacenter.NULLif no suitable Datacenter was found - See Also:
-
defaultVmMapper
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.NULLif no suitable VM was found - See Also:
-