Package 

Class MergingDatagramSocket

  • All Implemented Interfaces:
    java.io.Closeable , java.lang.AutoCloseable

    
    public class MergingDatagramSocket
    extends DatagramSocket
                        

    A DatagramSocket implementation which merges a set of sockets. It maintains a thread reading from each of the underlying sockets. Thus received datagrams are provided via the receive API, in the order in which they were originally received (or close to it, since the implementation is only based on timestamps). One of the underlying sockets is used as a delegate, and handles sending via send and calls to getLocalPort, getLocalAddress and getLocalSocketAddress.

    • Constructor Detail

      • MergingDatagramSocket

        MergingDatagramSocket(Logger parentLogger)
        Initializes a new MergingDatagramSocket instance.
        Parameters:
        parentLogger - the Logger parent logger from which we'll derive this class' logger instance
    • Method Detail

      • send

         void send(DatagramPacket pkt)
        The current implementation delegates to the first container, but this is subject to change.
        Parameters:
        pkt - the datagram to send.
      • add

         void add(DelegatingSocket socket)

        Adds a DelegatingSocket instance to this merging socket. Note that this will start a thread reading from the added socket.

        Parameters:
        socket - the socket to add.
      • add

         void add(IceSocketWrapper wrapper)

        Adds the socket instance wrapped by wrapper to this merging socket. Note that this will start a thread reading from the added socket.

        Parameters:
        wrapper - the wrapper of the socket to add.
      • add

         void add(DatagramSocket socket)

        Adds a DatagramSocket instance to this merging socket. Note that this will start a thread reading from the added socket.

        Parameters:
        socket - the socket to add.
      • getLocalPort

         int getLocalPort()
        Delegates to the "active" socket, if one exists. Else returns 0. TODO: should we return 0 (unbound) or -1 (closed) if there are no sockets?
      • receive

         void receive(DatagramPacket p)
        Copies into p a packet already received from one of the underlying sockets. The socket is chosen on the base of the timestamp of the reception of the first packet in its queue (so that earlier packets are received first).