Class Router

java.lang.Object
model.estrutura.Router

public class Router extends Object
Represents a router that manages multiple protocols and their associated data queues. The router provides functionality to add data to specific protocols and read data from protocol queues following FIFO principles.

This class acts as a facade that coordinates between the protocol management system and the data storage mechanism.

Since:
2024
  • Field Details

  • Constructor Details

    • Router

      public Router()
      Constructs a new Router with an empty protocol list. Initializes the internal protocol management system.
  • Method Details

    • addData

      public void addData(String type, String data)
      Adds data to the specified protocol type. If the protocol doesn't exist, it will be created automatically. The data is written to the protocol's FIFO data queue.
      Parameters:
      type - the protocol type to which the data should be added
      data - the data to be added to the protocol's queue
    • readData

      public String readData(String type) throws IllegalArgumentException
      Reads and removes data from the specified protocol's queue. If the protocol's queue becomes empty after reading, the protocol is automatically removed from the system.
      Parameters:
      type - the protocol type from which to read data
      Returns:
      the data read from the protocol's queue, or a message indicating the protocol was removed if the queue is empty
      Throws:
      IllegalArgumentException - if no protocols exist in the system or if the specified protocol doesn't exist