Class Hub


  • public class Hub
    extends Object
    Manages a collection of KDC clients as a single communication entity.

    A hub is protocol-independent and may contain clients using different communication protocols. It allows applications to add and remove clients, inspect the collection, and broadcast agents to all associated clients.

    Access to the client collection is synchronized. Broadcast operations use a snapshot of the collection to avoid concurrent modification.

    A hub may be cleared without halting its clients. Calling halt() halts the currently associated clients and removes them from the collection. The hub remains available for reuse.

    Author:
    Charles B. Kozoyed
    • Constructor Detail

      • Hub

        public Hub()
        Creates an empty client hub.
    • Method Detail

      • clear

        public void clear()
        Removes all clients from this hub.

        This method does not halt or close the removed clients.

      • addClient

        public void addClient​(Client client)
        Adds a client to this hub.
        Parameters:
        client - the client to add
        Throws:
        IllegalArgumentException - if client is null
      • removeClient

        public void removeClient​(Client client)
        Removes a client from this hub.

        The removed client is not halted or closed.

        Parameters:
        client - the client to remove
        Throws:
        IllegalArgumentException - if client is null
      • size

        public int size()
        Returns the number of clients currently in this hub.
        Returns:
        the number of clients
      • getClients

        public List<Client> getClients()
        Returns an unmodifiable snapshot of the clients in this hub.

        Changes to the hub after this method returns are not reflected in the returned list.

        Returns:
        an unmodifiable list containing the current clients
      • sendAsync

        public void sendAsync​(Agent agent)
        Sends an agent asynchronously to every client currently in this hub.

        The operation uses a snapshot of the client collection. If sending to an individual client fails, the error is logged and sending continues to the remaining clients.

        Parameters:
        agent - the agent to send
        Throws:
        IllegalArgumentException - if agent is null
      • halt

        public void halt()
        Halts all clients currently associated with this hub and removes them from the collection.

        The client collection is cleared atomically, and each client in the captured snapshot is subsequently halted.

        New clients may be added while previously associated clients are being halted. The hub remains available for reuse.

        Concurrent send operations may still be processing previously captured client snapshots.