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 TypeMethodDescriptionvoid
close()
static NIOServer
create(Server server, BlockingQueue<Message> receiveQueue)
Creates a new unlaunched NIO servervoid
finalize()
Gets the host address for this server (including port), or null if closedint
getPort()
Gets the port that this server instance is listening on.void
void
protected void
selectRead(SelectionKey key)
protected void
selectWrite(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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getHostAddress
Gets the host address for this server (including port), or null if closed- Returns:
- Host address
-