Interface Simulation

All Known Implementing Classes:
CloudSim

public interface Simulation
An interface to be implemented by a class that manages simulation execution, controlling all the simulation life cycle.
Since:
CloudSim Plus 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
See Also:
  • Field Details

    • ANY_EVT

      static final Predicate<SimEvent> ANY_EVT
      A standard predicate that matches any event.
    • NULL

      static final Simulation NULL
      An attribute that implements the Null Object Design Pattern for Simulation objects.
  • Method Details

    • setIdForEntitiesWithoutOne

      static <T extends ChangeableId> T setIdForEntitiesWithoutOne(List<? extends T> list)
      Defines IDs for a list of ChangeableId entities that don't have one already assigned. Such entities can be a Cloudlet, Vm or any object that implements ChangeableId.
      Type Parameters:
      T - the type of entities to define an ID
      Parameters:
      list - list of objects to define an ID
      Returns:
      the last entity that had an id set
    • setIdForEntitiesWithoutOne

      static <T extends ChangeableId> T setIdForEntitiesWithoutOne(List<? extends T> list, T lastEntity)
      Defines IDs for a list of ChangeableId entities that don't have one already assigned. Such entities can be a Cloudlet, Vm or any object that implements ChangeableId.
      Type Parameters:
      T - the type of entities to define an ID
      Parameters:
      list - list of objects to define an ID
      lastEntity - the last created Entity which its ID will be used as the base for the next IDs
      Returns:
      the last entity that had an id set
    • isTerminationTimeSet

      boolean isTerminationTimeSet()
    • abort

      void abort()
      Aborts the simulation without finishing the processing of entities in the entities list, which may give unexpected results.

      Use this method just if you want to abandon the simulation an usually ignore the results.

    • isAborted

      boolean isAborted()
      Check if the simulation has been aborted.
      Returns:
    • addEntity

      void addEntity(CloudSimEntity entity)
      Adds a new entity to the simulation. Each CloudSimEntity object register itself when it is instantiated.
      Parameters:
      entity - The new entity
    • cancel

      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.
      Parameters:
      src - Id of entity that scheduled the event
      predicate - the event selection predicate
      Returns:
      the removed event or SimEvent.NULL if not found
    • cancelAll

      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.
      Parameters:
      src - id of entity that scheduled the event
      predicate - the event selection predicate
      Returns:
      true if at least one event has been cancelled; false otherwise
    • clock

      double clock()
      Gets the current simulation time in seconds.
      Returns:
      See Also:
    • clockStr

      String clockStr()
      Gets the current simulation time in seconds as a formatted String.
      Returns:
      See Also:
    • clockInMinutes

      double clockInMinutes()
      Gets the current simulation time in minutes.
      Returns:
      See Also:
    • clockInHours

      double clockInHours()
      Gets the current simulation time in hours.
      Returns:
      See Also:
    • findFirstDeferred

      SimEvent findFirstDeferred(SimEntity dest, Predicate<SimEvent> predicate)
      Find first deferred event matching a predicate.
      Parameters:
      dest - id of entity that the event has to be sent to
      predicate - the event selection predicate
      Returns:
      the first matched event or SimEvent.NULL if not found
    • getCalendar

      Calendar getCalendar()
      Gets a new copy of initial simulation Calendar.
      Returns:
      a new copy of Calendar object
    • getCloudInfoService

      CloudInformationService getCloudInfoService()
      Returns:
      the Entity
    • getEntityList

      List<SimEntity> getEntityList()
      Returns a read-only list of entities created for the simulation.
      Returns:
    • getMinTimeBetweenEvents

      double getMinTimeBetweenEvents()
      Gets the minimum time between events (in seconds). Events within shorter periods after the last event are discarded.
      Returns:
      the minimum time between events (in seconds).
    • getNumEntities

      int getNumEntities()
      Get the current number of entities in the simulation.
      Returns:
      The number of entities
    • removeOnEventProcessingListener

      boolean removeOnEventProcessingListener(EventListener<SimEvent> listener)
      Removes a listener from the onEventProcessingListener List.
      Parameters:
      listener - the listener to remove
      Returns:
      true if the listener was found and removed, false otherwise
    • addOnSimulationPauseListener

      Simulation addOnSimulationPauseListener(EventListener<EventInfo> listener)
      Adds an 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.

      Parameters:
      listener - the event listener to add
      Returns:
    • addOnSimulationStartListener

      Simulation addOnSimulationStartListener(EventListener<EventInfo> listener)
    • removeOnSimulationPauseListener

      boolean removeOnSimulationPauseListener(EventListener<EventInfo> listener)
      Removes a listener from the onSimulationPausedListener List.
      Parameters:
      listener - the listener to remove
      Returns:
      true if the listener was found and removed, false otherwise
    • addOnEventProcessingListener

      Simulation addOnEventProcessingListener(EventListener<SimEvent> listener)
      Adds a 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.
      Parameters:
      listener - the event listener to add
      Returns:
    • addOnClockTickListener

      Simulation addOnClockTickListener(EventListener<EventInfo> listener)
      Adds a 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.
      Parameters:
      listener - the event listener to add
      Returns:
    • removeOnClockTickListener

      boolean removeOnClockTickListener(EventListener<? extends EventInfo> listener)
      Removes a listener from the onClockTickListener List.
      Parameters:
      listener - the listener to remove
      Returns:
      true if the listener was found and removed, false otherwise
    • pauseEntity

      void pauseEntity(SimEntity src, double delay)
      Pauses an entity for some time.
      Parameters:
      src - id of entity to be paused
      delay - the time period for which the entity will be inactive
    • isPaused

      boolean isPaused()
      Checks if the simulation is paused.
      Returns:
    • pause

      boolean pause()
      Requests the simulation to be paused as soon as possible.
      Returns:
      true if the simulation was paused, false if it was already paused or has finished
    • pause

      boolean pause(double time)
      Requests the simulation to be paused at a given time. The method schedules the pause request and then returns immediately.
      Parameters:
      time - the time at which the simulation has to be paused
      Returns:
      true if pause request was successfully received (the given time is greater than or equal to the current simulation time), false otherwise.
    • resume

      boolean resume()
      Resumes the simulation if it has previously been paused.
      Returns:
      true if the simulation has been restarted or false if it wasn't paused before.
    • isRunning

      boolean isRunning()
      Check if the simulation is still running. Even if the 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.

      Returns:
    • select

      SimEvent select(SimEntity dest, Predicate<SimEvent> predicate)
      Selects the first deferred event that matches a given predicate and removes it from the queue.
      Parameters:
      dest - entity that the event has to be sent to
      predicate - the event selection predicate
      Returns:
      the removed event or SimEvent.NULL if not found
    • send

      void send(SimEvent evt)
      Sends an event where all data required is defined inside the event instance.
      Parameters:
      evt - the event to send
    • send

      void send(SimEntity src, SimEntity dest, double delay, CloudSimTag tag, Object data)
      Sends an event from one entity to another.
      Parameters:
      src - entity that scheduled the event
      dest - entity that the event will be sent to
      delay - How many seconds after the current simulation time the event should be sent
      tag - the tag that classifies the event
      data - the data to be sent inside the event
    • sendFirst

      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.
      Parameters:
      evt - the event to send
    • sendFirst

      void sendFirst(SimEntity src, SimEntity dest, double delay, CloudSimTag 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.
      Parameters:
      src - entity that scheduled the event
      dest - entity that the event will be sent to
      delay - How many seconds after the current simulation time the event should be sent
      tag - the tag that classifies the event
      data - the data to be sent inside the event
    • sendNow

      void sendNow(SimEntity src, SimEntity dest, CloudSimTag tag, Object data)
      Sends an event from one entity to another without delaying the message.
      Parameters:
      src - entity that scheduled the event
      dest - entity that the event will be sent to
      tag - the tag that classifies the event
      data - the data to be sent inside the event
    • runFor

      double runFor(double interval)
      Runs the simulation for a specific period of time and then immediately returns. In order to complete the whole simulation you need to invoke this method multiple times Note: Should be used only in the synchronous mode (after starting the simulation with startSync()).
      Parameters:
      interval - The interval for which the simulation should be run (in seconds)
      Returns:
      Clock at the end of simulation interval (in seconds)
    • start

      double start()
      Starts simulation execution and waits for all entities to finish, i.e. until all entities threads reach non-RUNNABLE state or there are no more events in the future event queue.

      Note: This method should be called only after all the entities have been setup and added. The method blocks until the simulation is ended.

      Returns:
      the last clock time
      Throws:
      UnsupportedOperationException - When the simulation has already run once. If you paused the simulation and wants to resume it, you must use resume() instead of calling the current method.
      See Also:
    • startSync

      void startSync()
      Starts simulation execution in synchronous mode, retuning immediately. You need to call runFor(double) method subsequently to actually process simulation steps. Note: This method should be called only after all entities have been set up and added. The method returns immediately after preparing the internal state of the simulation.

      Throws:
      UnsupportedOperationException - When the simulation has already run once. If you paused the simulation and wants to resume it, you must use resume() instead of calling the current method.
      See Also:
    • isTimeToTerminateSimulationUnderRequest

      boolean isTimeToTerminateSimulationUnderRequest()
    • terminate

      boolean terminate()
      Forces the termination of the simulation before it ends.
      Returns:
      true if the simulation was running and the termination request was accepted, false if the simulation was not started yet
    • terminateAt

      boolean terminateAt(double time)
      Schedules the termination of the simulation for a given time (in seconds).

      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:

      Parameters:
      time - the time at which the simulation has to be terminated (in seconds)
      Returns:
      true if the time given is greater than the current simulation time, false otherwise
    • wait

      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. Only such events will be passed to the entity. This is done to avoid unnecessary context switch.
      Parameters:
      src - entity that scheduled the event
      predicate - the event selection predicate
    • getNetworkTopology

      NetworkTopology getNetworkTopology()
      Gets the network topology used for Network simulations.
      Returns:
    • setNetworkTopology

      void setNetworkTopology(NetworkTopology networkTopology)
      Sets the network topology used for Network simulations.
      Parameters:
      networkTopology - the network topology to set
    • getNumberOfFutureEvents

      long getNumberOfFutureEvents(Predicate<SimEvent> predicate)
      Gets the number of events in the future queue which match a given predicate.
      Parameters:
      predicate - the predicate to filter the list of future events.
      Returns:
      the number of future events which match the predicate
    • isThereAnyFutureEvt

      boolean isThereAnyFutureEvt(Predicate<SimEvent> predicate)
      Checks if there is any event in the future queue that matches a given predicate.
      Parameters:
      predicate - the predicate to selected the desired events
      Returns:
      true if any event matching the given predicate is found, false otherwise
    • getLastCloudletProcessingUpdate

      double getLastCloudletProcessingUpdate()
      Gets the last time (in seconds) some Cloudlet was processed in the simulation.
    • setLastCloudletProcessingUpdate

      void setLastCloudletProcessingUpdate(double lastCloudletProcessingUpdate)
      Sets the last time (in seconds) some Cloudlet was processed in the simulation.
      Parameters:
      lastCloudletProcessingUpdate - the time to set (in seconds)
    • isAbortRequested

      boolean isAbortRequested()
      Checks if a request to abort the simulation was already sent.
      Returns: