Package convex.net
Class NIOServer
java.lang.Object
convex.net.NIOServer
- All Implemented Interfaces:
Closeable,AutoCloseable
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static NIOServercreate(Server server, BlockingQueue<Message> receiveQueue)Creates a new unlaunched NIO servervoidfinalize()Gets the host address for this server (including port), or null if closedintgetPort()Gets the port that this server instance is listening on.voidvoidprotected voidselectRead(SelectionKey key)protected voidselectWrite(SelectionKey key)
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
- Constant Field Values
-
-
Method Details
-
create
Creates a new unlaunched NIO server- Parameters:
server- Peer Server instance for this NIOServerreceiveQueue- Queue for received messages- Returns:
- New NIOServer instance
-
launch
-
launch
-
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
- Throws:
IOException
-
selectRead
- Throws:
IOException
-
finalize
public void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getHostAddress
Gets the host address for this server (including port), or null if closed- Returns:
- Host address
-