Package org.cloudbus.cloudsim.core
Class CloudSimEntity
java.lang.Object
org.cloudbus.cloudsim.core.CloudSimEntity
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<SimEntity>
,java.lang.Runnable
,Identifiable
,Nameable
,SimEntity
- Direct Known Subclasses:
AbstractSwitch
,CloudInformationService
,DatacenterBrokerAbstract
,DatacenterSimple
,HostFaultInjection
public abstract class CloudSimEntity extends java.lang.Object implements SimEntity
Represents a simulation entity. An entity handles events and can
send events to other entities.
- Since:
- CloudSim Toolkit 1.0
- Author:
- Marcos Dias de Assuncao
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cloudbus.cloudsim.core.SimEntity
SimEntity.State
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CloudSimEntity(Simulation simulation)
Creates a new entity. -
Method Summary
Modifier and Type Method Description SimEvent
cancelEvent(java.util.function.Predicate<SimEvent> predicate)
Cancels the first event from the future event queue that matches a given predicate and that was submitted by this entity, then removes it from the queue.protected java.lang.Object
clone()
Gets a clone of the entity.int
compareTo(SimEntity entity)
boolean
equals(java.lang.Object object)
long
getId()
Gets the unique id number assigned to this entity.java.lang.String
getName()
Gets the name of this entity.SimEvent
getNextEvent()
Gets the first event waiting in the entity's deferred queue, or if there are none, wait for an event to arrive.SimEvent
getNextEvent(java.util.function.Predicate<SimEvent> predicate)
Gets the first event matching a predicate from the deferred queue, or if none match, wait for a matching event to arrive.Simulation
getSimulation()
Gets the CloudSim instance that represents the simulation to each the Entity is related to.SimEntity.State
getState()
Gets the entity state.int
hashCode()
boolean
isAlive()
Checks if the entity is alive, i.e, it's not finished.boolean
isFinished()
Checks if the entity is finished or not.boolean
isStarted()
Checks if the entity already was started or not.void
pause(double delay)
Sets the entity to be inactive for a time period.void
run()
The run loop to process events fired during the simulation.void
run(double until)
boolean
schedule(double delay, int tag)
Sends an event from the entity to itself with no data.boolean
schedule(double delay, int tag, java.lang.Object data)
Sends an event from the entity to itself.boolean
schedule(int tag, java.lang.Object data)
Sends an event from the entity to itself with no delay.boolean
schedule(SimEvent evt)
Sends an event where all data required is defined inside the event instance.boolean
schedule(SimEntity dest, double delay, int tag)
Sends an event to another entity with no attached data.boolean
schedule(SimEntity dest, double delay, int tag, java.lang.Object data)
Sends an event to another entity.void
scheduleFirst(SimEntity dest, double delay, int tag)
Sends a high priority event to another entity and with no attached data.void
scheduleFirst(SimEntity dest, double delay, int tag, java.lang.Object data)
Sends a high priority event to another entity.void
scheduleFirstNow(SimEntity dest, int tag)
Sends a high priority event to another entity with no attached data and no delay.void
scheduleFirstNow(SimEntity dest, int tag, java.lang.Object data)
Sends a high priority event to another entity with no delay.void
scheduleNow(SimEntity dest, int tag)
Sends an event to another entity with no attached data and no delay.void
scheduleNow(SimEntity dest, int tag, java.lang.Object data)
Sends an event to another entity with no delay.SimEvent
selectEvent(java.util.function.Predicate<SimEvent> predicate)
Extracts the first event matching a predicate waiting in the entity's deferred queue.protected void
send(SimEntity dest, double delay, int cloudSimTag)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.protected void
send(SimEntity dest, double delay, int cloudSimTag, java.lang.Object data)
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.protected void
sendNow(SimEntity dest, int cloudSimTag)
Sends an event/message to another entity, with a tag representing the event type.protected void
sendNow(SimEntity dest, int cloudSimTag, java.lang.Object data)
Sends an event/message to another entity, with a tag representing the event type.protected void
setEventBuffer(SimEvent evt)
Sets the event buffer.protected void
setId(int id)
Sets the entity id and defines its name based on such ID.SimEntity
setName(java.lang.String name)
Sets the Entity name.SimEntity
setSimulation(Simulation simulation)
Sets the CloudSim instance that represents the simulation the Entity is related to.protected void
setStarted(boolean started)
Defines if the entity has already started or not.SimEntity
setState(SimEntity.State state)
Sets the entity state.void
shutdownEntity()
Shuts down the entity.void
start()
Starts the entity during simulation start.protected abstract void
startEntity()
Defines the logic to be performed by the entity when the simulation starts.void
waitForEvent(java.util.function.Predicate<SimEvent> predicate)
Waits for an event matching a specific predicate.
-
Constructor Details
-
CloudSimEntity
Creates a new entity.- Parameters:
simulation
- The CloudSim instance that represents the simulation the Entity is related to- Throws:
java.lang.IllegalArgumentException
- when the entity name is invalid
-
-
Method Details
-
getName
public java.lang.String getName()Gets the name of this entity. -
getId
public long getId()Gets the unique id number assigned to this entity.- Specified by:
getId
in interfaceIdentifiable
- Returns:
- The id number
-
start
public void start()Starts the entity during simulation start. This method is invoked by theCloudSim
class when the simulation is started.. It performs general initialization tasks that are common for every entity and executes the specific entity startup code by callingstartEntity()
.- Specified by:
start
in interfaceSimEntity
- See Also:
startEntity()
-
shutdownEntity
public void shutdownEntity()Description copied from interface:SimEntity
Shuts down the entity. This method is invoked by theCloudSim
before the simulation finishes. If you want to save data in log files this is the method in which the corresponding code would be placed.- Specified by:
shutdownEntity
in interfaceSimEntity
-
startEntity
protected abstract void startEntity()Defines the logic to be performed by the entity when the simulation starts. -
schedule
Description copied from interface:SimEntity
Sends an event to another entity.- Specified by:
schedule
in interfaceSimEntity
- Parameters:
dest
- the destination entitydelay
- How many seconds after the current simulation time the event should be senttag
- An user-defined number representing the type of event.data
- The data to be sent with the event.- Returns:
- true if the event was sent, false if the simulation was not started yet
-
schedule
public boolean schedule(double delay, int tag, java.lang.Object data)Description copied from interface:SimEntity
Sends an event from the entity to itself.- Specified by:
schedule
in interfaceSimEntity
- Parameters:
delay
- How many seconds after the current simulation time the event should be senttag
- An user-defined number representing the type of event.data
- The data to be sent with the event.- Returns:
- true if the event was sent, false if the simulation was not started yet
-
schedule
public boolean schedule(double delay, int tag)Description copied from interface:SimEntity
Sends an event from the entity to itself with no data. -
schedule
Description copied from interface:SimEntity
Sends an event to another entity with no attached data.- Specified by:
schedule
in interfaceSimEntity
- Parameters:
dest
- the destination entitydelay
- How many seconds after the current simulation time the event should be senttag
- An user-defined number representing the type of event.- Returns:
- true if the event was sent, false if the simulation was not started yet
-
schedule
public boolean schedule(int tag, java.lang.Object data)Description copied from interface:SimEntity
Sends an event from the entity to itself with no delay. -
schedule
Description copied from interface:SimEntity
Sends an event where all data required is defined inside the event instance. -
scheduleNow
Sends an event to another entity with no delay.- Parameters:
dest
- the destination entitytag
- An user-defined number representing the type of event.data
- The data to be sent with the event.
-
scheduleNow
Sends an event to another entity with no attached data and no delay.- Parameters:
dest
- the destination entitytag
- An user-defined number representing the type of event.
-
scheduleFirstNow
Sends a high priority event to another entity with no delay.- Parameters:
dest
- the destination entitytag
- An user-defined number representing the type of event.data
- The data to be sent with the event.
-
scheduleFirstNow
Sends a high priority event to another entity with no attached data and no delay.- Parameters:
dest
- the destination entitytag
- An user-defined number representing the type of event.
-
scheduleFirst
Sends a high priority event to another entity and with no attached data.- Parameters:
dest
- the destination entitydelay
- How many seconds after the current simulation time the event should be senttag
- An user-defined number representing the type of event.
-
scheduleFirst
Sends a high priority event to another entity.- Parameters:
dest
- the destination entitydelay
- How many seconds after the current simulation time the event should be senttag
- An user-defined number representing the type of event.data
- The data to be sent with the event.
-
pause
public void pause(double delay)Sets the entity to be inactive for a time period.- Parameters:
delay
- the time period for which the entity will be inactive
-
selectEvent
Extracts the first event matching a predicate waiting in the entity's deferred queue.- Parameters:
predicate
- The event selection predicate- Returns:
- the simulation event; or
SimEvent.NULL
if not found or the simulation is not running
-
cancelEvent
Cancels the first event from the future event queue that matches a given predicate and that was submitted by this entity, then removes it from the queue.- Parameters:
predicate
- the event selection predicate- Returns:
- the removed event or
SimEvent.NULL
if not found
-
getNextEvent
Gets the first event matching a predicate from the deferred queue, or if none match, wait for a matching event to arrive.- Parameters:
predicate
- The predicate to match- Returns:
- the simulation event; or
SimEvent.NULL
if not found or the simulation is not running
-
getNextEvent
Gets the first event waiting in the entity's deferred queue, or if there are none, wait for an event to arrive.- Returns:
- the simulation event; or
SimEvent.NULL
if not found or the simulation is not running
-
waitForEvent
Waits for an event matching a specific predicate. This method does not check the entity's deferred queue.- Parameters:
predicate
- The predicate to match
-
run
public void run()Description copied from interface:SimEntity
The run loop to process events fired during the simulation. The events that will be processed are defined in theSimEntity.processEvent(SimEvent)
method.- Specified by:
run
in interfacejava.lang.Runnable
- Specified by:
run
in interfaceSimEntity
- See Also:
SimEntity.processEvent(SimEvent)
-
run
public void run(double until) -
clone
protected final java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionGets a clone of the entity. This is used when independent replications have been specified as an output analysis method. Clones or backups of the entities are made in the beginning of the simulation in order to reset the entities for each subsequent replication. This method should not be called by the user.- Overrides:
clone
in classjava.lang.Object
- Returns:
- A clone of the entity
- Throws:
java.lang.CloneNotSupportedException
- when the entity doesn't support cloning
-
getSimulation
Description copied from interface:SimEntity
Gets the CloudSim instance that represents the simulation to each the Entity is related to.- Specified by:
getSimulation
in interfaceSimEntity
- Returns:
-
setSimulation
Description copied from interface:SimEntity
Sets the CloudSim instance that represents the simulation the Entity is related to.- Specified by:
setSimulation
in interfaceSimEntity
- Parameters:
simulation
- The CloudSim instance that represents the simulation the Entity is related to- Returns:
-
setName
Description copied from interface:SimEntity
Sets the Entity name. -
getState
Description copied from interface:SimEntity
Gets the entity state. -
setState
Sets the entity state. -
setId
protected final void setId(int id)Sets the entity id and defines its name based on such ID.- Parameters:
id
- the new id
-
setEventBuffer
Sets the event buffer.- Parameters:
evt
- the new event buffer
-
send
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.- Parameters:
dest
- the destination entitydelay
- How many seconds after the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0cloudSimTag
- an user-defined number representing the type of an event/messagedata
- A reference to data to be sent with the event
-
send
Sends an event/message to another entity by delaying the simulation time from the current time, with a tag representing the event type.- Parameters:
dest
- the destination entitydelay
- How many seconds after the current simulation time the event should be sent. If delay is a negative number, then it will be changed to 0cloudSimTag
- an user-defined number representing the type of an event/message
-
sendNow
Sends an event/message to another entity, with a tag representing the event type.- Parameters:
dest
- the destination entitycloudSimTag
- an user-defined number representing the type of an event/messagedata
- A reference to data to be sent with the event
-
sendNow
Sends an event/message to another entity, with a tag representing the event type.- Parameters:
dest
- the destination entitycloudSimTag
- an user-defined number representing the type of an event/message
-
isStarted
public boolean isStarted()Description copied from interface:SimEntity
Checks if the entity already was started or not. -
isAlive
public boolean isAlive()Description copied from interface:SimEntity
Checks if the entity is alive, i.e, it's not finished. -
isFinished
public boolean isFinished()Description copied from interface:SimEntity
Checks if the entity is finished or not.- Specified by:
isFinished
in interfaceSimEntity
- Returns:
-
setStarted
protected void setStarted(boolean started)Defines if the entity has already started or not.- Parameters:
started
- the start state to set
-
compareTo
- Specified by:
compareTo
in interfacejava.lang.Comparable<SimEntity>
-
equals
public boolean equals(java.lang.Object object)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-