Modifier and Type | Field and Description |
---|---|
Map<InetSocketAddress,Consumer<TcpChannel>> |
handlers
Handlers for each server address.
|
int[] |
selectorIds
Ids of selectors for this server.
|
int |
serverSocketBacklog
Server socket backlog.
|
int |
maxConnections
Max number of connections.
|
int |
maxConnectionsPerIp
Max number of connections per IP.
|
ConsumerX<ServerSocketChannel> |
serverSocketConf
Action to configure the server socket.
|
ConsumerX<SocketChannel> |
socketConf
Action to configure each newly accepted socket.
|
Constructor and Description |
---|
Conf()
Create a Conf with default values
|
public Map<InetSocketAddress,Consumer<TcpChannel>> handlers
default: empty
A channel handler is invoked whenever a new incoming connection is accepted on the address; the handler must not block, must not throw Exception.
Example:
conf.handlers.put( new InetSocketAddress(port), channel->{...} );
public int[] selectorIds
default: [0, 1, ... N-1] where N is the number of processors
Conceptually there are infinite number of selectors, each associated with a dedicated thread. A server may choose to use any one or several selectors. Different servers/clients can share same selectors or use different selectors.
public int serverSocketBacklog
default: 50
public int maxConnections
default:
Integer.MAX_VALUE
If this limit is reached, no new incoming connections are accepted, until some existing connections are closed.
public int maxConnectionsPerIp
default:
Integer.MAX_VALUE
For any IP, if this limit is reached, no new incoming connections are accepted, until some existing connections are closed.
public ConsumerX<ServerSocketChannel> serverSocketConf
default action:
enable
SO_REUSEADDR
if the OS is not Windows.
App may want to configure more options on the server socket, e.g.
ServerSocket.setReceiveBufferSize(int)
.
The ServerSocketChannel is in non-blocking model; it must not be changed to blocking mode.
The action will be invoked before
ServerSocket.bind()
.
public ConsumerX<SocketChannel> socketConf
default action:
enable
TCP_NODELAY
App may want to configure more options on each socket. The SocketChannel is in non-blocking model; it must not be changed to blocking mode.