Class AbstractPort

java.lang.Object
org.simplesim.core.messaging.AbstractPort
All Implemented Interfaces:
Port
Direct Known Subclasses:
MultiPort, SinglePort, SwitchPort

public abstract class AbstractPort extends Object implements Port
Ports are used to send messages within a model.

In the phase of model building, ports are connected with each others via the connectTo method. The sending entity puts a Message on its outport. The message is then routed along the established connections. A port that has no further connection is always an end-point (destination of delivery). Thus, connections are always directed from source outport to destination inport.

Each port must also implement its own copyMessages strategy to support message forwarding during the simulation run.

See Also:
  • Constructor Details

    • AbstractPort

      public AbstractPort(ModelEntity model)
  • Method Details

    • clearMessages

      public final void clearMessages()
      Description copied from interface: Port
      Clears message queue of this port.
      Specified by:
      clearMessages in interface Port
    • countMessages

      public final int countMessages()
      Description copied from interface: Port
      Counts messages in queue of this port.
      Specified by:
      countMessages in interface Port
      Returns:
      number of messages, can be zero
    • hasMessages

      public final boolean hasMessages()
      Description copied from interface: Port
      Checks if the port has messages.
      Specified by:
      hasMessages in interface Port
      Returns:
      true if there are messages
    • poll

      public final <M extends AbstractMessage<?>> M poll()
      Description copied from interface: Port
      Returns and removes the last element in the message queue.
      Specified by:
      poll in interface Port
      Returns:
      last element in message list or null if list is empty
    • readAll

      public final <M extends AbstractMessage<?>> Collection<M> readAll()
      Description copied from interface: Port
      Returns the message queue.

      Elements must be removed manually by calling the Port.clearMessages() method

      Specified by:
      readAll in interface Port
      Returns:
      the message queue
    • write

      public final void write(AbstractMessage<?> message)
      Description copied from interface: Port
      Puts a message to be forwarded on this port.
      Specified by:
      write in interface Port
      Parameters:
      message - the message
    • writeAll

      public final void writeAll(Collection<AbstractMessage<?>> m)
      Description copied from interface: Port
      Puts several messages to be forwarded on this port.
      Specified by:
      writeAll in interface Port
      Parameters:
      m - collection of messages
    • getParent

      public final ModelEntity getParent()
      Specified by:
      getParent in interface Port
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object