Package convex.net

Class NIOServer

java.lang.Object
convex.net.NIOServer
All Implemented Interfaces:
Closeable, AutoCloseable

public class NIOServer extends Object implements Closeable
NIO Server implementation that handles incoming messages on a given port. Allocates a single thread for the selector. Incoming messages are associated with a Connection (which is created if required), then placed on the receive message queue. This will block if the receive queue is full (thereby applying back-pressure to clients)
  • Field Details

  • Method Details

    • create

      public static NIOServer create(Server server, BlockingQueue<Message> receiveQueue)
      Creates a new unlaunched NIO server
      Parameters:
      server - Peer Server instance for this NIOServer
      receiveQueue - Queue for received messages
      Returns:
      New NIOServer instance
    • launch

      public void launch(Integer port)
    • getPort

      public int getPort()
      Gets the port that this server instance is listening on.
      Returns:
      Port number, or 0 if a server socket is not bound.
    • selectWrite

      protected void selectWrite(SelectionKey key) throws IOException
      Throws:
      IOException
    • selectRead

      protected void selectRead(SelectionKey key) throws IOException
      Throws:
      IOException
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getHostAddress

      public InetSocketAddress getHostAddress()
      Gets the host address for this server (including port), or null if closed
      Returns:
      Host address