CloudSimEntity

public abstract class CloudSimEntity implements SimEntity

Represents a simulation entity. An entity handles events and can send events to other entities.

Author:Marcos Dias de Assuncao

Constructors

CloudSimEntity

public CloudSimEntity(Simulation simulation)

Creates a new entity.

Parameters:
  • simulation – The CloudSim instance that represents the simulation the Entity is related to
Throws:
  • IllegalArgumentException – when the entity name is invalid

Methods

cancelEvent

public SimEvent cancelEvent(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.

Parameters:
  • predicate – the event selection predicate
Returns:

the removed event or SimEvent.NULL if not found

clone

protected final Object clone()

Gets 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.

Throws:
Returns:

A clone of the entity

compareTo

public int compareTo(SimEntity entity)

equals

public boolean equals(Object object)

getId

public long getId()

Gets the unique id number assigned to this entity.

Returns:The id number

getName

public String getName()

Gets the name of this entity.

Returns:The entity’s name

getNextEvent

public SimEvent getNextEvent(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.

Parameters:
  • predicate – The predicate to match
Returns:

the simulation event

getNextEvent

public SimEvent 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

getSimulation

public Simulation getSimulation()

getState

public State getState()

hashCode

public int hashCode()

isAlive

public boolean isAlive()

isFinished

public boolean isFinished()

isStarted

public boolean isStarted()

numEventsWaiting

public long numEventsWaiting(Predicate<SimEvent> predicate)

Counts how many events matching a predicate are waiting in the entity’s deferred queue.

Parameters:
  • predicate – The event selection predicate
Returns:

The count of matching events

numEventsWaiting

public long numEventsWaiting()

Counts how many events are waiting in the entity’s deferred queue.

Returns:The count of events

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

run

public void run()

schedule

public boolean schedule(SimEntity dest, double delay, int tag, Object data)

schedule

public boolean schedule(double delay, int tag, Object data)

schedule

public boolean schedule(SimEntity dest, double delay, int tag)

schedule

public boolean schedule(SimEvent evt)

scheduleFirst

public void scheduleFirst(SimEntity dest, double delay, int tag)

Sends a high priority event to another entity and with no attached data.

Parameters:
  • dest – the destination entity
  • delay – How many seconds after the current simulation time the event should be sent
  • tag – An user-defined number representing the type of event.

scheduleFirst

public void scheduleFirst(SimEntity dest, double delay, int tag, Object data)

Sends a high priority event to another entity.

Parameters:
  • dest – the destination entity
  • delay – How many seconds after the current simulation time the event should be sent
  • tag – An user-defined number representing the type of event.
  • data – The data to be sent with the event.

scheduleFirstNow

public void scheduleFirstNow(SimEntity dest, int tag, Object data)

Sends a high priority event to another entity with no delay.

Parameters:
  • dest – the destination entity
  • tag – An user-defined number representing the type of event.
  • data – The data to be sent with the event.

scheduleFirstNow

public void scheduleFirstNow(SimEntity dest, int tag)

Sends a high priority event to another entity with no attached data and no delay.

Parameters:
  • dest – the destination entity
  • tag – An user-defined number representing the type of event.

scheduleNow

public void scheduleNow(SimEntity dest, int tag, Object data)

Sends an event to another entity with no delay.

Parameters:
  • dest – the destination entity
  • tag – An user-defined number representing the type of event.
  • data – The data to be sent with the event.

scheduleNow

public void scheduleNow(SimEntity dest, int tag)

Sends an event to another entity with no attached data and no delay.

Parameters:
  • dest – the destination entity
  • tag – An user-defined number representing the type of event.

selectEvent

public SimEvent selectEvent(Predicate<SimEvent> predicate)

Extracts the first event matching a predicate waiting in the entity’s deferred queue.

Parameters:
  • predicate – The event selection predicate
Returns:

the simulation event

send

protected void send(SimEntity dest, double delay, int cloudSimTag, 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.

Parameters:
  • dest – the destination entity
  • delay – 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 0
  • cloudSimTag – an user-defined number representing the type of an event/message
  • data – A reference to data to be sent with the event

send

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.

Parameters:
  • dest – the destination entity
  • delay – 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 0
  • cloudSimTag – an user-defined number representing the type of an event/message

sendNow

protected void sendNow(SimEntity dest, int cloudSimTag, Object data)

Sends an event/message to another entity, with a tag representing the event type.

Parameters:
  • dest – the destination entity
  • cloudSimTag – an user-defined number representing the type of an event/message
  • data – A reference to data to be sent with the event

sendNow

protected void sendNow(SimEntity dest, int cloudSimTag)

Sends an event/message to another entity, with a tag representing the event type.

Parameters:
  • dest – the destination entity
  • cloudSimTag – an user-defined number representing the type of an event/message

setEventBuffer

protected void setEventBuffer(SimEvent evt)

Sets the event buffer.

Parameters:
  • evt – the new event buffer

setId

protected final void setId(int id)

Sets the entity id and defines its name based on such ID.

Parameters:
  • id – the new id

setName

public SimEntity setName(String name)

setSimulation

public final SimEntity setSimulation(Simulation simulation)

setStarted

protected void setStarted(boolean started)

Defines if the entity has already started or not.

Parameters:
  • started – the start state to set

setState

public SimEntity setState(State state)

Sets the entity state.

Parameters:
  • state – the new state

shutdownEntity

public void shutdownEntity()

start

public void start()

{@inheritDoc}. It performs general initialization tasks that are common for every entity and executes the specific entity startup code by calling startEntity().

See also: .startEntity()

startEntity

protected abstract void startEntity()

Defines the logic to be performed by the entity when the simulation starts.

waitForEvent

public void waitForEvent(Predicate<SimEvent> predicate)

Waits for an event matching a specific predicate. This method does not check the entity’s deferred queue.

Parameters:
  • predicate – The predicate to match