NIOServerSocket (Naga API)
Date: 2016-06-28

naga

## Interface NIOServerSocket

- All Superinterfaces:
    NIOAbstractSocket
  All Known Subinterfaces:
    NIOServerSocketSSL

      public interface NIOServerSocket
      extends NIOAbstractSocket

  Interface for the NIOServerSocket, which is an asynchronous facade to an underlying ServerSocket.

  The NIOServerSocket executes callbacks to a ServerSocket observer to react to new connections and other events.

  Author:
    Christoffer Lerno

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `getTotalAcceptedConnections()` Returns the total number of accepted connections on this socket since it opened.
    `long` | `getTotalConnections()` Returns the total number of connections made on this socket since it opened.
    `long` | `getTotalFailedConnections()` Returns the total number of failed connections on this socket since it opened.
    `long` | `getTotalRefusedConnections()` Returns the total number of refused connections on this socket since it opened.
    `void` | `listen(ServerSocketObserver observer)` Associates a server socket observer with this server socket and starts accepting connections.
    `void` | `setConnectionAcceptor(ConnectionAcceptor acceptor)` Sets the connection acceptor for this server socket.
    `java.net.ServerSocket` | `socket()` Allows access to the underlying server socket.

    - ### Methods inherited from interface naga.NIOAbstractSocket

      `close, getAddress, getIp, getPort, getTag, isOpen, setTag`

- - ### Method Detail

    - #### getTotalConnections

          long getTotalConnections()

      Returns the total number of connections made on this socket since it opened.

      This method is thread-safe.

      Returns:
        the total number of connections made on this server socket.

    - #### getTotalRefusedConnections

          long getTotalRefusedConnections()

      Returns the total number of refused connections on this socket since it opened.

      This method is thread-safe.

      Returns:
        the total number of refused connections on this server socket.

    - #### getTotalAcceptedConnections

          long getTotalAcceptedConnections()

      Returns the total number of accepted connections on this socket since it opened.

      This method is thread-safe.

      Returns:
        the total number of accepted connections on this server socket.

    - #### getTotalFailedConnections

          long getTotalFailedConnections()

      Returns the total number of failed connections on this socket since it opened.

      This method is thread-safe.

      Returns:
        the total number of failed connections on this server socket.

    - #### listen

          void listen(ServerSocketObserver observer)

      Associates a server socket observer with this server socket and starts accepting connections.

      This method is thread-safe, but may only be called once.

      Parameters:
        `observer` - the observer to receive callbacks from this socket.
      Throws:
        `java.lang.NullPointerException` - if the observer given is null.
        `java.lang.IllegalStateException` - if an observer has already been set.

    - #### setConnectionAcceptor

          void setConnectionAcceptor(ConnectionAcceptor acceptor)

      Sets the connection acceptor for this server socket.

      A connection acceptor determines if a connection should be disconnected or not after the initial accept is done.

      For more information, see the documentation for `naga.ConnectionAcceptor`.

      This method is thread-safe.

      Parameters:
        `acceptor` - the acceptor to use, or null to default to ConnectorAcceptor.DENY.

    - #### socket

          java.net.ServerSocket socket()

      Allows access to the underlying server socket.

      Note calling close and similar functions on this socket will put the NIOServerSocket in an undefined state

      Returns:
        return the underlying server socket.