Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,15 +74,15 @@
/// 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.
///
/// In fact, this [EventListener] is a Java 8+ [FunctionalInterface]
/// 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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -144,7 +145,7 @@ private KeepSimulationRunningExample() {
broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList);

simulation.addOnClockTickListener(this::createDynamicCloudletAndVm);
simulation.listeners().addOnClockTick(this::createDynamicCloudletAndVm);

simulation.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -134,7 +135,7 @@ private RandomCloudletsArrivalExample() {
broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList);

simulation.addOnClockTickListener(this::createRandomCloudlets);
simulation.listeners().addOnClockTick(this::createRandomCloudlets);

simulation.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Loading
Loading