Class NetServerBuilder
- Direct Known Subclasses:
NioServerBuilder
NetworkApplicationBuilder for creating NetServers.- Since:
- 2.1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.omegazero.net.common.NetworkApplicationBuilder
NetworkApplicationBuilder.TransportType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]protected Collection<InetAddress> protected intprotected intprotected Stringprotected Collection<Integer> Fields inherited from class org.omegazero.net.common.NetworkApplicationBuilder
encrypted, sslContext, transportType, workerCreator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddBindAddress(InetAddress bindAddress) Adds a local address to bind to.addPort(int port) Adds a network port this server should listen on.applicationLayerProtocols(String... applicationLayerProtocols) Sets the application protocol name options the server presents.applicationLayerProtocols(Collection<String> applicationLayerProtocols) Sets the application protocol name options the server presents, for example during TLS Application-Layer Protocol Negotiation.bindAddress(InetAddress bindAddress) Sets the single local address the server should bind to.bindAddresses(InetAddress... bindAddresses) Sets the local addresses the server should bind to.bindAddresses(Collection<InetAddress> bindAddresses) Sets the local addresses the server should bind to.abstract NetServerbuild()Creates theNetworkApplicationfrom the previously set parameters.connectionBacklog(int connectionBacklog) Sets the maximum length of the queue for pending connections, if applicable.connectionIdleTimeout(int connectionIdleTimeout) Sets the minimum time in seconds to keep an idle connection with no traffic.encrypted(boolean encrypted) Sets whether to use encryption.listenPath(String listenPath) Sets the local file system path the server should listen on.port(int port) Sets a single network port this server should listen on.ports(int... ports) Sets the network ports this server should listen on.ports(Collection<Integer> ports) Sets the network ports this server should listen on.protected voidThis method does parameter validation and preparations.Sets an implementation specific configuration parameter.sslContext(SSLContext sslContext) Sets theSSLContextto use for encryption.transportType(NetworkApplicationBuilder.TransportType transportType) Sets theNetworkApplicationBuilder.TransportTypeto use in this instance.workerCreator(Function<SocketConnection, Consumer<Runnable>> workerCreator) Sets a worker creator which creates a worker instance for each connection created.Methods inherited from class org.omegazero.net.common.NetworkApplicationBuilder
addImplementationAlias, newClientManager, newServer
-
Field Details
-
bindAddresses
-
ports
-
listenPath
-
connectionBacklog
protected int connectionBacklog -
connectionIdleTimeout
protected int connectionIdleTimeout -
applicationLayerProtocols
-
-
Constructor Details
-
NetServerBuilder
public NetServerBuilder()
-
-
Method Details
-
build
Description copied from class:NetworkApplicationBuilderCreates theNetworkApplicationfrom the previously set parameters.- Specified by:
buildin classNetworkApplicationBuilder- Returns:
- The
NetworkApplication
-
transportType
Description copied from class:NetworkApplicationBuilderSets theNetworkApplicationBuilder.TransportTypeto use in this instance.The default is
NetworkApplicationBuilder.TransportType.STREAM.- Overrides:
transportTypein classNetworkApplicationBuilder- Parameters:
transportType- TheTransportType- Returns:
- This builder
-
encrypted
Description copied from class:NetworkApplicationBuilderSets whether to use encryption. Specific implementation or types may require additional parameters to enable encryption.The default is
false.- Overrides:
encryptedin classNetworkApplicationBuilder- Parameters:
encrypted- Whether encryption is enabled- Returns:
- This builder
-
workerCreator
Description copied from class:NetworkApplicationBuilderSets a worker creator which creates a worker instance for each connection created.The default is
null(no workers).- Overrides:
workerCreatorin classNetworkApplicationBuilder- Parameters:
workerCreator- The function- Returns:
- This builder
-
sslContext
Description copied from class:NetworkApplicationBuilderSets theSSLContextto use for encryption.This method implicitly enables encryption if the given parameter is not
null, and disables it otherwise.The default is
null. Setting this parameter may be required by the implementation if encryption is enabled.- Overrides:
sslContextin classNetworkApplicationBuilder- Parameters:
sslContext- TheSSLContext- Returns:
- This builder
-
set
Description copied from class:NetworkApplicationBuilderSets an implementation specific configuration parameter.- Overrides:
setin classNetworkApplicationBuilder- Parameters:
option- The name of the parametervalue- The value
-
bindAddresses
Sets the local addresses the server should bind to.This method overrides any previous local address settings.
nullor a collection with a singlenullelement may be passed to bind to the default addresses chosen by the system or implementation. This is also the default.- Parameters:
bindAddresses- The local addresses- Returns:
- This builder
- Throws:
NullPointerException- If the collection has more than one element and any element isnull
-
bindAddresses
Sets the local addresses the server should bind to. SeebindAddresses(Collection).This method overrides any previous local address settings.
- Parameters:
bindAddresses- The local addresses- Returns:
- This builder
- Throws:
NullPointerException- If the collection has more than one element and any element isnull
-
bindAddress
Sets the single local address the server should bind to.This method overrides any previous local address settings.
- Parameters:
bindAddress- The local address- Returns:
- This builder
- Throws:
NullPointerException- If the given value isnull
-
addBindAddress
Adds a local address to bind to.- Parameters:
bindAddress- The local address- Returns:
- This builder
- Throws:
NullPointerException- If the given value isnull- See Also:
-
ports
Sets the network ports this server should listen on.This method overrides any previous port settings.
This method and
listenPath(String)are mutually exclusive, but one of them is required.- Parameters:
ports- The ports- Returns:
- This builder
- Throws:
NullPointerException- If an element isnullIllegalArgumentException- If a port is not positive
-
ports
Sets the network ports this server should listen on.This method overrides any previous port settings.
This method and
listenPath(String)are mutually exclusive, but one of them is required.- Parameters:
ports- The ports- Returns:
- This builder
- Throws:
IllegalArgumentException- If a port is not positive
-
port
Sets a single network port this server should listen on.This method overrides any previous port settings.
This method and
listenPath(String)are mutually exclusive, but one of them is required.- Parameters:
port- The port- Returns:
- This builder
- Throws:
IllegalArgumentException- If the port is not positive
-
addPort
Adds a network port this server should listen on.This method and
listenPath(String)are mutually exclusive, but one of them is required.- Parameters:
port- The port- Returns:
- This builder
- Throws:
IllegalArgumentException- If the port is not positive
-
listenPath
Sets the local file system path the server should listen on.This method and
ports(Collection)(and other methods to set ports) are mutually exclusive, but one of them is required.- Parameters:
listenPath- The path- Returns:
- This builder
-
connectionBacklog
Sets the maximum length of the queue for pending connections, if applicable.The default,
0, may be set to let the system or implementation choose an appropriate value.- Parameters:
connectionBacklog- The queue length- Returns:
- This builder
- Throws:
IllegalArgumentException- If the given value is negative
-
connectionIdleTimeout
Sets the minimum time in seconds to keep an idle connection with no traffic.The default,
0, may be set to disable idle timeouts.- Parameters:
connectionIdleTimeout- The idle timeout in seconds- Returns:
- This builder
- Throws:
IllegalArgumentException- If the given value is negative
-
applicationLayerProtocols
Sets the application protocol name options the server presents, for example during TLS Application-Layer Protocol Negotiation. The elements in this list should be ordered from most-preferred to least-preferred protocol name.The default is
null(protocol presented by client is selected, or negotiation is disabled).- Parameters:
applicationLayerProtocols- The protocol names- Returns:
- This builder
-
applicationLayerProtocols
Sets the application protocol name options the server presents. SeeapplicationLayerProtocols(Collection).- Parameters:
applicationLayerProtocols- The protocol names- Returns:
- This builder
-
prepareBuild
protected void prepareBuild()Description copied from class:NetworkApplicationBuilderThis method does parameter validation and preparations.- Overrides:
prepareBuildin classNetworkApplicationBuilder
-