Class CloudSimEntity

java.lang.Object
org.cloudbus.cloudsim.core.CloudSimEntity
All Implemented Interfaces:
Cloneable, Comparable<SimEntity>, Runnable, Identifiable, Nameable, SimEntity
Direct Known Subclasses:
AbstractSwitch, CloudInformationService, DatacenterBrokerAbstract, DatacenterSimple, HostFaultInjection, PowerMeter

public abstract class CloudSimEntity extends Object implements SimEntity, Cloneable
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
  • Constructor Details

    • CloudSimEntity

      public CloudSimEntity(Simulation simulation)
      Creates a new entity.
      Parameters:
      simulation - The CloudSim instance that represents the simulation the Entity belongs to
      Throws:
      IllegalArgumentException - when the entity name is invalid
  • Method Details

    • getName

      public String getName()
      Gets the name of this entity.
      Specified by:
      getName in interface Nameable
      Returns:
      the entity's name
    • getId

      public long getId()
      Gets the unique id number assigned to this entity.
      Specified by:
      getId in interface Identifiable
      Returns:
      the id number
    • start

      public final boolean start()
      Starts the entity during simulation start. This method is invoked by the CloudSim 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 calling startInternal().
      Specified by:
      start in interface SimEntity
      Returns:
      true if the entity started successfully; false if it was already started
      See Also:
    • shutdown

      public void shutdown()
      Description copied from interface: SimEntity
      Shuts down the entity. This method is invoked by the CloudSim 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:
      shutdown in interface SimEntity
    • startInternal

      protected abstract void startInternal()
      Defines the logic to be performed by the entity when the simulation starts.
    • schedule

      public boolean schedule(SimEntity dest, double delay, CloudSimTag tag, Object data)
      Description copied from interface: SimEntity
      Sends an event to another entity.
      Specified by:
      schedule in interface SimEntity
      Parameters:
      dest - the destination entity
      delay - How many seconds after the current simulation time the event should be sent
      tag - a tag 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, CloudSimTag tag, Object data)
      Description copied from interface: SimEntity
      Sends an event from the entity to itself.
      Specified by:
      schedule in interface SimEntity
      Parameters:
      delay - How many seconds after the current simulation time the event should be sent
      tag - a tag 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, CloudSimTag tag)
      Description copied from interface: SimEntity
      Sends an event from the entity to itself with no data.
      Specified by:
      schedule in interface SimEntity
      Parameters:
      delay - How many seconds after the current simulation time the event should be sent
      tag - a tag representing the type of event.
      Returns:
      true if the event was sent; false if the simulation was not started yet
    • schedule

      public boolean schedule(SimEntity dest, double delay, CloudSimTag tag)
      Description copied from interface: SimEntity
      Sends an event to another entity with no attached data.
      Specified by:
      schedule in interface SimEntity
      Parameters:
      dest - the destination entity
      delay - How many seconds after the current simulation time the event should be sent
      tag - a tag representing the type of event.
      Returns:
      true if the event was sent; false if the simulation was not started yet
    • schedule

      public boolean schedule(CloudSimTag tag, Object data)
      Description copied from interface: SimEntity
      Sends an event from the entity to itself with no delay.
      Specified by:
      schedule in interface SimEntity
      Parameters:
      tag - a tag 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(SimEvent evt)
      Description copied from interface: SimEntity
      Sends an event where all data required is defined inside the event instance.
      Specified by:
      schedule in interface SimEntity
      Parameters:
      evt - the event to send
      Returns:
      true if the event was sent; false if the simulation was not started yet
    • scheduleNow

      public void scheduleNow(SimEntity dest, CloudSimTag tag, Object data)
      Sends an event to another entity with no delay.
      Parameters:
      dest - the destination entity
      tag - a tag representing the type of event.
      data - The data to be sent with the event.
    • scheduleNow

      public void scheduleNow(SimEntity dest, CloudSimTag tag)
      Sends an event to another entity with no attached data and no delay.
      Parameters:
      dest - the destination entity
      tag - a user-defined number representing the type of event.
    • scheduleFirstNow

      public void scheduleFirstNow(SimEntity dest, CloudSimTag tag, Object data)
      Sends a high priority event to another entity with no delay.
      Parameters:
      dest - the destination entity
      tag - a tag representing the type of event.
      data - The data to be sent with the event.
    • scheduleFirstNow

      public void scheduleFirstNow(SimEntity dest, CloudSimTag tag)
      Sends a high priority event to another entity with no attached data and no delay.
      Parameters:
      dest - the destination entity
      tag - a user-defined number representing the type of event.
    • scheduleFirst

      public void scheduleFirst(SimEntity dest, double delay, CloudSimTag 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 - a user-defined number representing the type of event.
    • scheduleFirst

      public void scheduleFirst(SimEntity dest, double delay, CloudSimTag 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 - a 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

      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; or SimEvent.NULL if not found or the simulation is not running
    • 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
    • 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; or SimEvent.NULL if not found or the simulation is not running
    • 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; or SimEvent.NULL if not found or the simulation is not running
    • 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
    • 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 the SimEntity.processEvent(SimEvent) method.
      Specified by:
      run in interface Runnable
      Specified by:
      run in interface SimEntity
      See Also:
    • run

      public void run(double until)
    • clone

      public final CloudSimEntity clone() throws CloneNotSupportedException
      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.
      Overrides:
      clone in class Object
      Returns:
      A clone of the entity
      Throws:
      CloneNotSupportedException - when the entity doesn't support cloning
    • getSimulation

      public Simulation getSimulation()
      Description copied from interface: SimEntity
      Gets the CloudSim instance that represents the simulation to each the Entity belongs to.
      Specified by:
      getSimulation in interface SimEntity
      Returns:
    • setSimulation

      public final SimEntity setSimulation(Simulation simulation)
      Description copied from interface: SimEntity
      Sets the CloudSim instance that represents the simulation the Entity belongs to.
      Specified by:
      setSimulation in interface SimEntity
      Parameters:
      simulation - The simulation instance the Entity is related to
      Returns:
    • setName

      public SimEntity setName(String name) throws IllegalArgumentException
      Description copied from interface: SimEntity
      Sets the Entity name.
      Specified by:
      setName in interface SimEntity
      Parameters:
      name - the new name
      Returns:
      Throws:
      IllegalArgumentException - when the entity name is null or empty
    • getState

      public SimEntity.State getState()
      Description copied from interface: SimEntity
      Gets the entity state.
      Specified by:
      getState in interface SimEntity
      Returns:
      the state
    • setState

      public SimEntity setState(SimEntity.State state)
      Sets the entity state.
      Specified by:
      setState in interface SimEntity
      Parameters:
      state - the new 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

      protected void setEventBuffer(SimEvent evt)
      Sets the event buffer.
      Parameters:
      evt - the new event buffer
    • send

      protected void send(SimEntity dest, double delay, CloudSimTag tag, 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
      tag - a 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, CloudSimTag tag)
      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
      tag - a user-defined number representing the type of an
    • sendNow

      protected void sendNow(SimEntity dest, CloudSimTag tag, Object data)
      Sends an event/message to another entity, with a tag representing the event type.
      Parameters:
      dest - the destination entity
      tag - a 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, CloudSimTag tag)
      Sends an event/message to another entity, with a tag representing the event type.
      Parameters:
      dest - the destination entity
      tag - a user-defined number representing the event/message type
    • isStarted

      public boolean isStarted()
      Description copied from interface: SimEntity
      Checks if the entity already was started or not.
      Specified by:
      isStarted in interface SimEntity
      Returns:
    • isAlive

      public boolean isAlive()
      Description copied from interface: SimEntity
      Checks if the entity is alive, i.e, it's not finished.
      Specified by:
      isAlive in interface SimEntity
      Returns:
    • isFinished

      public boolean isFinished()
      Description copied from interface: SimEntity
      Checks if the entity is finished or not.
      Specified by:
      isFinished in interface SimEntity
      Returns:
    • compareTo

      public int compareTo(SimEntity entity)
      Specified by:
      compareTo in interface Comparable<SimEntity>
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getShutdownTime

      public double getShutdownTime()
      Description copied from interface: SimEntity
      Gets the time the entity was shutdown (in seconds). If the entity SimEntity.isAlive() yet, the method returns -1.
      Specified by:
      getShutdownTime in interface SimEntity
      Returns:
    • getStartTime

      public double getStartTime()
      Description copied from interface: SimEntity
      Gets the time the entity was started.
      Specified by:
      getStartTime in interface SimEntity
      Returns:
      the entity start time or -1 if it haven't started yet.