Class CloudSim
- All Implemented Interfaces:
Simulation
- Since:
- CloudSim Toolkit 1.0
- Author:
- Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.slf4j.Logger
static final String
CloudSim Plus current version.Fields inherited from interface org.cloudbus.cloudsim.core.Simulation
ANY_EVT, NULL
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Aborts the simulation without finishing the processing of entities in theentities list
, which may give unexpected results.void
addEntity
(CloudSimEntity entity) Adds a new entity to the simulation.addOnClockTickListener
(EventListener<EventInfo> listener) Adds aEventListener
object that will be notified every time when the simulation clock advances.final Simulation
addOnEventProcessingListener
(EventListener<SimEvent> listener) Adds aEventListener
object that will be notified when any event is processed by CloudSim.final Simulation
addOnSimulationPauseListener
(EventListener<EventInfo> listener) Adds anEventListener
object that will be notified when the simulation is paused.final Simulation
addOnSimulationStartListener
(EventListener<EventInfo> listener) Cancels the first event from the future event queue that matches a given predicate and was sent by a given entity, then removes it from the queue.boolean
Cancels all events from the future event queue that matches a given predicate and were sent by a given entity, then removes those ones from the queue.double
clock()
Gets the current simulation time in seconds.double
Gets the current simulation time in hours.double
Gets the current simulation time in minutes.clockStr()
Gets the current simulation time in seconds as a formatted String.findFirstDeferred
(SimEntity dest, Predicate<SimEvent> predicate) Find first deferred event matching a predicate.Gets a new copy of initial simulation Calendar.Gets theCloudInformationService
.Returns a read-only list of entities created for the simulation.long
Gets the total number of events generated in theFutureQueue
double
Gets the last time (in seconds) some Cloudlet was processed in the simulation.long
Gets the maximum number of events that have ever existed at the same time inside theFutureQueue
.double
Gets the minimum time between events (in seconds).Gets the network topology used for Network simulations.long
getNumberOfFutureEvents
(Predicate<SimEvent> predicate) Gets the number of events in the future queue which match a given predicate.int
Get the current number of entities in the simulation.double
Gets the time defined to terminate the simulation or -1 if it was not set.protected void
holdEntity
(SimEntity src, long delay) Holds an entity for some time.boolean
Check if the simulation has been aborted.boolean
Indicates if an abrupt termination was requested.boolean
isPaused()
Checks if the simulation is paused.boolean
Check if the simulation is still running.boolean
boolean
isThereAnyFutureEvt
(Predicate<SimEvent> predicate) Checks if there is any event in the future queue that matches a given predicate.boolean
boolean
pause()
Requests the simulation to be paused as soon as possible.boolean
pause
(double time) Requests the simulation to be paused at a given time.void
pauseEntity
(SimEntity src, double delay) Pauses an entity for some time.protected void
removeFinishedEntity
(CloudSimEntity entity) boolean
removeOnClockTickListener
(EventListener<? extends EventInfo> listener) Removes a listener from the onClockTickListener List.boolean
removeOnEventProcessingListener
(EventListener<SimEvent> listener) Removes a listener from the onEventProcessingListener List.boolean
Removes a listener from the onSimulationPausedListener List.boolean
resume()
Resumes the simulation if it has previously been paused.double
runFor
(double interval) Runs the simulation for a specific period of time and then immediately returns.Selects the first deferred event that matches a given predicate and removes it from the queue.void
Sends an event where all data required is defined inside the event instance.void
send
(SimEntity src, SimEntity dest, double delay, CloudSimTag tag, Object data) Sends an event from one entity to another.void
Sends an event where all data required is defined inside the event instance, adding it to the beginning of the queue in order to give priority to it.void
sendFirst
(SimEntity src, SimEntity dest, double delay, CloudSimTag tag, Object data) Sends an event from one entity to another, adding it to the beginning of the queue in order to give priority to it.void
sendNow
(SimEntity src, SimEntity dest, CloudSimTag tag, Object data) Sends an event from one entity to another without delaying the message.void
setLastCloudletProcessingUpdate
(double lastCloudletProcessingUpdate) Sets the last time (in seconds) some Cloudlet was processed in the simulation.void
setNetworkTopology
(NetworkTopology networkTopology) Sets the network topology used for Network simulations.double
start()
Starts simulation execution and waits for all entities to finish, i.e.void
Starts simulation execution in synchronous mode, retuning immediately.boolean
Forces the termination of the simulation before it ends.boolean
terminateAt
(double time) Schedules the termination of the simulation for a given time (in seconds).void
wait
(CloudSimEntity src, Predicate<SimEvent> predicate) Sets the state of an entity toSimEntity.State.WAITING
, making it to wait for events that satisfy a given predicate.
-
Field Details
-
VERSION
CloudSim Plus current version.- See Also:
-
LOGGER
public static final org.slf4j.Logger LOGGER
-
-
Constructor Details
-
CloudSim
public CloudSim()Creates a CloudSim simulation. Internally it creates a CloudInformationService.- See Also:
-
CloudSim
public CloudSim(double minTimeBetweenEvents) Creates a CloudSim simulation that tracks events happening in a time interval as little as the minTimeBetweenEvents parameter. Internally it creates aCloudInformationService
.- Parameters:
minTimeBetweenEvents
- the minimal period between events. Events within shorter periods after the last event are discarded.- See Also:
-
-
Method Details
-
runFor
public double runFor(double interval) Description copied from interface:Simulation
Runs the simulation for a specific period of time and then immediately returns. In order to complete the whole simulation you need to invoke this method multiple times Note: Should be used only in the synchronous mode (after starting the simulation withSimulation.startSync()
).- Specified by:
runFor
in interfaceSimulation
- Parameters:
interval
- The interval for which the simulation should be run (in seconds)- Returns:
- Clock at the end of simulation interval (in seconds)
-
start
public double start()Description copied from interface:Simulation
Starts simulation execution and waits for all entities to finish, i.e. until all entities threads reach non-RUNNABLE state or there are no more events in the future event queue.Note: This method should be called only after all the entities have been setup and added. The method blocks until the simulation is ended.
- Specified by:
start
in interfaceSimulation
- Returns:
- the last clock time
- See Also:
-
startSync
public void startSync()Description copied from interface:Simulation
Starts simulation execution in synchronous mode, retuning immediately. You need to callSimulation.runFor(double)
method subsequently to actually process simulation steps. Note: This method should be called only after all entities have been set up and added. The method returns immediately after preparing the internal state of the simulation.- Specified by:
startSync
in interfaceSimulation
- See Also:
-
isTimeToTerminateSimulationUnderRequest
public boolean isTimeToTerminateSimulationUnderRequest()- Specified by:
isTimeToTerminateSimulationUnderRequest
in interfaceSimulation
-
terminate
public boolean terminate()Description copied from interface:Simulation
Forces the termination of the simulation before it ends.- Specified by:
terminate
in interfaceSimulation
- Returns:
- true if the simulation was running and the termination request was accepted, false if the simulation was not started yet
-
terminateAt
public boolean terminateAt(double time) Description copied from interface:Simulation
Schedules the termination of the simulation for a given time (in seconds).If a termination time is set, the simulation stays running even if there is no event to process. It keeps waiting for new dynamic events, such as the creation of Cloudlets and VMs at runtime. If no event happens, the clock is increased to simulate time passing. The clock increment is defined according to:
- the lower
Datacenter.getSchedulingInterval()
between existing Datacenters; - or
Simulation.getMinTimeBetweenEvents()
in case noDatacenter
has its schedulingInterval set.
- Specified by:
terminateAt
in interfaceSimulation
- Parameters:
time
- the time at which the simulation has to be terminated (in seconds)- Returns:
- true if the time given is greater than the current simulation time, false otherwise
- the lower
-
getTerminationTime
public double getTerminationTime()Gets the time defined to terminate the simulation or -1 if it was not set.- Returns:
-
getMinTimeBetweenEvents
public double getMinTimeBetweenEvents()Description copied from interface:Simulation
Gets the minimum time between events (in seconds). Events within shorter periods after the last event are discarded.- Specified by:
getMinTimeBetweenEvents
in interfaceSimulation
- Returns:
- the minimum time between events (in seconds).
-
getCalendar
Description copied from interface:Simulation
Gets a new copy of initial simulation Calendar.- Specified by:
getCalendar
in interfaceSimulation
- Returns:
- a new copy of Calendar object
-
getCloudInfoService
Description copied from interface:Simulation
Gets theCloudInformationService
.- Specified by:
getCloudInfoService
in interfaceSimulation
- Returns:
- the Entity
-
clock
public double clock()Description copied from interface:Simulation
Gets the current simulation time in seconds.- Specified by:
clock
in interfaceSimulation
- Returns:
- See Also:
-
clockStr
Description copied from interface:Simulation
Gets the current simulation time in seconds as a formatted String.- Specified by:
clockStr
in interfaceSimulation
- Returns:
- See Also:
-
clockInMinutes
public double clockInMinutes()Description copied from interface:Simulation
Gets the current simulation time in minutes.- Specified by:
clockInMinutes
in interfaceSimulation
- Returns:
- See Also:
-
clockInHours
public double clockInHours()Description copied from interface:Simulation
Gets the current simulation time in hours.- Specified by:
clockInHours
in interfaceSimulation
- Returns:
- See Also:
-
getNumEntities
public int getNumEntities()Description copied from interface:Simulation
Get the current number of entities in the simulation.- Specified by:
getNumEntities
in interfaceSimulation
- Returns:
- The number of entities
-
getEntityList
Description copied from interface:Simulation
Returns a read-only list of entities created for the simulation.- Specified by:
getEntityList
in interfaceSimulation
- Returns:
-
addEntity
Description copied from interface:Simulation
Adds a new entity to the simulation. EachCloudSimEntity
object register itself when it is instantiated.- Specified by:
addEntity
in interfaceSimulation
- Parameters:
entity
- The new entity
-
removeFinishedEntity
-
sendNow
Description copied from interface:Simulation
Sends an event from one entity to another without delaying the message.- Specified by:
sendNow
in interfaceSimulation
- Parameters:
src
- entity that scheduled the eventdest
- entity that the event will be sent totag
- thetag
that classifies the eventdata
- thedata
to be sent inside the event
-
send
Description copied from interface:Simulation
Sends an event from one entity to another.- Specified by:
send
in interfaceSimulation
- Parameters:
src
- entity that scheduled the eventdest
- entity that the event will be sent todelay
- How many seconds after the current simulation time the event should be senttag
- thetag
that classifies the eventdata
- thedata
to be sent inside the event
-
send
Description copied from interface:Simulation
Sends an event where all data required is defined inside the event instance.- Specified by:
send
in interfaceSimulation
- Parameters:
evt
- the event to send
-
sendFirst
Description copied from interface:Simulation
Sends an event from one entity to another, adding it to the beginning of the queue in order to give priority to it.- Specified by:
sendFirst
in interfaceSimulation
- Parameters:
src
- entity that scheduled the eventdest
- entity that the event will be sent todelay
- How many seconds after the current simulation time the event should be senttag
- thetag
that classifies the eventdata
- thedata
to be sent inside the event
-
sendFirst
Description copied from interface:Simulation
Sends an event where all data required is defined inside the event instance, adding it to the beginning of the queue in order to give priority to it.- Specified by:
sendFirst
in interfaceSimulation
- Parameters:
evt
- the event to send
-
wait
Description copied from interface:Simulation
Sets the state of an entity toSimEntity.State.WAITING
, making it to wait for events that satisfy a given predicate. Only such events will be passed to the entity. This is done to avoid unnecessary context switch.- Specified by:
wait
in interfaceSimulation
- Parameters:
src
- entity that scheduled the eventpredicate
- the event selection predicate
-
select
Description copied from interface:Simulation
Selects the first deferred event that matches a given predicate and removes it from the queue.- Specified by:
select
in interfaceSimulation
- Parameters:
dest
- entity that the event has to be sent topredicate
- the event selection predicate- Returns:
- the removed event or
SimEvent.NULL
if not found
-
findFirstDeferred
Description copied from interface:Simulation
Find first deferred event matching a predicate.- Specified by:
findFirstDeferred
in interfaceSimulation
- Parameters:
dest
- id of entity that the event has to be sent topredicate
- the event selection predicate- Returns:
- the first matched event or
SimEvent.NULL
if not found
-
cancel
Description copied from interface:Simulation
Cancels the first event from the future event queue that matches a given predicate and was sent by a given entity, then removes it from the queue.- Specified by:
cancel
in interfaceSimulation
- Parameters:
src
- Id of entity that scheduled the eventpredicate
- the event selection predicate- Returns:
- the removed event or
SimEvent.NULL
if not found
-
cancelAll
Description copied from interface:Simulation
Cancels all events from the future event queue that matches a given predicate and were sent by a given entity, then removes those ones from the queue.- Specified by:
cancelAll
in interfaceSimulation
- Parameters:
src
- id of entity that scheduled the eventpredicate
- the event selection predicate- Returns:
- true if at least one event has been cancelled; false otherwise
-
isRunning
public boolean isRunning()Description copied from interface:Simulation
Check if the simulation is still running. Even if the simulationis paused
, the method returns true to indicate that the simulation is in fact active yet.This method should be used by entities to check if they should continue executing.
- Specified by:
isRunning
in interfaceSimulation
- Returns:
-
pause
public boolean pause()Description copied from interface:Simulation
Requests the simulation to be paused as soon as possible.- Specified by:
pause
in interfaceSimulation
- Returns:
- true if the simulation was paused, false if it was already paused or has finished
-
pause
public boolean pause(double time) Description copied from interface:Simulation
Requests the simulation to be paused at a given time. The method schedules the pause request and then returns immediately.- Specified by:
pause
in interfaceSimulation
- Parameters:
time
- the time at which the simulation has to be paused- Returns:
- true if pause request was successfully received (the given time is greater than or equal to the current simulation time), false otherwise.
-
resume
public boolean resume()Description copied from interface:Simulation
Resumes the simulation if it has previously been paused.- Specified by:
resume
in interfaceSimulation
- Returns:
- true if the simulation has been restarted or false if it wasn't paused before.
-
pauseEntity
Description copied from interface:Simulation
Pauses an entity for some time.- Specified by:
pauseEntity
in interfaceSimulation
- Parameters:
src
- id of entity to be pauseddelay
- the time period for which the entity will be inactive
-
holdEntity
Holds an entity for some time.- Parameters:
src
- id of entity to be helddelay
- How many seconds after the current time the entity has to be held
-
getNumberOfFutureEvents
Description copied from interface:Simulation
Gets the number of events in the future queue which match a given predicate.- Specified by:
getNumberOfFutureEvents
in interfaceSimulation
- Parameters:
predicate
- the predicate to filter the list of future events.- Returns:
- the number of future events which match the predicate
-
isThereAnyFutureEvt
Description copied from interface:Simulation
Checks if there is any event in the future queue that matches a given predicate.- Specified by:
isThereAnyFutureEvt
in interfaceSimulation
- Parameters:
predicate
- the predicate to selected the desired events- Returns:
- true if any event matching the given predicate is found, false otherwise
-
isTerminationTimeSet
public boolean isTerminationTimeSet()- Specified by:
isTerminationTimeSet
in interfaceSimulation
-
abort
public void abort()Description copied from interface:Simulation
Aborts the simulation without finishing the processing of entities in theentities list
, which may give unexpected results.Use this method just if you want to abandon the simulation an usually ignore the results.
- Specified by:
abort
in interfaceSimulation
-
isAborted
public boolean isAborted()Description copied from interface:Simulation
Check if the simulation has been aborted.- Specified by:
isAborted
in interfaceSimulation
- Returns:
-
isPaused
public boolean isPaused()Description copied from interface:Simulation
Checks if the simulation is paused.- Specified by:
isPaused
in interfaceSimulation
- Returns:
-
addOnSimulationPauseListener
Description copied from interface:Simulation
Adds anEventListener
object that will be notified when the simulation is paused. When this Listener is notified, it will receive anEventInfo
informing the time the pause occurred.This object is just information about the event that happened. In fact, it isn't generated an actual
SimEvent
for a pause event because there is not need for that.- Specified by:
addOnSimulationPauseListener
in interfaceSimulation
- Parameters:
listener
- the event listener to add- Returns:
-
addOnSimulationStartListener
- Specified by:
addOnSimulationStartListener
in interfaceSimulation
-
removeOnSimulationPauseListener
Description copied from interface:Simulation
Removes a listener from the onSimulationPausedListener List.- Specified by:
removeOnSimulationPauseListener
in interfaceSimulation
- Parameters:
listener
- the listener to remove- Returns:
- true if the listener was found and removed, false otherwise
-
addOnEventProcessingListener
Description copied from interface:Simulation
Adds aEventListener
object that will be notified when any event is processed by CloudSim. When this Listener is notified, it will receive theSimEvent
that was processed.- Specified by:
addOnEventProcessingListener
in interfaceSimulation
- Parameters:
listener
- the event listener to add- Returns:
-
removeOnEventProcessingListener
Description copied from interface:Simulation
Removes a listener from the onEventProcessingListener List.- Specified by:
removeOnEventProcessingListener
in interfaceSimulation
- Parameters:
listener
- the listener to remove- Returns:
- true if the listener was found and removed, false otherwise
-
addOnClockTickListener
Description copied from interface:Simulation
Adds aEventListener
object that will be notified every time when the simulation clock advances. Notifications are sent in a second interval to avoid notification flood. Thus, if the clock changes, for instance, from 1.0, to 1.1, 2.0, 2.1, 2.2, 2.5 and then 3.2, notifications will just be sent for the times 1, 2 and 3 that represent the integer part of the simulation time.- Specified by:
addOnClockTickListener
in interfaceSimulation
- Parameters:
listener
- the event listener to add- Returns:
-
removeOnClockTickListener
Description copied from interface:Simulation
Removes a listener from the onClockTickListener List.- Specified by:
removeOnClockTickListener
in interfaceSimulation
- Parameters:
listener
- the listener to remove- Returns:
- true if the listener was found and removed, false otherwise
-
getNetworkTopology
Description copied from interface:Simulation
Gets the network topology used for Network simulations.- Specified by:
getNetworkTopology
in interfaceSimulation
- Returns:
-
setNetworkTopology
Description copied from interface:Simulation
Sets the network topology used for Network simulations.- Specified by:
setNetworkTopology
in interfaceSimulation
- Parameters:
networkTopology
- the network topology to set
-
getLastCloudletProcessingUpdate
public double getLastCloudletProcessingUpdate()Description copied from interface:Simulation
Gets the last time (in seconds) some Cloudlet was processed in the simulation.- Specified by:
getLastCloudletProcessingUpdate
in interfaceSimulation
-
setLastCloudletProcessingUpdate
public void setLastCloudletProcessingUpdate(double lastCloudletProcessingUpdate) Description copied from interface:Simulation
Sets the last time (in seconds) some Cloudlet was processed in the simulation.- Specified by:
setLastCloudletProcessingUpdate
in interfaceSimulation
- Parameters:
lastCloudletProcessingUpdate
- the time to set (in seconds)
-
getMaxEventsNumber
public long getMaxEventsNumber()Gets the maximum number of events that have ever existed at the same time inside theFutureQueue
. -
getGeneratedEventsNumber
public long getGeneratedEventsNumber()Gets the total number of events generated in theFutureQueue
-
isAbortRequested
public boolean isAbortRequested()Indicates if an abrupt termination was requested.- Specified by:
isAbortRequested
in interfaceSimulation
- Returns:
- See Also:
-