Class SimEntity

java.lang.Object
simEngine.SimEntity
Direct Known Subclasses:
NetNode

public abstract class SimEntity extends Object
This class represents entities, or processes, running in the system. To create a new type of entity, it should be extended and a definition for the body() method given. The body() method is called by the SimSystem and defines the behaviour of the entity during the simulation.

Author:
Federico Granata
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    protected static final int
    State FINISHED: the entity has finished its behaviour.
    protected static final int
    State HOLDING: the entity has been caused to wait for a specified number of units of simulation time.
     
    protected static final int
    State RUNNING: the entity can be run by the simulation
    protected SimSystem
     
    protected int
     
    protected static final int
    State WAITING: the entity is waiting for an event.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The standard constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    The method which defines the behaviour of the entity.
    final SimEvent
     
    int
    Get the unique id number assigned to this entity
    Get the name of this entity
    Returns the Predicate which this entity is waiting for
    void
    Changes the state of the entity into FINISHED.
    abstract void
    Restarts the entity after an hold period
    void
     
    final int
    Cancel the first event waiting for this entity on the future queue, matched by the predicate p.
    final int
    Get the id of the currently running entity
    final void
    Get the first event from the deferred queue waiting on the entity, or, if there are none, wait for an event to arrive.
    final void
    Gets the first event matching a predicate from the deferred queue, or, if none match, wait for a matching event to arrive.
    final void
    simHold(double delay)
    Causes the entity to hold for delay units of simulation time.
    final double
    simHoldFor(double delay)
    An interruptible hold.
    Puts an event back on the deferred queue.
    simSchedule(int dest, double delay, int tag)
    Send an event to another entity, by id number and with no data.
    simSchedule(int dest, double delay, int tag, Object data)
    Send an event to another entity, by id number with data.
    final void
    Extract the first event waiting for this entity on the deferred queue, matched by the predicate p.
    final boolean
    Removes a scheduled event from future or deferred queue
    final void
    Hold until the entity receives an event.
    final void
    Repeatedly simWait() until the entity receives an event matched by the specified predicate, all the other received events are discarded.
    final int
    Count how many events are waiting for this entity on the deferred queue
    final int
    Count how many events matching a predicate are waiting for this entity on the deferred queue.
    abstract void
    Starts the activity of the SimEntity, call it the first time before calling execute.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • name

      public String name
    • evbuf

      public SimEvent evbuf
    • state

      protected int state
    • simSystem

      protected SimSystem simSystem
    • RUNNABLE

      protected static final int RUNNABLE
      State RUNNING: the entity can be run by the simulation
      See Also:
    • WAITING

      protected static final int WAITING
      State WAITING: the entity is waiting for an event.
      See Also:
    • HOLDING

      protected static final int HOLDING
      State HOLDING: the entity has been caused to wait for a specified number of units of simulation time.
      See Also:
    • FINISHED

      protected static final int FINISHED
      State FINISHED: the entity has finished its behaviour.
      See Also:
  • Constructor Details

    • SimEntity

      public SimEntity(String name)
      The standard constructor.
      Parameters:
      name - The name to be associated with this entity
  • Method Details

    • setSimSystem

      public void setSimSystem(SimSystem simSystem)
    • getName

      public String getName()
      Get the name of this entity
      Returns:
      The entity's name
    • getId

      public int getId()
      Get the unique id number assigned to this entity
      Returns:
      The id number
    • body

      protected abstract void body()
      The method which defines the behaviour of the entity. This method should be overridden in subclasses of SimEntity.
    • simHold

      public final void simHold(double delay)
      Causes the entity to hold for delay units of simulation time.
      Parameters:
      delay - The amount of time to hold
    • simHoldFor

      public final double simHoldFor(double delay)
      An interruptible hold. Causes the entity to hold for delay units of simulation time.
      Parameters:
      delay - The amount of time to hold
      Returns:
      The amount of time left on the hold (0.0 if no interruptions)
    • simSchedule

      public final RemoveToken simSchedule(int dest, double delay, int tag, Object data)
      Send an event to another entity, by id number with data.
      Parameters:
      dest - The unique id number of the destination entity
      delay - How long from the current simulation time the event should be sent
      tag - An user-defined number representing the type of event.
      data - A reference to data to be sent with the event.
      Returns:
      a token to remove scheduled message
    • simSchedule

      public final RemoveToken simSchedule(int dest, double delay, int tag)
      Send an event to another entity, by id number and with no data.
      Parameters:
      dest - The unique id number of the destination entity
      delay - How long from the current simulation time the event should be sent
      tag - An user-defined number representing the type of event.
      Returns:
      a token to remove scheduled message
    • simUnschedule

      public final boolean simUnschedule(RemoveToken token)
      Removes a scheduled event from future or deferred queue
      Parameters:
      token - the token to remove the element
      Returns:
      true if event was found and removed, false if it was not found
    • simWait

      public final void simWait()
      Hold until the entity receives an event.
    • simWaiting

      public final int simWaiting(SimPredicate p)
      Count how many events matching a predicate are waiting for this entity on the deferred queue.
      Parameters:
      p - The event selection predicate
      Returns:
      The count of matching events
    • simWaiting

      public final int simWaiting()
      Count how many events are waiting for this entity on the deferred queue
      Returns:
      The count of events
    • simSelect

      public final void simSelect(SimPredicate p)
      Extract the first event waiting for this entity on the deferred queue, matched by the predicate p.
      Parameters:
      p - An event selection predicate
    • simCancel

      public final int simCancel(SimPredicate p, SimEvent ev)
      Cancel the first event waiting for this entity on the future queue, matched by the predicate p. Returns the number of events cancelled (0 or 1).
      Parameters:
      p - An event selection predicate
      ev - The event matched is copied into ev if it points to a blank event, or discarded if ev is null
    • simWaitFor

      public final void simWaitFor(SimPredicate p)
      Repeatedly simWait() until the entity receives an event matched by the specified predicate, all the other received events are discarded.
      Parameters:
      p - The event selection predicate
    • simPutback

      public final RemoveToken simPutback(SimEvent ev)
      Puts an event back on the deferred queue.
      Parameters:
      ev - The event to reinsert
      Returns:
      a token to remove scheduled message
    • simGetNext

      public final void simGetNext(SimPredicate p)
      Gets the first event matching a predicate from the deferred queue, or, if none match, wait for a matching event to arrive.
      Parameters:
      p - The predicate to match
    • simGetNext

      public final void simGetNext()
      Get the first event from the deferred queue waiting on the entity, or, if there are none, wait for an event to arrive.
    • simCurrent

      public final int simCurrent()
      Get the id of the currently running entity
      Returns:
      A unique entity id number
    • getEvbuf

      public final SimEvent getEvbuf()
    • restart

      public abstract void restart()
      Restarts the entity after an hold period
    • poison

      public void poison()
      Changes the state of the entity into FINISHED.
    • start

      public abstract void start()
      Starts the activity of the SimEntity, call it the first time before calling execute.
    • getWaitingPred

      public final SimPredicate getWaitingPred()
      Returns the Predicate which this entity is waiting for
      Returns: