Package org.omegazero.net.common
Class NetworkApplicationBuilder
java.lang.Object
org.omegazero.net.common.NetworkApplicationBuilder
- Direct Known Subclasses:
NetClientManagerBuilder
,NetServerBuilder
A builder class for creating
NetworkApplication
s.
Builders for server and client manager instances are created using newServer(String)
and newClientManager(String)
.
- Since:
- 2.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An enum containing the transport type options of a network application. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected SSLContext
protected NetworkApplicationBuilder.TransportType
protected Function
<SocketConnection, Consumer<Runnable>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addImplementationAlias
(String name, String className) Adds an implementation name alias.abstract NetworkApplication
build()
Creates theNetworkApplication
from the previously set parameters.encrypted
(boolean encrypted) Sets whether to use encryption.static NetClientManagerBuilder
newClientManager
(String implementation) Creates a newNetClientManagerBuilder
to create aNetClientManager
instance.static NetServerBuilder
Creates a newNetServerBuilder
to create aNetServer
instance.protected void
This method does parameter validation and preparations.Sets an implementation specific configuration parameter.sslContext
(SSLContext sslContext) Sets theSSLContext
to use for encryption.transportType
(NetworkApplicationBuilder.TransportType transportType) Sets theNetworkApplicationBuilder.TransportType
to use in this instance.workerCreator
(Function<SocketConnection, Consumer<Runnable>> workerCreator) Sets a worker creator which creates a worker instance for each connection created.
-
Field Details
-
transportType
-
encrypted
protected boolean encrypted -
workerCreator
-
sslContext
-
-
Constructor Details
-
NetworkApplicationBuilder
public NetworkApplicationBuilder()
-
-
Method Details
-
build
Creates theNetworkApplication
from the previously set parameters.- Returns:
- The
NetworkApplication
- Throws:
UnsupportedOperationException
- If the specific configuration is not supported by the implementationIllegalArgumentException
- If a configuration parameter combination is invalidIllegalStateException
- If a required parameter was not set- Implementation Requirements:
- Implementations of this method must call
prepareBuild()
first.
-
prepareBuild
protected void prepareBuild()This method does parameter validation and preparations. -
transportType
public NetworkApplicationBuilder transportType(NetworkApplicationBuilder.TransportType transportType) Sets theNetworkApplicationBuilder.TransportType
to use in this instance.The default is
NetworkApplicationBuilder.TransportType.STREAM
.- Parameters:
transportType
- TheTransportType
- Returns:
- This builder
- Throws:
NullPointerException
- If transportType isnull
-
encrypted
Sets whether to use encryption. Specific implementation or types may require additional parameters to enable encryption.The default is
false
.- Parameters:
encrypted
- Whether encryption is enabled- Returns:
- This builder
-
workerCreator
public NetworkApplicationBuilder workerCreator(Function<SocketConnection, Consumer<Runnable>> workerCreator) Sets a worker creator which creates a worker instance for each connection created.The default is
null
(no workers).- Parameters:
workerCreator
- The function- Returns:
- This builder
-
sslContext
Sets theSSLContext
to 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.- Parameters:
sslContext
- TheSSLContext
- Returns:
- This builder
-
set
Sets an implementation specific configuration parameter.- Parameters:
option
- The name of the parametervalue
- The value- Throws:
IllegalArgumentException
- If the given parameter name is not valid- Since:
- 2.2.1
- Implementation Note:
- By default, this method always throws an
IllegalArgumentException
-
addImplementationAlias
Adds an implementation name alias.Usually, the methods
newServer(String)
andnewClientManager(String)
require a class name for the implementation parameter. Adding a name alias allows a shorter name to be passed instead.For example, adding an alias as follows:
addImplementationAlias("example_server", "com.example.server.ServerBuilder");
newServer("com.example.server.ServerBuilder"); newServer("example_server"); newServer("example");
"_server"
(or"_client"
for client managers) is also tried.By default, two aliases are registered:
"nio_server"
-"org.omegazero.net.nio.server.NioServerBuilder"
"nio_client"
-"org.omegazero.net.nio.client.NioClientManagerBuilder"
- Parameters:
name
- The short nameclassName
- The implementation builder class name
-
newServer
Creates a newNetServerBuilder
to create aNetServer
instance.- Parameters:
implementation
- The implementation name or class name of the builder- Returns:
- The new builder
- See Also:
-
newClientManager
Creates a newNetClientManagerBuilder
to create aNetClientManager
instance.- Parameters:
implementation
- The implementation name or class name of the builder- Returns:
- The new builder
- See Also:
-