Class NioServer

All Implemented Interfaces:
Closeable, AutoCloseable, ConnectionListener

public class NioServer extends NioBaseServer
Server for sending and receiving messages via NIO channels. Uses only a single thread to accept, connect, write and read to/from connections.

Note that writes can get dropped, e.g. in the case where we have a previous write pending and a new write is invoked. This is typically not an issue as JGroups retransmits messages, but might become one when using NioServer standalone, i.e. outside JGroups.

Since:
3.6.5
  • Field Details

  • Constructor Details

    • NioServer

      public NioServer(InetAddress bind_addr, int port) throws Exception
      Creates an instance of NioServer that opens a server channel and listens for connections. Needs to be started next.
      Parameters:
      bind_addr - The local address to bind to. If null, the address will be picked by the OS
      port - The local port to bind to
      Throws:
      Exception - Thrown if the creation failed
    • NioServer

      public NioServer(ThreadFactory thread_factory, SocketFactory socket_factory, InetAddress bind_addr, int srv_port, int end_port, InetAddress external_addr, int external_port, int recv_buf_size) throws Exception
      Throws:
      Exception
    • NioServer

      public NioServer(ThreadFactory thread_factory, SocketFactory socket_factory, InetAddress bind_addr, int srv_port, int end_port, InetAddress external_addr, int external_port, int recv_buf_size, String service_name) throws Exception
      Creates an instance of NioServer that opens a server channel and listens for connections. Needs to be started next.
      Parameters:
      thread_factory - The thread factory used to create new threads
      socket_factory - The socket factory used to create socket channels
      bind_addr - The local address to bind to. If null, the address will be picked by the OS
      srv_port - The local port to bind to If 0, the port will be picked by the OS.
      end_port - If srv_port is taken, the next port is tried, until end_port has been reached, in which case an exception will be thrown. If srv_port == end_port, only 1 port will be tried.
      external_addr - The external address in case of NAT. Ignored if null.
      external_port - The external port on the NA. If 0, srv_port is used.
      recv_buf_size - The size of the initial TCP receive window (in bytes)
      service_name - The name of the service
      Throws:
      Exception - Thrown if the creation failed
  • Method Details