diff --git a/CLAUDE.md b/CLAUDE.md index 8924f7b..a920be1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -41,7 +41,7 @@ Common structure of an example (see `BasicFirstExample`): 1. `private static final` constants for host, VM and cloudlet sizes (MIPS, PEs, RAM in MB, BW in Mbps, storage in MB, length in MI). 2. Constructor: `new CloudSimPlus()`, then `createDatacenter()` (`DatacenterSimple` with `HostSimple`s built from `PeSimple`s), then `new DatacenterBrokerSimple(simulation)`. 3. `createVms()` (`VmSimple`) and `createCloudlets()` (`CloudletSimple` + a `UtilizationModel*`), then `broker.submitVmList(...)` and `broker.submitCloudletList(...)`. -4. Optionally register event listeners (e.g. `simulation.addOnClockTickListener`, `vm.addOnHostPlacementListener`) for dynamic behaviour. +4. Optionally register event listeners (e.g. `simulation.listeners().addOnClockTick`, `vm.listeners().addOnHostPlacement`) for dynamic behaviour. 5. `simulation.start()`, then print results with `new CloudletsTableBuilder(broker.getCloudletFinishedList()).build()`. Default policies (VM placement, VM/cloudlet schedulers, allocators) apply unless an example sets them on purpose. Usually that choice is the point of the example. diff --git a/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java b/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java index 64fd655..aa38ca7 100755 --- a/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java +++ b/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java @@ -117,7 +117,7 @@ private CloudletCancellationExample() { /// In order to make this work, the [Datacenter#getSchedulingInterval()] /// most be set. /// See [#SCHEDULING_INTERVAL] for more details. - cloudletList.get(0).addOnUpdateProcessingListener(this::cancelCloudletIfHalfExecuted); + cloudletList.get(0).listeners().addOnUpdateProcessing(this::cancelCloudletIfHalfExecuted); broker0.submitVmList(vmList); broker0.submitCloudletList(cloudletList); diff --git a/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java b/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java index 1eb947d..df1cbcf 100755 --- a/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java +++ b/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java @@ -110,7 +110,7 @@ private VmBootTimeAndOverheadExample() { vmList = createVms(); cloudletList = createCloudlets(); broker0.submitVmList(vmList); - vmList.getFirst().addOnUpdateProcessingListener(this::updateVmProcessingListener); + vmList.getFirst().listeners().addOnUpdateProcessing(this::updateVmProcessingListener); broker0.submitCloudletList(cloudletList); simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java b/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java index 056951b..63d131b 100755 --- a/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java +++ b/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java @@ -131,7 +131,7 @@ private VmDestructionExample() { * add this event listener for each desired VM that it will work * transparently for any VM. */ - vmList.get(1).addOnUpdateProcessingListener(this::vmProcessingUpdateListener); + vmList.get(1).listeners().addOnUpdateProcessing(this::vmProcessingUpdateListener); broker0.submitVmList(vmList); broker0.submitCloudletList(cloudletList); diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java b/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java index e968853..a2f1b29 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java @@ -48,6 +48,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.Comparator; @@ -71,7 +72,7 @@ /// to enable monitoring the simulation and dynamically creating objects such as Cloudlets and VMs. /// It relies on /// [Java 8 Lambda Expressions](http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html) -/// to set a Listener for the [onClockTick event][Simulation#addOnClockTickListener(EventListener)]. +/// to set a Listener for the [onClockTick event][SimulationListeners#addOnClockTick(EventListener)]. /// That Listener gets notified every time the simulation clock advances and then creates and submits new Cloudlets. /// /// The [DatacenterBroker] is accountable to perform horizontal down scaling. @@ -155,7 +156,7 @@ private LoadBalancerByHorizontalVmScalingExample() { cloudletList = new ArrayList<>(CLOUDLETS); simulation = new CloudSimPlus(); - simulation.addOnClockTickListener(this::createNewCloudlets); + simulation.listeners().addOnClockTick(this::createNewCloudlets); dc0 = createDatacenter(); broker0 = new DatacenterBrokerSimple(simulation); @@ -196,7 +197,7 @@ private void createCloudletList() { /// Creates new Cloudlets at every [#CLOUDLETS_CREATION_INTERVAL] seconds, up to the 50th simulation second. /// A reference to this method is set as the [EventListener] - /// to the [Simulation#addOnClockTickListener(EventListener)]. + /// to the [SimulationListeners#addOnClockTick(EventListener)]. /// The method is called every time the simulation clock advances. /// /// @param info the information about the OnClockTick event that has happened diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java index 4742014..98015c6 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java @@ -53,6 +53,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelStochastic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.Comparator; @@ -72,7 +73,7 @@ /// to enable monitoring the simulation and dynamically create objects such as Cloudlets and VMs at runtime. /// It relies on /// [Java 8 Method References](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html) -/// to set a method to be called for [onClockTick events][Simulation#addOnClockTickListener(EventListener)]. +/// to set a method to be called for [onClockTick events][SimulationListeners#addOnClockTick(EventListener)]. /// It enables getting notifications when the simulation clock advances, then creating and submitting new cloudlets. /// /// @author Manoel Campos da Silva Filho @@ -142,7 +143,7 @@ private VerticalVmCpuScalingDynamicThreshold() { cloudletList = new ArrayList<>(CLOUDLETS); simulation = new CloudSimPlus(); - simulation.addOnClockTickListener(this::onClockTickListener); + simulation.listeners().addOnClockTick(this::onClockTickListener); createDatacenter(); broker0 = new DatacenterBrokerSimple(simulation); diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java index 236cf4f..9a6b8e2 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java @@ -49,6 +49,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.Comparator; @@ -67,7 +68,7 @@ /// /// The example uses the CloudSim Plus [EventListener] feature /// to enable monitoring the simulation and dynamically create objects such as Cloudlets and VMs at runtime. -/// The [onClockTick listener][Simulation#addOnClockTickListener(EventListener)]. +/// The [onClockTick listener][SimulationListeners#addOnClockTick(EventListener)]. /// enables getting notifications when the simulation clock changes, then creating and submitting new cloudlets. /// /// @author Manoel Campos da Silva Filho @@ -139,7 +140,7 @@ private VerticalVmCpuScalingExample() { cloudletList = new ArrayList<>(CLOUDLETS); simulation = new CloudSimPlus(); - simulation.addOnClockTickListener(this::onClockTickListener); + simulation.listeners().addOnClockTick(this::onClockTickListener); createDatacenter(); broker0 = new DatacenterBrokerSimple(simulation); diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java index d2e8039..c1ba2d9 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java @@ -47,6 +47,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.Comparator; @@ -70,7 +71,7 @@ /// /// The example uses the CloudSim Plus [EventListener] feature /// to enable monitoring the simulation and dynamically creating objects such as Cloudlets and VMs. -/// It creates a Listener for the [onClockTick event][Simulation#addOnClockTickListener(EventListener)] +/// It creates a Listener for the [onClockTick event][SimulationListeners#addOnClockTick(EventListener)] /// to get notifications when the simulation clock advances, then creating and submitting new cloudlets. /// /// @author Manoel Campos da Silva Filho @@ -159,7 +160,7 @@ private VerticalVmRamScalingExample() { cloudletList = new ArrayList<>(CLOUDLET_LENGTHS.length); simulation = new CloudSimPlus(); - simulation.addOnClockTickListener(this::onClockTickListener); + simulation.listeners().addOnClockTick(this::onClockTickListener); createDatacenter(); broker0 = new DatacenterBrokerSimple(simulation); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java index 5fe2261..174680c 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java @@ -116,7 +116,7 @@ private DatacenterBrokerBatchVmCreationRequestExample() { cloudletList = new ArrayList<>(); createVmsAndCloudlets(); - simulation.addOnClockTickListener(this::onClockTick); + simulation.listeners().addOnClockTick(this::onClockTick); simulation.start(); final var cloudletFinishedList = broker0.getCloudletFinishedList(); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java index f735fbc..653cae2 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.List; @@ -132,7 +133,7 @@ private MultipleBrokers2() { * See the documentation of the methods called below for more details. */ //submitCloudletWithDelay(); - simulation.addOnClockTickListener(this::dynamicCloudletArrival); + simulation.listeners().addOnClockTick(this::dynamicCloudletArrival); simulation.start(); printResults(); @@ -174,7 +175,7 @@ private void submitCloudletWithDelay() { /// @param e information about the generated event /// @return /// @see Datacenter#getSchedulingInterval() - /// @see CloudSimPlus#addOnClockTickListener(EventListener) + /// @see SimulationListeners#addOnClockTick(EventListener) private void dynamicCloudletArrival(EventInfo e) { if((int)e.getTime() != 35) { return; diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java b/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java index dcdaace..e15a1e1 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.cloudlets.CloudletListeners; import java.util.ArrayList; import java.util.List; @@ -53,7 +54,7 @@ /// the a Cloudlet finishes its execution to then request /// the creation of a new Cloudlet. It uses the Java 8+ Lambda Functions features /// to pass a listener to the mentioned Cloudlet, by means of the -/// [Cloudlet#addOnFinishListener(EventListener)] method. +/// [CloudletListeners#addOnFinish(EventListener)] method. /// /// @author Manoel Campos da Silva Filho /// @since CloudSim Plus 2.2.0 @@ -145,7 +146,7 @@ private void createAndSubmitOneCloudlet() { cloudletList.add(cloudlet); if(cloudletList.size() < CLOUDLETS){ - cloudlet.addOnFinishListener(this::cloudletFinishListener); + cloudlet.listeners().addOnFinish(this::cloudletFinishListener); } broker.submitCloudlet(cloudlet); diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java index 53f2161..f484e72 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java @@ -41,6 +41,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.cloudlets.CloudletListeners; import java.util.ArrayList; import java.util.List; @@ -54,12 +55,12 @@ /// the first Cloudlet finishes its execution to then request /// the creation of new VMs and Cloudlets. It uses the Java 8+ Lambda Functions features /// to pass a listener to the mentioned Cloudlet, by means of the -/// [Cloudlet#addOnFinishListener(EventListener)] method. +/// [CloudletListeners#addOnFinish(EventListener)] method. /// /// @author Manoel Campos da Silva Filho /// @since CloudSim Plus 1.0 /// -/// @see Cloudlet#addOnFinishListener(EventListener) +/// @see CloudletListeners#addOnFinish(EventListener) /// @see EventListener public class DynamicCreationOfVmsAndCloudletsExample { private final CloudSimPlus simulation; @@ -97,7 +98,7 @@ on behalf of a given cloud user (customer).*/ /* Assigns an EventListener to be notified when the first Cloudlets finishes executing * and then dynamically create a new list of VMs and Cloudlets to submit to the broker.*/ final var cloudlet0 = this.cloudletList.get(0); - cloudlet0.addOnFinishListener(this::submitNewVmsAndCloudletsToBroker); + cloudlet0.listeners().addOnFinish(this::submitNewVmsAndCloudletsToBroker); /* Starts the simulation and waits all cloudlets to be executed. */ simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java index 92215e0..f8357a1 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java @@ -43,6 +43,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.List; @@ -73,7 +74,7 @@ /// to set the scheduling interval. Check the method documentation for more details. /// This example uses the CloudSim Plus Listener features to enable your simulation /// to be notified when some event happens. -/// In this case, it's being used the [CloudSimPlus#addOnClockTickListener(EventListener)] +/// In this case, it's being used the [SimulationListeners#addOnClockTick(EventListener)] /// to pass a [EventListener] object that will be notified /// when the simulation clock advances. /// @@ -81,7 +82,7 @@ /// that enables using Lambda Expression /// or method references in order to provide a [FunctionalInterface]. /// This example uses a reference to the [#clockTickListener(EventInfo)] method -/// as being the [EventListener] required by the [CloudSimPlus#addOnClockTickListener(EventListener)]. +/// as being the [EventListener] required by the [SimulationListeners#addOnClockTick(EventListener)]. /// /// **Lambda Expressions, method references and Functional Interfaces are Java 8+ features.** /// If you don't know what these features are, I suggest checking out this @@ -142,7 +143,7 @@ private DynamicHostCreation() { broker0.submitVmList(vmList); broker0.submitCloudletList(cloudletList); - simulation.addOnClockTickListener(this::clockTickListener); + simulation.listeners().addOnClockTick(this::clockTickListener); simulation.start(); final var cloudletFinishedList = broker0.getCloudletFinishedList(); @@ -173,7 +174,7 @@ private void clockTickListener(final EventInfo info) { /* Removes the listener so that this event is fired just once. * This way, it's ensured the new Host, VMs and Cloudlets are created only one time. */ - simulation.removeOnClockTickListener(info.getListener()); + simulation.listeners().removeOnClockTick(info.getListener()); } } diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java index 37aafe3..757e602 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java @@ -44,6 +44,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.List; @@ -71,7 +72,7 @@ /// to enable monitoring the simulation and dynamically creating Cloudlets and VMs at runtime. /// It relies on /// [Java 8 Method References](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html) -/// to set a method to be called for [onClockTick events][Simulation#addOnClockTickListener(EventListener)]. +/// to set a method to be called for [onClockTick events][SimulationListeners#addOnClockTick(EventListener)]. /// It enables getting notifications when the simulation clock advances, then creating and submitting new cloudlets. /// /// Since the simulation was set to keep waiting for new events @@ -144,7 +145,7 @@ private KeepSimulationRunningExample() { broker0.submitVmList(vmList); broker0.submitCloudletList(cloudletList); - simulation.addOnClockTickListener(this::createDynamicCloudletAndVm); + simulation.listeners().addOnClockTick(this::createDynamicCloudletAndVm); simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java index 0025fca..42596bf 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java @@ -46,6 +46,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.List; @@ -69,7 +70,7 @@ /// to enable monitoring the simulation and dynamically creating Cloudlets and VMs at runtime. /// It relies on /// [Java 8 Method References](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html) -/// to set a method to be called for [onClockTick events][Simulation#addOnClockTickListener(EventListener)]. +/// to set a method to be called for [onClockTick events][SimulationListeners#addOnClockTick(EventListener)]. /// It enables getting notifications when the simulation clock advances, then creating and submitting new cloudlets. /// /// Since the simulation was set to keep waiting for new events @@ -134,7 +135,7 @@ private RandomCloudletsArrivalExample() { broker0.submitVmList(vmList); broker0.submitCloudletList(cloudletList); - simulation.addOnClockTickListener(this::createRandomCloudlets); + simulation.listeners().addOnClockTick(this::createRandomCloudlets); simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java index 8784837..b75d5e6 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.cloudlets.CloudletListeners; import java.util.ArrayList; import java.util.List; @@ -52,7 +53,7 @@ /// The example uses the new Cloudlet listeners to get these /// notifications while the simulation is running. /// -/// @see Cloudlet#addOnFinishListener(EventListener) +/// @see CloudletListeners#addOnFinish(EventListener) /// @see EventListener /// /// @author Manoel Campos da Silva Filho @@ -190,9 +191,10 @@ private Cloudlet createCloudlet(long id, Vm vm, long length) { .setUtilizationModelCpu(new UtilizationModelFull()) .setUtilizationModelBw(utilizationModel) .setUtilizationModelRam(utilizationModel) - .setVm(vm) - .addOnStartListener(this::onCloudletStartListener) - .addOnFinishListener(this::onCloudletFinishListener); + .setVm(vm); + cloudlet.listeners() + .addOnStart(this::onCloudletStartListener) + .addOnFinish(this::onCloudletFinishListener); return cloudlet; } diff --git a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java index 925eb80..d1e38fc 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelStochastic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.cloudlets.CloudletListeners; import java.util.ArrayList; import java.util.List; @@ -53,7 +54,7 @@ /// The example uses the [UtilizationModelStochastic] /// to define that the usage of CPU, RAM and Bandwidth is random. /// -/// @see Cloudlet#addOnUpdateProcessingListener(EventListener) +/// @see CloudletListeners#addOnUpdateProcessing(EventListener) /// @see EventListener /// /// @author Manoel Campos da Silva Filho @@ -196,8 +197,8 @@ private Cloudlet createCloudlet(long id, Vm vm, long length) { .setUtilizationModelCpu(cpuUtilizationModel) .setUtilizationModelRam(ramUtilizationModel) .setUtilizationModelBw(bwUtilizationModel) - .setVm(vm) - .addOnUpdateProcessingListener(this::onUpdateCloudletProcessingListener); + .setVm(vm); + cloudlet.listeners().addOnUpdateProcessing(this::onUpdateCloudletProcessingListener); return cloudlet; } diff --git a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java index 1a4cbd7..cf627a4 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java @@ -40,6 +40,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.vms.VmListeners; import java.util.ArrayList; import java.util.List; @@ -52,9 +53,9 @@ /// The example uses the new Vm listeners to get these /// notifications while the simulation is running. /// -/// @see Vm#addOnHostPlacementListener(EventListener) -/// @see Vm#addOnHostRemovalListener(EventListener) -/// @see Vm#addOnCreationFailureListener(EventListener) +/// @see VmListeners#addOnHostPlacement(EventListener) +/// @see VmListeners#addOnHostRemoval(EventListener) +/// @see VmListeners#addOnCreationFailure(EventListener) /// @see EventListener /// /// @author Manoel Campos da Silva Filho @@ -129,14 +130,14 @@ private void createAndSubmitVms() { /* Sets the Listener to intercept allocation of a Host to the Vm. * The Listener is created using Java 8+ Lambda Expressions. */ - vm0.addOnHostPlacementListener(eventInfo -> System.out.printf( + vm0.listeners().addOnHostPlacement(eventInfo -> System.out.printf( "%n\t#EventListener: Host %d allocated to Vm %d at time %.2f%n", eventInfo.getHost().getId(), eventInfo.getVm().getId(), eventInfo.getTime())); /* Sets the listener to intercept deallocation of a Host for the Vm. * The Listener is created using Java 8+ Lambda Expressions. */ - vm0.addOnHostRemovalListener(eventInfo -> System.out.printf( + vm0.listeners().addOnHostRemoval(eventInfo -> System.out.printf( "%n\t#EventListener: Vm %d moved/removed from Host %d at time %.2f%n", eventInfo.getVm().getId(), eventInfo.getHost().getId(), eventInfo.getTime())); @@ -144,7 +145,7 @@ private void createAndSubmitVms() { * The Listener is created using Java 8+ Lambda Expressions. */ final var vm1 = createVm(1); - vm1.addOnCreationFailureListener(eventInfo -> System.out.printf( + vm1.listeners().addOnCreationFailure(eventInfo -> System.out.printf( "%n\t#EventListener: Vm %d could not be placed into any host of Datacenter %d at time %.2f due to lack of a host with enough resources.%n", eventInfo.getVm().getId(), eventInfo.getDatacenter().getId(), eventInfo.getTime())); diff --git a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java index d86b02f..a2a0d38 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java @@ -41,6 +41,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.vms.VmListeners; import java.util.ArrayList; import java.util.List; @@ -53,8 +54,8 @@ /// notifications while the simulation is running. It also shows how to /// reuse the same listener object to different VMs. /// -/// @see Vm#addOnHostPlacementListener(EventListener) -/// @see Vm#addOnHostRemovalListener(EventListener) +/// @see VmListeners#addOnHostPlacement(EventListener) +/// @see VmListeners#addOnHostRemoval(EventListener) /// @see EventListener /// /// @author Manoel Campos da Silva Filho @@ -169,10 +170,10 @@ private Vm createVm(int id) { .setCloudletScheduler(new CloudletSchedulerTimeShared()); /*Adds the listener to intercept allocation of a Host to the Vm.*/ - vm.addOnHostPlacementListener(this.onHostPlacementListener); + vm.listeners().addOnHostPlacement(this.onHostPlacementListener); /*Adds the listener to intercept deallocation of a Host for the Vm.*/ - vm.addOnHostRemovalListener(this.onHostRemovalListener); + vm.listeners().addOnHostRemoval(this.onHostRemovalListener); return vm; } diff --git a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java index 5375c54..be79616 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.vms.VmListeners; import java.util.ArrayList; import java.util.List; @@ -55,7 +56,7 @@ /// is deallocated for a VM (in this case meaning that the VM has finished /// executing) in order to place the next VM to run inside the host. /// -/// @see Vm#addOnHostRemovalListener(EventListener) +/// @see VmListeners#addOnHostRemoval(EventListener) /// @see EventListener /// /// @author Manoel Campos da Silva Filho @@ -208,10 +209,11 @@ private Vm createVm(int id, DatacenterBroker broker) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - return VmSimple.of(id, new CoreCapacity(VM_PES_NUMBER, mips)) + final var vm = VmSimple.of(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) - .setCloudletScheduler(new CloudletSchedulerSpaceShared()) - .addOnHostRemovalListener(this::onHostRemovalListener); + .setCloudletScheduler(new CloudletSchedulerSpaceShared()); + vm.listeners().addOnHostRemoval(this::onHostRemovalListener); + return vm; } /// Creates a cloudlet with pre-defined configuration. diff --git a/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java b/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java index 4582746..0cbade5 100755 --- a/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java +++ b/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java @@ -50,6 +50,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.vms.VmListeners; import java.util.ArrayList; import java.util.Arrays; @@ -295,7 +296,7 @@ private void createVmsAndCloudlets() { for (final DatacenterBroker broker : brokerList) { createAndSubmitVms(broker, VM_CORES[i++]); createAndSubmitCloudlets(broker); - broker.addOnVmsCreatedListener(this::onVmsCreatedListener); + broker.listeners().addOnVmsCreated(this::onVmsCreatedListener); } } @@ -317,7 +318,7 @@ private void onVmsCreatedListener(final DatacenterBrokerEventInfo info) { datacenterList.stream() .map(dc -> (VmPlacementPolicyMigrationFirstFitStaticThreshold)dc.getVmPlacementPolicy()) .forEach(policy -> policy.setOverUtilizationThreshold(HOST_OVER_UTILIZATION_THRESHOLD_FOR_VM_MIGRATION)); - broker.removeOnVmsCreatedListener(info.getListener()); + broker.listeners().removeOnVmsCreated(info.getListener()); } public void createAndSubmitCloudlets(final DatacenterBroker broker) { @@ -353,13 +354,13 @@ public Cloudlet createCloudlet(final Vm vm, final UtilizationModel cpuUtilizatio public void createAndSubmitVms(final DatacenterBroker broker, final int[] vmPesArray) { final var vmList = Arrays.stream(vmPesArray).mapToObj(this::createVm).toList(); broker.submitVmList(vmList); - vmList.forEach(vm -> vm.addOnMigrationStartListener(this::startMigration)); + vmList.forEach(vm -> vm.listeners().addOnMigrationStart(this::startMigration)); } /// A listener method that is called when a VM migration starts. /// @param info information about the happened event /// - /// @see Vm#addOnMigrationFinishListener(EventListener) + /// @see VmListeners#addOnMigrationFinish(EventListener) private void startMigration(final VmHostEventInfo info) { migrationsNumber++; } diff --git a/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java b/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java index 63577e0..bbed2c0 100755 --- a/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java +++ b/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java @@ -48,6 +48,8 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; +import org.cloudsimplus.vms.VmListeners; import java.util.ArrayList; import java.util.Comparator; @@ -144,7 +146,7 @@ private ManualMigrationExample1(){ broker = new DatacenterBrokerSimple(simulation); createAndSubmitVms(broker); createAndSubmitCloudlets(broker); - simulation.addOnClockTickListener(this::clockTickListener); + simulation.listeners().addOnClockTick(this::clockTickListener); simulation.start(); @@ -165,7 +167,7 @@ private ManualMigrationExample1(){ /// an arbitrary Host. /// /// @param info information about the event happened. - /// @see CloudSimPlus#addOnClockTickListener(EventListener) + /// @see SimulationListeners#addOnClockTick(EventListener) private void clockTickListener(EventInfo info) { if(!migrationRequested && info.getTime() >= 10){ final var sourceVm = vmList.get(0); @@ -229,14 +231,14 @@ public void createAndSubmitVms(DatacenterBroker broker) { vmList.addAll(newVmList); broker.submitVmList(newVmList); - vmList.forEach(vm -> vm.addOnMigrationStartListener(this::startMigration)); + vmList.forEach(vm -> vm.listeners().addOnMigrationStart(this::startMigration)); } /// A listener method that is called when a VM migration starts. /// @param info information about the happened event /// /// @see #createAndSubmitVms(DatacenterBroker) - /// @see Vm#addOnMigrationFinishListener(EventListener) + /// @see VmListeners#addOnMigrationFinish(EventListener) private void startMigration(final VmHostEventInfo info) { final Vm vm = info.getVm(); final Host targetHost = info.getHost(); diff --git a/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java b/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java index bcd40ff..82569bf 100755 --- a/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java +++ b/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java @@ -49,6 +49,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.vms.VmListeners; import java.util.ArrayList; import java.util.Comparator; @@ -201,7 +202,7 @@ private MigrationExample1(){ createAndSubmitVms(broker); createAndSubmitCloudlets(broker); - broker.addOnVmsCreatedListener(this::onVmsCreatedListener); + broker.listeners().addOnVmsCreated(this::onVmsCreatedListener); simulation.start(); @@ -231,7 +232,7 @@ private void printHosts() { /// @param info information about the happened event /// /// @see #createAndSubmitVms(DatacenterBroker) - /// @see Vm#addOnMigrationFinishListener(EventListener) + /// @see VmListeners#addOnMigrationFinish(EventListener) private void startMigration(final VmHostEventInfo info) { final Vm vm = info.getVm(); final Host targetHost = info.getHost(); @@ -251,7 +252,7 @@ private void startMigration(final VmHostEventInfo info) { } //After the first VM starts being migrated, tracks some metrics along simulation time - simulation.addOnClockTickListener(clock -> { + simulation.listeners().addOnClockTick(clock -> { if (clock.getTime() <= 2 || (clock.getTime() >= 11 && clock.getTime() <= 15)) showVmAllocatedMips(vm, targetHost, clock.getTime()); }); @@ -268,7 +269,7 @@ private void showVmAllocatedMips(final Vm vm, final Host targetHost, final doubl /// @param info information about the happened event /// /// @see #createAndSubmitVms(DatacenterBroker) - /// @see Vm#addOnMigrationStartListener(EventListener) + /// @see VmListeners#addOnMigrationStart(EventListener) private void finishMigration(final VmHostEventInfo info) { final var host = info.getHost(); System.out.printf( @@ -331,8 +332,8 @@ public void createAndSubmitVms(DatacenterBroker broker) { vmList.addAll(newVmList); broker.submitVmList(newVmList); - newVmList.forEach(vm -> vm.addOnMigrationStartListener(this::startMigration)); - newVmList.forEach(vm -> vm.addOnMigrationFinishListener(this::finishMigration)); + newVmList.forEach(vm -> vm.listeners().addOnMigrationStart(this::startMigration)); + newVmList.forEach(vm -> vm.listeners().addOnMigrationFinish(this::finishMigration)); } public Vm createVm(final int pes) { @@ -445,7 +446,7 @@ public Host createHost(final int pesNumber, final long ram) { private void onVmsCreatedListener(final DatacenterBrokerEventInfo info) { System.out.printf("# All %d VMs submitted to the broker have been created.%n", broker.getVmCreatedList().size()); allocationPolicy.setOverUtilizationThreshold(HOST_OVER_UTILIZATION_THRESHOLD_FOR_VM_MIGRATION); - broker.removeOnVmsCreatedListener(info.getListener()); + broker.listeners().removeOnVmsCreated(info.getListener()); vmList.forEach(vm -> showVmAllocatedMips(vm, vm.getHost(), info.getTime())); System.out.println(); diff --git a/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java b/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java index 4dedd52..d7611fe 100755 --- a/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java +++ b/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java @@ -148,13 +148,13 @@ private HostActivationExample() { datacenter0 = createDatacenter(); /*After Host 1 is shutdown, send new VMs to request it to startup again.*/ - datacenter0.getHost(1).addOnShutdownListener(this::hostShutdownListener); + datacenter0.getHost(1).listeners().addOnShutdown(this::hostShutdownListener); broker0 = createBroker(); vmList = new ArrayList<>(MAX_VMS); cloudletList = new ArrayList<>(MAX_VMS); createAndSubmitVmsAndCloudlets(MIN_VMS); - simulation.addOnClockTickListener(this::clockTickListener); + simulation.listeners().addOnClockTick(this::clockTickListener); simulation.start(); @@ -179,7 +179,7 @@ private void hostShutdownListener(final HostEventInfo info) { simulation.clockStr(), createVmList.size(), host.getId(), createVmList); //Ensure the listener is fired only once. - host.removeOnShutdownListener(info.getListener()); + host.listeners().removeOnShutdown(info.getListener()); } private void printHostsUpTime() { diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java index be52f78..a4d2ef0 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java @@ -97,7 +97,7 @@ private VmRelativeHostResourceUtilizationExample() { Log.setLevel(ch.qos.logback.classic.Level.WARN); simulation = new CloudSimPlus(); - simulation.addOnClockTickListener(this::onClockTick); + simulation.listeners().addOnClockTick(this::onClockTick); datacenter0 = createDatacenter(); broker0 = new DatacenterBrokerSimple(simulation); diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java index 425a269..c2814af 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java @@ -45,10 +45,11 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.*; -/// Shows how to use the [onClockTick Listener][Simulation#addOnClockTickListener(EventListener)] +/// Shows how to use the [onClockTick Listener][SimulationListeners#addOnClockTick(EventListener)] /// to keep track os simulation clock and store VM's RAM and BW utilization along the time. /// CloudSim Plus already has built-in features to obtain VM's CPU utilization. /// Check [org.cloudsimplus.examples.power.PowerExample]. @@ -57,7 +58,7 @@ /// to enable monitoring the simulation and dynamically collect RAM and BW usage. /// It relies on /// [Java 8 Method References](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html) -/// to set a method to be called for [onClockTick events][Simulation#addOnClockTickListener(EventListener)]. +/// to set a method to be called for [onClockTick events][SimulationListeners#addOnClockTick(EventListener)]. /// It enables getting notifications when the simulation clock advances, then creating and submitting new cloudlets. /// /// @author Manoel Campos da Silva Filho @@ -125,7 +126,7 @@ private VmsRamAndBwUsageExample() { allVmsRamUtilizationHistory = initializeUtilizationHistory(); allVmsBwUtilizationHistory = initializeUtilizationHistory(); - simulation.addOnClockTickListener(this::onClockTickListener); + simulation.listeners().addOnClockTick(this::onClockTickListener); simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java index feec98b..3cf77ea 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java @@ -40,6 +40,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.List; @@ -55,7 +56,7 @@ /// the simulation was paused, allowing to collect the desired data. /// This example uses the Java 8+ Lambda Functions features /// to pass a listener to a [CloudSimPlus] instance, by means of the -/// [CloudSimPlus#addOnSimulationPauseListener(EventListener)] method. +/// [SimulationListeners#addOnSimulationPause(EventListener)] method. /// However, the same feature can be used for Java 7 passing an anonymous class /// that implements `EventListener`. /// @@ -63,7 +64,7 @@ /// @since CloudSim Plus 1.0 /// /// @see CloudSimPlus#pause(double) -/// @see CloudSimPlus#addOnSimulationPauseListener(EventListener) +/// @see SimulationListeners#addOnSimulationPause(EventListener) /// @see EventListener public class PauseSimulationAtGivenTimeExample1 { /// The interval in which the Datacenter will schedule events. @@ -147,7 +148,7 @@ Since the start() method blocks until the simulation is finished, * that will be executed only when the simulation is paused. * */ this.simulation - .addOnSimulationPauseListener(this::printCloudletsFinishedSoFarAndResumeSimulation); + .listeners().addOnSimulationPause(this::printCloudletsFinishedSoFarAndResumeSimulation); /* Starts the simulation and waits all cloudlets to be executed. */ this.simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java index f820ea0..3f21428 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.core.SimulationListeners; import java.util.ArrayList; import java.util.List; @@ -51,14 +52,14 @@ /// The example creates 4 Cloudlets that will run sequentially using a [CloudletSchedulerSpaceShared]. /// /// The pause is scheduled after the simulation starts, by adding an -/// [OnEventProcessingListener][Simulation#addOnEventProcessingListener(EventListener)] +/// [OnEventProcessingListener][SimulationListeners#addOnEventProcessing(EventListener)] /// that will be notified every time a simulation event is processed. /// /// This example uses CloudSim Plus Listener features to intercept when /// the simulation was paused, allowing to collect the desired data. /// This example uses the Java 8+ Lambda Functions features /// to pass a listener to a [CloudSimPlus] instance, by means of the -/// [CloudSimPlus#addOnSimulationPauseListener(EventListener)] method. +/// [SimulationListeners#addOnSimulationPause(EventListener)] method. /// However, the same feature can be used for Java 7 passing an anonymous class /// that implements `EventListener`. /// @@ -66,7 +67,7 @@ /// @since CloudSim Plus 1.0 /// /// @see CloudSimPlus#pause(double) -/// @see CloudSimPlus#addOnSimulationPauseListener(EventListener) +/// @see SimulationListeners#addOnSimulationPause(EventListener) /// @see EventListener public class PauseSimulationAtGivenTimeExample2 { /// The interval in which the Datacenter will schedule events. @@ -144,7 +145,7 @@ on behalf of a given cloud user (customer). /// Realise that it is being used Java 8 Lambda Expressions to define a Listener /// that will be executed only when a simulation event happens. /// See the [#pauseSimulationAtSpecificTime(SimEvent)] method for more details. - this.simulation.addOnEventProcessingListener(this::pauseSimulationAtSpecificTime); + this.simulation.listeners().addOnEventProcessing(this::pauseSimulationAtSpecificTime); /* * Sets a Listener that will be notified when the simulation is paused. @@ -152,7 +153,7 @@ on behalf of a given cloud user (customer). * that will be executed only when the simulation is paused. * */ this.simulation - .addOnSimulationPauseListener(this::printCloudletsFinishedSoFarAndResumeSimulation); + .listeners().addOnSimulationPause(this::printCloudletsFinishedSoFarAndResumeSimulation); /* Starts the simulation and waits all cloudlets to be executed. */ this.simulation.start(); diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java index 99df1c5..ee2a2dd 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java @@ -42,6 +42,7 @@ import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.cloudlets.CloudletListeners; import java.util.ArrayList; import java.util.List; @@ -55,7 +56,7 @@ /// the second Cloudlet reaches 50% of its execution to then request /// the simulation termination. This example uses the Java 8+ Lambda Functions features /// to pass a listener to the mentioned Cloudlet, by means of the -/// [Cloudlet#addOnUpdateProcessingListener(EventListener)] method. +/// [CloudletListeners#addOnUpdateProcessing(EventListener)] method. /// However, the same feature can be used for Java 7 passing an anonymous class /// that implements `EventListener`. /// @@ -63,7 +64,7 @@ /// @since CloudSim Plus 1.0 /// /// @see CloudSimPlus#terminate() -/// @see Cloudlet#addOnUpdateProcessingListener(EventListener) +/// @see CloudletListeners#addOnUpdateProcessing(EventListener) /// @see EventListener public class TerminateSimulationAtGivenConditionExample { private final CloudSimPlus simulation; @@ -107,7 +108,7 @@ on behalf of a given cloud user (customer). } final var lastCloudlet = this.cloudletList.get(this.cloudletList.size()-1); - lastCloudlet.addOnUpdateProcessingListener(this::onClouletProcessingUpdate); + lastCloudlet.listeners().addOnUpdateProcessing(this::onClouletProcessingUpdate); broker0.submitCloudletList(cloudletList); diff --git a/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java b/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java index 1c4f35a..6f187e1 100755 --- a/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java +++ b/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java @@ -43,6 +43,7 @@ import org.cloudsimplus.util.TimeUtil; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; +import org.cloudsimplus.brokers.DatacenterBrokerListeners; import java.time.LocalTime; import java.util.ArrayList; @@ -136,7 +137,7 @@ private SwfWorkloadFormatExample1() { broker.submitVmList(vmlist); broker.submitCloudletList(cloudletList); - broker.addOnVmsCreatedListener(this::onVmsCreated); + broker.listeners().addOnVmsCreated(this::onVmsCreated); simulation.start(); @@ -152,7 +153,7 @@ private SwfWorkloadFormatExample1() { /// Method executed when all VMs submitted to the broker are placed /// into some Host. /// @param info - /// @see DatacenterBroker#addOnVmsCreatedListener(EventListener) + /// @see DatacenterBrokerListeners#addOnVmsCreated(EventListener) private void onVmsCreated(DatacenterBrokerEventInfo info) { System.out.printf("%d VMs from Broker %d placed into some Host%n", vmlist.size(), info.getDatacenterBroker().getId()); } diff --git a/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java b/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java index 239c556..8527825 100755 --- a/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java +++ b/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java @@ -105,7 +105,7 @@ private GoogleMachineEventsExample1() { /* Sets a listener method that will be called every time a new Host becomes available during simulation runtime * for the second Datacenter*/ - datacenters.get(1).addOnHostAvailableListener(this::onHostAvailableListener); + datacenters.get(1).listeners().addOnHostAvailable(this::onHostAvailableListener); simulation.start();