Interface Port

All Known Implementing Classes:
AbstractPort, MultiPort, SinglePort, SwitchPort

public interface Port
Ports are used to send messages within the simulation 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 outport (source) to inport (destination).

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

See Also:
  • Method Details

    • connect

      void connect(Port target)
      Connects this port to another one.

      Note that connections are directed.

      Parameters:
      target - the other part of the connection
    • disconnect

      void disconnect(Port target)
      Disconnects this port from another one.
      Parameters:
      target - the port to be removed
      Throws:
      ModelEntity.PortConnectionException - if the port is not connected with the target or the simulation is running
    • isEndPoint

      boolean isEndPoint()
      Tests if the port is the end point of a connection.
      Returns:
      true if it is end point (destination port)
    • isConnectedTo

      boolean isConnectedTo(Port port)
      Tests if the port is connected to another one.
      Parameters:
      port - the port to test
      Returns:
      true if this port is connected to the other port
    • forwardMessages

      Collection<Port> forwardMessages()
      Implements a message forwarding strategy specific for the port class.

      Port must be connected to other ports, please check if it is an end point beforehand!

      Note: Only to be used by an implementation of MessageForwardingStrategy

      Returns:
      list of destination ports that need further forwarding
    • clearMessages

      void clearMessages()
      Clears message queue of this port.
    • countMessages

      int countMessages()
      Counts messages in queue of this port.
      Returns:
      number of messages, can be zero
    • hasMessages

      boolean hasMessages()
      Checks if the port has messages.
      Returns:
      true if there are messages
    • poll

      <M extends AbstractMessage<?>> M poll()
      Returns and removes the last element in the message queue.
      Returns:
      last element in message list or null if list is empty
    • readAll

      <M extends AbstractMessage<?>> Collection<M> readAll()
      Returns the message queue.

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

      Returns:
      the message queue
    • write

      void write(AbstractMessage<?> msg)
      Puts a message to be forwarded on this port.
      Parameters:
      msg - the message
    • writeAll

      void writeAll(Collection<AbstractMessage<?>> msg)
      Puts several messages to be forwarded on this port.
      Parameters:
      msg - collection of messages
    • getParent

      ModelEntity getParent()