Class CloudSimEntity

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

public abstract class CloudSimEntity extends 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.cloudsimplus.core.SimEntity

    SimEntity.State
  • Field Summary

    Fields inherited from interface org.cloudsimplus.core.SimEntity

    NULL
  • Constructor Summary

    Constructors
    Constructor
    Description
    CloudSimEntity(@NonNull Simulation simulation)
    Creates a new entity.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    int
     
    Gets the first event waiting in the entity's deferred queue, or if there are none, wait for an event to arrive.
    Gets the first event matching a predicate from the deferred queue, or if none match, wait for a matching event to arrive.
    boolean
     
    boolean
     
    boolean
     
    void
    pause(double delay)
    Sets the entity to be inactive for a time period.
    void
    run()
    Starts 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, Object data)
    Sends an event from the entity to itself.
    boolean
    schedule(int tag, Object data)
    Sends an event from the entity to itself with no delay.
    boolean
    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, 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, 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, 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, Object data)
    Sends an event to another entity with no delay.
    Extracts the first event matching a predicate waiting in the entity's deferred queue.
    protected void
    send(SimEntity dest, double delay, int tag)
    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 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.
    protected void
    sendNow(SimEntity dest, int tag)
    Sends an event/message to another entity, with a tag representing the event type.
    protected void
    sendNow(SimEntity dest, int tag, Object data)
    Sends an event/message to another entity, with a tag representing the event type.
    protected void
    setEventBuffer(@NonNull SimEvent evt)
    Sets the event buffer.
    protected final void
    setId(int id)
    Sets the entity id and defines its name based on it.
    setName(@NonNull String name)
    Sets the Entity name.
    void
    Shuts down the entity.
    final boolean
    Starts the entity during simulation start.
    protected abstract void
    Defines the logic to be performed by the entity when the simulation starts.
    void
    Waits for an event matching a specific predicate.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.cloudsimplus.core.Identifiable

    getId

    Methods inherited from interface org.cloudsimplus.core.Nameable

    getName

    Methods inherited from interface org.cloudsimplus.core.SimEntity

    getShutdownTime, getSimulation, getStartTime, getState, processEvent, schedule, setState
  • Constructor Details

    • CloudSimEntity

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

    • start

      public final boolean start()
      Starts the entity during simulation start. This method is invoked by the CloudSimPlus class when the simulation is started.. It performs general initialization tasks that are common for every entity and executes the specific entity startup code.
      Specified by:
      start in interface SimEntity
      Returns:
      true if the entity started successfully; false if it was already started
    • shutdown

      public void shutdown()
      Description copied from interface: SimEntity
      Shuts down the entity. This method is invoked by CloudSimPlus before the simulation finishes. If you want to save data in log files, this is the method in which the corresponding code may 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, int 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, according to the CloudSimTag or some custom one.
      data - The data to be sent with the event, according to the tag
      Returns:
      true if the event was sent; false if the simulation was not started yet
    • schedule

      public boolean schedule(double delay, int 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, according to the CloudSimTag or some custom one.
      data - The data to be sent with the event, according to the tag
      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.
      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, according to the CloudSimTag or some custom one.
      Returns:
      true if the event was sent; false if the simulation was not started yet
    • schedule

      public boolean schedule(SimEntity dest, double delay, int 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, according to the CloudSimTag or some custom one.
      Returns:
      true if the event was sent; false if the simulation was not started yet
    • schedule

      public boolean schedule(int 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, according to the CloudSimTag or some custom one.
      data - The data to be sent with the event, according to the tag
      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, int 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, according to the CloudSimTag or some custom one.
      data - the data to be sent with the event, according to the tag
    • 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 - a tag representing the type of event, according to the CloudSimTag or some custom one.
    • 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 - a tag representing the type of event, according to the CloudSimTag or some custom one.
      data - The data to be sent with the event, according to the tag
    • 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 - a tag representing the type of event, according to the CloudSimTag or some custom one.
    • 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 - a tag representing the type of event, according to the CloudSimTag or some custom one.
    • 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 - a tag representing the type of event, according to the CloudSimTag or some custom one.
      data - The data to be sent with the event, according to the tag
    • 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
      Starts 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
    • run

      public void run(double until)
    • setName

      public SimEntity setName(@NonNull @NonNull 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:
      this entity instance
      Throws:
      IllegalArgumentException - when the entity name is null or empty
    • setId

      protected final void setId(int id)
      Sets the entity id and defines its name based on it.
      Parameters:
      id - the new id
    • setEventBuffer

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

      protected void send(SimEntity dest, double delay, int 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 the delay is a negative number, then it will be changed to 0
      tag - a tag representing the type of event, according to the CloudSimTag or some custom one.
      data - A reference to data to be sent with the event
    • send

      protected void send(SimEntity dest, double delay, int 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 the delay is a negative number, then it will be changed to 0
      tag - a tag representing the type of event, according to the CloudSimTag or some custom one
    • sendNow

      protected void sendNow(SimEntity dest, int tag, Object data)
      Sends an event/message to another entity, with a tag representing the event type.
      Parameters:
      dest - the destination entity
      tag - a tag representing the type of event, according to the CloudSimTag or some custom one
      data - the data to be sent with the event, according to the tag
    • sendNow

      protected void sendNow(SimEntity dest, int tag)
      Sends an event/message to another entity, with a tag representing the event type.
      Parameters:
      dest - the destination entity
      tag - a tag representing the type of event, according to the CloudSimTag or some custom one
    • isStarted

      public boolean isStarted()
      Specified by:
      isStarted in interface SimEntity
      Returns:
      true if the entity already was started, false otherwise.
    • isAlive

      public boolean isAlive()
      Specified by:
      isAlive in interface SimEntity
      Returns:
      true if the entity is alive, i.e, it's not finished; false otherwise.
    • isFinished

      public boolean isFinished()
      Specified by:
      isFinished in interface SimEntity
      Returns:
      true if the entity is finished, false otherwise.
    • compareTo

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