Interface Acceptor

  • All Superinterfaces:
    AutoCloseable

    public interface Acceptor
    extends AutoCloseable
    The interface provides methods for maintaining multiple listening ports. It allows to add/remove listening port and calls the specified listener when a new connection is accepted via an added listening port.
    • Method Detail

      • getListener

        Acceptor.Listener getListener()
        Returns the listener which will be called in case there is a new connection accepted on a listening port.
        Returns:
        the listener which will be called in case there is a new connection accepted on a listening port.
      • setListener

        void setListener​(Acceptor.Listener listener)
        Sets the listener which will be called in case there is a new connection accepted on a listening port. By default, NULL_LISTENER is specified.
        Parameters:
        listener - listener to be used when a new connection accepted.
      • addListeningPort

        void addListeningPort​(InetSocketAddress bindAddress,
                              Object attachment)
                       throws IOException
        Creates a server-socket bound to the specified address. In case there will be a new connection accepted on the port the specified Acceptor listener will be fired with accepted socket and the specified attachment.
        Parameters:
        bindAddress - address created server-socket will be bound.
        attachment - attachment which will be returned when a new connection will be accepted.
        Throws:
        IOException - will be thrown in case there is a exception while binding/configuring server-socket.
      • removeListeningPort

        boolean removeListeningPort​(int port)
                             throws IOException
        Removes the server-socket corresponding to the port number.
        Parameters:
        port - port number
        Returns:
        true in case corresponding server-socket is removed, false otherwise.
        Throws:
        IOException - will be thrown in case there is a exception while unbinding/closing server-socket.
      • getBacklog

        int getBacklog()
        Returns the maximum number of pending connections on listen ports.
        Returns:
        the maximum number of pending connections on listen ports.
      • setBacklog

        void setBacklog​(int backlog)
        Sets the maximum number of pending connections on listen ports.
        Parameters:
        backlog - the maximum number of pending connections