public class CloudSim extends Object implements Simulation
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
LOGGER |
static String |
VERSION
CloudSim Plus current version.
|
ANY_EVT, NULL
Constructor and Description |
---|
CloudSim()
Creates a CloudSim simulation.
|
CloudSim(double minTimeBetweenEvents)
Creates a CloudSim simulation that tracks events happening in a time interval
as little as the minTimeBetweenEvents parameter.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts the simulation without finishing the processing
of entities in the
entities list , which may give
unexpected results. |
void |
addEntity(CloudSimEntity entity)
Adds a new entity to the simulation.
|
Simulation |
addOnClockTickListener(EventListener<EventInfo> listener)
Adds a
EventListener object that will be notified every time when the
simulation clock advances. |
Simulation |
addOnEventProcessingListener(EventListener<SimEvent> listener)
Adds a
EventListener object that will be notified when any event
is processed by CloudSim. |
Simulation |
addOnSimulationPauseListener(EventListener<EventInfo> listener)
Adds an
EventListener object that will be notified when the simulation is paused. |
Simulation |
addOnSimulationStartListener(EventListener<EventInfo> listener) |
SimEvent |
cancel(SimEntity src,
Predicate<SimEvent> predicate)
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 |
cancelAll(SimEntity src,
Predicate<SimEvent> predicate)
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 |
clockInHours()
Gets the current simulation time in hours.
|
double |
clockInMinutes()
Gets the current simulation time in minutes.
|
String |
clockStr()
Gets the current simulation time in seconds as a formatted String.
|
SimEvent |
findFirstDeferred(SimEntity dest,
Predicate<SimEvent> predicate)
Find first deferred event matching a predicate.
|
Calendar |
getCalendar()
Gets a new copy of initial simulation Calendar.
|
CloudInformationService |
getCloudInfoService()
Gets the
CloudInformationService . |
List<SimEntity> |
getEntityList()
Returns a read-only list of entities created for the simulation.
|
long |
getGeneratedEventsNumber()
Gets the total number of events generated in the
FutureQueue |
double |
getLastCloudletProcessingUpdate()
Gets the last time (in seconds) some Cloudlet was processed in the simulation.
|
long |
getMaxEventsNumber()
Gets the maximum number of events that have ever existed at the same time
inside the
FutureQueue . |
double |
getMinTimeBetweenEvents()
Returns the minimum time between events (in seconds).
|
NetworkTopology |
getNetworkTopology()
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 |
getNumEntities()
Get the current number of entities in the simulation.
|
double |
getTerminationTime()
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 |
isAborted()
Check if the simulation has been aborted.
|
boolean |
isAbortRequested()
Indicates if an abrupt termination was requested.
|
boolean |
isPaused()
Checks if the simulation is paused.
|
boolean |
isRunning()
Check if the simulation is still running.
|
boolean |
isTerminationTimeSet() |
boolean |
isThereAnyFutureEvt(Predicate<SimEvent> predicate)
Checks if there is any event in the future queue that matches a given predicate.
|
boolean |
isTimeToTerminateSimulationUnderRequest() |
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 |
removeOnSimulationPauseListener(EventListener<EventInfo> listener)
Removes a listener from the onSimulationPausedListener List.
|
boolean |
resume()
This method is called if one wants to resume the simulation that has
previously been paused.
|
double |
runFor(double interval)
Runs the simulation for a specific period of time and then immediately returns.
|
SimEvent |
select(SimEntity dest,
Predicate<SimEvent> predicate)
Selects the first deferred event that matches a given predicate
and removes it from the queue.
|
void |
send(SimEntity src,
SimEntity dest,
double delay,
int tag,
Object data)
Sends an event from one entity to another.
|
void |
send(SimEvent evt)
Sends an event where all data required is defined inside the event instance.
|
void |
sendFirst(SimEntity src,
SimEntity dest,
double delay,
int 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 |
sendFirst(SimEvent evt)
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 |
sendNow(SimEntity src,
SimEntity dest,
int 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 |
startSync()
Starts simulation execution in synchronous mode, retuning immediately.
|
boolean |
terminate()
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 to
SimEntity.State.WAITING ,
making it to wait for events that satisfy a given predicate. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setIdForEntitiesWithoutOne, setIdForEntitiesWithoutOne
public static final String VERSION
public static final org.slf4j.Logger LOGGER
public CloudSim()
CloudInformationService
,
CloudSim(double)
public CloudSim(double minTimeBetweenEvents)
CloudInformationService
.minTimeBetweenEvents
- the minimal period between events. Events
within shorter periods after the last event are discarded.CloudInformationService
public double runFor(double interval)
Simulation
Simulation.startSync()
).runFor
in interface Simulation
interval
- The interval for which the simulation should be run (in seconds)public double start()
Simulation
Note: This method should be called only after all the entities have been setup and added. The method blocks until the simulation is ended.
start
in interface Simulation
Simulation.startSync()
public void startSync()
Simulation
Simulation.runFor(double)
method subsequently to actually process simulation steps.
Note: This method should be called only after all the entities
have been setup and added. The method returns immediately after preparing the
internal state of the simulation.
startSync
in interface Simulation
Simulation.runFor(double)
public boolean isTimeToTerminateSimulationUnderRequest()
isTimeToTerminateSimulationUnderRequest
in interface Simulation
public boolean terminate()
Simulation
terminate
in interface Simulation
public boolean terminateAt(double time)
Simulation
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: (i) the lower Datacenter.getSchedulingInterval()
between existing Datacenters; or (ii) Simulation.getMinTimeBetweenEvents()
in case
no Datacenter
has its schedulingInterval set.
terminateAt
in interface Simulation
time
- the time at which the simulation has to be terminated (in seconds)public double getTerminationTime()
public double getMinTimeBetweenEvents()
Simulation
getMinTimeBetweenEvents
in interface Simulation
public Calendar getCalendar()
Simulation
getCalendar
in interface Simulation
public CloudInformationService getCloudInfoService()
Simulation
CloudInformationService
.getCloudInfoService
in interface Simulation
public double clock()
Simulation
clock
in interface Simulation
Simulation.isRunning()
public String clockStr()
Simulation
clockStr
in interface Simulation
Simulation.clock()
public double clockInMinutes()
Simulation
clockInMinutes
in interface Simulation
Simulation.isRunning()
public double clockInHours()
Simulation
clockInHours
in interface Simulation
Simulation.isRunning()
public int getNumEntities()
Simulation
getNumEntities
in interface Simulation
public List<SimEntity> getEntityList()
Simulation
getEntityList
in interface Simulation
public void addEntity(CloudSimEntity entity)
Simulation
CloudSimEntity
object
register itself when it is instantiated.addEntity
in interface Simulation
entity
- The new entityprotected void removeFinishedEntity(CloudSimEntity entity)
public void sendNow(SimEntity src, SimEntity dest, int tag, Object data)
Simulation
sendNow
in interface Simulation
src
- entity that scheduled the eventdest
- entity that the event will be sent totag
- the tag
that classifies the eventdata
- the data
to be sent inside the eventpublic void send(SimEntity src, SimEntity dest, double delay, int tag, Object data)
Simulation
send
in interface Simulation
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
- the tag
that classifies the eventdata
- the data
to be sent inside the eventpublic void send(SimEvent evt)
Simulation
send
in interface Simulation
evt
- the event to sendpublic void sendFirst(SimEntity src, SimEntity dest, double delay, int tag, Object data)
Simulation
sendFirst
in interface Simulation
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
- the tag
that classifies the eventdata
- the data
to be sent inside the eventpublic void sendFirst(SimEvent evt)
Simulation
sendFirst
in interface Simulation
evt
- the event to sendpublic void wait(CloudSimEntity src, Predicate<SimEvent> predicate)
Simulation
SimEntity.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.wait
in interface Simulation
src
- entity that scheduled the eventpredicate
- the event selection predicatepublic SimEvent select(SimEntity dest, Predicate<SimEvent> predicate)
Simulation
select
in interface Simulation
dest
- entity that the event has to be sent topredicate
- the event selection predicateSimEvent.NULL
if not foundpublic SimEvent findFirstDeferred(SimEntity dest, Predicate<SimEvent> predicate)
Simulation
findFirstDeferred
in interface Simulation
dest
- Id of entity that the event has to be sent topredicate
- the event selection predicateSimEvent.NULL
if not foundpublic SimEvent cancel(SimEntity src, Predicate<SimEvent> predicate)
Simulation
cancel
in interface Simulation
src
- Id of entity that scheduled the eventpredicate
- the event selection predicateSimEvent.NULL
if not foundpublic boolean cancelAll(SimEntity src, Predicate<SimEvent> predicate)
Simulation
cancelAll
in interface Simulation
src
- Id of entity that scheduled the eventpredicate
- the event selection predicatepublic boolean isRunning()
Simulation
is 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.
isRunning
in interface Simulation
public boolean pause()
Simulation
pause
in interface Simulation
public boolean pause(double time)
Simulation
pause
in interface Simulation
time
- the time at which the simulation has to be pausedpublic boolean resume()
Simulation
resume
in interface Simulation
public void pauseEntity(SimEntity src, double delay)
Simulation
pauseEntity
in interface Simulation
src
- id of entity to be pauseddelay
- the time period for which the entity will be inactiveprotected void holdEntity(SimEntity src, long delay)
src
- id of entity to be helddelay
- How many seconds after the current time the entity has to be heldpublic long getNumberOfFutureEvents(Predicate<SimEvent> predicate)
Simulation
getNumberOfFutureEvents
in interface Simulation
predicate
- the predicate to filter the list of future events.public boolean isThereAnyFutureEvt(Predicate<SimEvent> predicate)
Simulation
isThereAnyFutureEvt
in interface Simulation
predicate
- the predicate to selected the desired eventspublic boolean isTerminationTimeSet()
isTerminationTimeSet
in interface Simulation
public void abort()
Simulation
entities list
, which may give
unexpected results.
Use this method just if you want to abandon the simulation an usually ignore the results.
abort
in interface Simulation
public boolean isAborted()
Simulation
isAborted
in interface Simulation
public boolean isPaused()
Simulation
isPaused
in interface Simulation
public final Simulation addOnSimulationPauseListener(EventListener<EventInfo> listener)
Simulation
EventListener
object that will be notified when the simulation is paused.
When this Listener is notified, it will receive an EventInfo
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.
addOnSimulationPauseListener
in interface Simulation
listener
- the event listener to addpublic final Simulation addOnSimulationStartListener(EventListener<EventInfo> listener)
addOnSimulationStartListener
in interface Simulation
public boolean removeOnSimulationPauseListener(EventListener<EventInfo> listener)
Simulation
removeOnSimulationPauseListener
in interface Simulation
listener
- the listener to removepublic final Simulation addOnEventProcessingListener(EventListener<SimEvent> listener)
Simulation
EventListener
object that will be notified when any event
is processed by CloudSim. When this Listener is notified, it will receive
the SimEvent
that was processed.addOnEventProcessingListener
in interface Simulation
listener
- the event listener to addpublic boolean removeOnEventProcessingListener(EventListener<SimEvent> listener)
Simulation
removeOnEventProcessingListener
in interface Simulation
listener
- the listener to removepublic Simulation addOnClockTickListener(EventListener<EventInfo> listener)
Simulation
EventListener
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.addOnClockTickListener
in interface Simulation
listener
- the event listener to addpublic boolean removeOnClockTickListener(EventListener<? extends EventInfo> listener)
Simulation
removeOnClockTickListener
in interface Simulation
listener
- the listener to removepublic NetworkTopology getNetworkTopology()
Simulation
getNetworkTopology
in interface Simulation
public void setNetworkTopology(NetworkTopology networkTopology)
Simulation
setNetworkTopology
in interface Simulation
networkTopology
- the network topology to setpublic double getLastCloudletProcessingUpdate()
Simulation
getLastCloudletProcessingUpdate
in interface Simulation
public void setLastCloudletProcessingUpdate(double lastCloudletProcessingUpdate)
Simulation
setLastCloudletProcessingUpdate
in interface Simulation
lastCloudletProcessingUpdate
- the time to set (in seconds)public long getMaxEventsNumber()
FutureQueue
.public long getGeneratedEventsNumber()
FutureQueue
public boolean isAbortRequested()
isAbortRequested
in interface Simulation
abort()
Copyright © 2015–2021 Systems, Security and Image Communication Lab - Instituto de Telecomunicações (IT) - Universidade da Beira Interior (UBI) - Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO). All rights reserved.