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
FieldsModifier and TypeFieldDescriptionstatic final int
protected static final long
protected static final long
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static NIOServer
Creates a new unlaunched NIO server componentvoid
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
pruneConnections
(long ts, Set<SelectionKey> keys) Prune old connectionsprotected void
selectRead
(SelectionKey key) protected void
selectWrite
(SelectionKey key)
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
SELECT_TIMEOUT
protected static final long SELECT_TIMEOUT- See Also:
-
PRUNE_TIMEOUT
protected static final long PRUNE_TIMEOUT- See Also:
-
-
Method Details
-
create
Creates a new unlaunched NIO server component- Parameters:
server
- Peer Server instance for this NIOServer- Returns:
- New NIOServer instance
-
launch
- Throws:
IOException
-
launch
- Throws:
IOException
-
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.
-
pruneConnections
Prune old connections- Parameters:
keys
- Keys to examine
-
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
-