Interface Simulation
- All Known Implementing Classes:
CloudSimPlus
- Since:
- CloudSim Plus 1.0
- Author:
- Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionA standard predicate that matches any event.static final SimulationAn attribute that implements the Null Object Design Pattern forSimulationobjects. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Aborts the simulation without finishing the processing of entities in theentities list, which may give unexpected results.voidaddEntity(CloudSimEntity entity) Adds a new entity to the simulation.addOnClockTickListener(EventListener<EventInfo> listener) Adds aEventListenerobject that will be notified every time when the simulation clock advances.addOnEventProcessingListener(EventListener<SimEvent> listener) Adds aEventListenerobject that will be notified when any event is processed by CloudSim Plus.addOnSimulationPauseListener(EventListener<EventInfo> listener) Adds anEventListenerobject that will be notified when the simulation is paused.addOnSimulationStartListener(EventListener<EventInfo> listener) Cancels the first event from the future event queue that matches a givenPredicateand was sent by a given entity, then removes it from the queue.booleanCancels all events from the future event queue that matches a givenPredicateand were sent by a given entity, then removes those from the queue.doubleclock()doubledoubleclockStr()findFirstDeferred(SimEntity dest, Predicate<SimEvent> predicate) Find the first-deferred event matching aPredicate.getCis()doubledoublelonggetNumberOfFutureEvents(Predicate<SimEvent> predicate) Returns the number of events in the future queue which match a given predicate.intbooleanbooleanbooleanisPaused()booleanCheck if the simulation is still running.booleanbooleanisThereAnyFutureEvt(Predicate<SimEvent> predicate) Checks if there is any event in the future queue that matches a given predicate.booleanbooleanpause()Requests the simulation to be paused as soon as possible.booleanpause(double time) Requests the simulation to be paused at a given time.voidpauseEntity(SimEntity src, double delay) Pauses an entity for some time.booleanremoveOnClockTickListener(EventListener<? extends EventInfo> listener) Removes a listener from the onClockTickListener List.booleanremoveOnEventProcessingListener(EventListener<SimEvent> listener) Removes a listener from the onEventProcessingListener List.booleanRemoves a listener from the onSimulationPausedListener List.booleanresume()Resumes the simulation if it has previously been paused.doublerunFor(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.voidSends an event where all data required is defined inside the event instance.voidSends an event from one entity to another.voidSends an event where all data required is defined inside the event instance, adding it to the beginning of the queue to give priority to it.voidSends an event from one entity to another, adding it to the beginning of the queue to give priority to it.voidSends an event from one entity to another without delaying the message.static <T extends ChangeableId>
TsetIdForEntitiesWithoutOne(List<? extends T> list) Defines IDs for a list ofChangeableIdentities that don't have one already assigned.static <T extends ChangeableId>
TsetIdForEntitiesWithoutOne(List<? extends T> list, T lastEntity) Defines IDs for a list ofChangeableIdentities that don't have one already assigned.setLastCloudletProcessingUpdate(double lastCloudletProcessingUpdate) Sets the last time some Cloudlet was processed in the simulation.setNetworkTopology(NetworkTopology networkTopology) Sets theNetworkTopologyused for Network simulations.doublestart()Starts simulation execution and waits for all entities to finish, i.e., until all entities reach the non-RUNNABLE state or there are no more events in the future event queue.voidStarts simulation execution in synchronous mode, retuning immediately.booleanForces the termination of the simulation before it ends.booleanterminateAt(double time) Schedules the termination of the simulation for a given time (in seconds).voidwait(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
-
ANY_EVT
-
NULL
An attribute that implements the Null Object Design Pattern forSimulationobjects.
-
-
Method Details
-
setIdForEntitiesWithoutOne
Defines IDs for a list ofChangeableIdentities that don't have one already assigned. Such entities can be aCloudlet,Vmor any object that implementsChangeableId.- Type Parameters:
T- the type of entities to define an ID- Parameters:
list- list of entities to define an ID- Returns:
- the last entity that had an id set
-
setIdForEntitiesWithoutOne
Defines IDs for a list ofChangeableIdentities that don't have one already assigned. Such entities can be aCloudlet,Vmor any object that implementsChangeableId.- Type Parameters:
T- the type of entities to define an ID- Parameters:
list- list of entities to define an IDlastEntity- the last created Entity which its ID will be used as the base for the next IDs- Returns:
- the last entity that had an id set
-
isTerminationTimeSet
boolean isTerminationTimeSet() -
abort
void abort()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 and usually ignore the results.
-
isAborted
boolean isAborted()- Returns:
- true if the simulation has been aborted, false otherwise
-
addEntity
Adds a new entity to the simulation. EachCloudSimEntityobject register itself when it is instantiated.- Parameters:
entity- the new entity to add
-
cancel
Cancels the first event from the future event queue that matches a givenPredicateand was sent by a given entity, then removes it from the queue.- Parameters:
src- entity that scheduled the eventpredicate- the event selection predicate- Returns:
- the removed event or
SimEvent.NULLif not found
-
cancelAll
Cancels all events from the future event queue that matches a givenPredicateand were sent by a given entity, then removes those from the queue.- Parameters:
src- entity that scheduled the eventpredicate- the event selection predicate- Returns:
- true if at least one event has been canceled; false otherwise
-
clock
double clock()- Returns:
- the current simulation time in seconds.
- See Also:
-
clockStr
String clockStr()- Returns:
- the current simulation time in seconds as a formatted String.
- See Also:
-
clockInMinutes
double clockInMinutes()- Returns:
- the current simulation time in minutes.
- See Also:
-
clockInHours
double clockInHours()- Returns:
- the current simulation time in hours.
- See Also:
-
findFirstDeferred
-
getCalendar
Calendar getCalendar()- Returns:
- the simulation Calendar
-
getCis
CloudInformationService getCis()- Returns:
- the
CloudInformationService
-
getEntityList
-
getMinTimeBetweenEvents
double getMinTimeBetweenEvents()- Returns:
- the minimum time between events (in seconds). Events within shorter periods after the last event are discarded.
-
getNumEntities
int getNumEntities()- Returns:
- the current number of entities in the simulation.
-
removeOnEventProcessingListener
Removes a listener from the onEventProcessingListener List.- Parameters:
listener- the listener to remove- Returns:
- true if the listener was found and removed, false otherwise
-
addOnSimulationPauseListener
Adds anEventListenerobject that will be notified when the simulation is paused. When this Listener is notified, it will receive anEventInfoinforming the time the pause occurred.This object is just information about the event that happened. In fact, it isn't generated an actual
SimEventfor a pause event because there is no need for that.- Parameters:
listener- the event listener to add
-
addOnSimulationStartListener
-
removeOnSimulationPauseListener
Removes a listener from the onSimulationPausedListener List.- Parameters:
listener- the listener to remove- Returns:
- true if the listener was found and removed, false otherwise
-
addOnEventProcessingListener
Adds aEventListenerobject that will be notified when any event is processed by CloudSim Plus. When this Listener is notified, it will receive theSimEventthat was processed.- Parameters:
listener- the event listener to add- Returns:
- this simulation
-
addOnClockTickListener
Adds aEventListenerobject that will be notified every time when the simulation clock advances. WARNING: Notifications are sent in an integer 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.- Parameters:
listener- the event listener to add- Returns:
- this simulation
-
removeOnClockTickListener
Removes a listener from the onClockTickListener List.- Parameters:
listener- the listener to remove- Returns:
- true if the listener was found and removed, false otherwise
-
pauseEntity
Pauses an entity for some time.- Parameters:
src- entity to be pauseddelay- the time period for which the entity will be inactive
-
isPaused
boolean isPaused()- Returns:
- true if the simulation is paused, false otherwise.
-
pause
boolean pause()Requests the simulation to be paused as soon as possible.- Returns:
- true if the simulation was paused, false if it was already paused or has finished
-
pause
boolean pause(double time) Requests the simulation to be paused at a given time. The method schedules the pause request and then returns immediately.- Parameters:
time- the time at which the simulation has to be paused- Returns:
- true if a pause request was successfully received (the given time is greater than or equal to the current simulation time), false otherwise.
-
resume
boolean resume()Resumes the simulation if it has previously been paused.- Returns:
- true if the simulation has been restarted or false if it wasn't paused before.
-
isRunning
boolean isRunning()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 already.This method should be used by entities to check if they should continue executing.
- Returns:
-
select
Selects the first deferred event that matches a given predicate and removes it from the queue.- Parameters:
dest- entity that the event has to be sent topredicate- the event selection predicate- Returns:
- the removed event or
SimEvent.NULLif not found
-
send
Sends an event where all data required is defined inside the event instance.- Parameters:
evt- the event to send
-
send
Sends an event from one entity to another. -
sendFirst
Sends an event where all data required is defined inside the event instance, adding it to the beginning of the queue to give priority to it.- Parameters:
evt- the event to send
-
sendFirst
Sends an event from one entity to another, adding it to the beginning of the queue to give priority to it. -
sendNow
Sends an event from one entity to another without delaying the message. -
runFor
double runFor(double interval) Runs the simulation for a specific period of time and then immediately returns. You need to invoke this method multiple times to complete the whole simulation.NOTE: Should be used only in the synchronous mode (after starting the simulation with
startSync()).- Parameters:
interval- the interval for which the simulation should be run (in seconds)- Returns:
- clock at the end of the simulation interval (in seconds)
-
start
double start()Starts simulation execution and waits for all entities to finish, i.e., until all entities reach the non-RUNNABLE state or there are no more events in the future event queue.NOTE: This method should be called only after all entities have been set up and added. The method blocks until the simulation is ended.
- Returns:
- the last clock time (in seconds)
- Throws:
UnsupportedOperationException- When the simulation has already run once. If you paused the simulation and wants to resume it, you must useresume()instead of calling the current method.- See Also:
-
startSync
void startSync()Starts simulation execution in synchronous mode, retuning immediately. You need to callrunFor(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.
- Throws:
UnsupportedOperationException- When the simulation has already run once. If you paused the simulation and wants to resume it, you must useresume()instead of calling the current method.- See Also:
-
isTimeToTerminateSimulationUnderRequest
boolean isTimeToTerminateSimulationUnderRequest() -
terminate
boolean terminate()Forces the termination of the simulation before it ends.- Returns:
- true if the simulation was running and the termination request was accepted, false if the simulation was not started yet
-
terminateAt
boolean terminateAt(double time) 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 lowest
Datacenter.getSchedulingInterval()between existing Datacenters; - or
getMinTimeBetweenEvents()in case noDatacenterhas its schedulingInterval set.
- 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 lowest
-
wait
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.- Parameters:
src- entity that scheduled the eventpredicate- the event selection predicate
-
getNetworkTopology
NetworkTopology getNetworkTopology()- Returns:
- the
NetworkTopologyused for Network simulations.
-
setNetworkTopology
Sets theNetworkTopologyused for Network simulations.- Parameters:
networkTopology- the network topology to set- Returns:
- this simulation
-
getNumberOfFutureEvents
-
isThereAnyFutureEvt
-
getLastCloudletProcessingUpdate
double getLastCloudletProcessingUpdate()- Returns:
- the last time (in seconds) some Cloudlet was processed in the simulation.
-
setLastCloudletProcessingUpdate
Sets the last time some Cloudlet was processed in the simulation.- Parameters:
lastCloudletProcessingUpdate- the time to set (in seconds)
-
isAbortRequested
boolean isAbortRequested()- Returns:
- true if a request to abort the simulation was already sent, false otherwise.
-