A net service provides methods to create resource friendly network clients and servers and resolve host addresses with DNS resolution.
This service should always be used to create clients or servers as it allows to centralize their usage so that thread creation and usage can be optimized based on hardware capabilities.
A typical implementation would rely on the Reactor
to obtain optimized event loop groups for the creation of client and server bootstraps.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Represents the transport type supported at runtime. -
Method Summary
Modifier and TypeMethodDescriptioncreateClient
(SocketAddress socketAddress) Creates a client bootstrap that will connect to the specified address with all available threads.createClient
(SocketAddress socketAddress, int nThreads) Creates a client bootstrap that will connect to the specified address with amount of threads.createClient
(SocketAddress socketAddress, NetClientConfiguration clientConfiguration) Creates a client bootstrap that will connect to the specified address with the specified configuration and all available threads.createClient
(SocketAddress socketAddress, NetClientConfiguration clientConfiguration, int nThreads) Creates a client bootstrap that will connect to the specified address with the specified configuration and amount of threads.createServer
(SocketAddress socketAddress) Creates a server bootstrap that will bind to the specified address with all available threads.createServer
(SocketAddress socketAddress, int nThreads) Creates a server bootstrap that will bind to the specified address with the specified amount of threads.createServer
(SocketAddress socketAddress, NetServerConfiguration serverConfiguration) Creates a server bootstrap that will bind to the specified address with the specified configuration and all available threads.createServer
(SocketAddress socketAddress, NetServerConfiguration serverConfiguration, int nThreads) Creates a server bootstrap that will bind to the specified address with the specified server configuration and amount of threads.Returns aByteBuf
allocator.Returns a directByteBuf
allocator.Returns the DNS resolver.Returns the transport type.default Mono
<InetAddress> Resolves an address associated to the specified host name.default Mono
<InetSocketAddress> Resolves a socket address associated to the specified host name and port.resolve
(InetSocketAddress socketAddress) Resolves a socket address associated to the socket address.default Mono
<List<InetAddress>> resolveAll
(String host) Resolves all addresses associated to the specified host name.default Mono
<List<InetSocketAddress>> resolveAll
(String host, int port) Resolves all socket addresses associated to the specified host name and port.resolveAll
(InetSocketAddress socketAddress) Resolves all socket addresses associated to the specified socket address.
-
Method Details
-
getTransportType
NetService.TransportType getTransportType()Returns the transport type.
- Returns:
- a transport type
-
createClient
Creates a client bootstrap that will connect to the specified address with all available threads.
- Parameters:
socketAddress
- the socket address to connect to- Returns:
- a client bootstrap
-
createClient
Creates a client bootstrap that will connect to the specified address with the specified configuration and all available threads.
- Parameters:
socketAddress
- the socket address to connect toclientConfiguration
- the client configuration- Returns:
- a client bootstrap
-
createClient
Creates a client bootstrap that will connect to the specified address with amount of threads.
- Parameters:
socketAddress
- the socket address to connect tonThreads
- the number of threads to allocate- Returns:
- a client bootstrap
- Throws:
IllegalArgumentException
- if the specified number of thread exceeds the number of threads available
-
createClient
Bootstrap createClient(SocketAddress socketAddress, NetClientConfiguration clientConfiguration, int nThreads) throws IllegalArgumentException Creates a client bootstrap that will connect to the specified address with the specified configuration and amount of threads.
- Parameters:
socketAddress
- the socket address to connect toclientConfiguration
- the client configurationnThreads
- the number of threads to allocate- Returns:
- a client bootstrap
- Throws:
IllegalArgumentException
- if the specified number of thread exceeds the number of threads available
-
createServer
Creates a server bootstrap that will bind to the specified address with all available threads.
- Parameters:
socketAddress
- the socket address to bind to- Returns:
- a server bootstrap
-
createServer
ServerBootstrap createServer(SocketAddress socketAddress, NetServerConfiguration serverConfiguration) Creates a server bootstrap that will bind to the specified address with the specified configuration and all available threads.
- Parameters:
socketAddress
- the socket address to bind toserverConfiguration
- the server configuration- Returns:
- a server bootstrap
-
createServer
ServerBootstrap createServer(SocketAddress socketAddress, int nThreads) throws IllegalArgumentException Creates a server bootstrap that will bind to the specified address with the specified amount of threads.
- Parameters:
socketAddress
- the socket address to bind tonThreads
- the number of threads to allocate- Returns:
- a server bootstrap
- Throws:
IllegalArgumentException
- if the specified number of thread exceeds the number of threads available
-
createServer
ServerBootstrap createServer(SocketAddress socketAddress, NetServerConfiguration serverConfiguration, int nThreads) throws IllegalArgumentException Creates a server bootstrap that will bind to the specified address with the specified server configuration and amount of threads.
- Parameters:
socketAddress
- the socket address to bind toserverConfiguration
- the server configurationnThreads
- the number of threads to allocate- Returns:
- a server bootstrap
- Throws:
IllegalArgumentException
- if the specified number of thread exceeds the number of threads available
-
resolve
Resolves an address associated to the specified host name.
- Parameters:
host
- a host name- Returns:
- a mono emitting an address
-
resolve
Resolves a socket address associated to the specified host name and port.
- Parameters:
host
- a host nameport
- a port- Returns:
- a mono emitting a socket address
-
resolve
Resolves a socket address associated to the socket address.
- Parameters:
socketAddress
- a socket address- Returns:
- a mono emitting a socket address
-
resolveAll
Resolves all addresses associated to the specified host name.
- Parameters:
host
- a host name- Returns:
- a mono emitting a list of addresses
-
resolveAll
Resolves all socket addresses associated to the specified host name and port.
- Parameters:
host
- a host nameport
- a port- Returns:
- a mono emitting a list of socket addresses
-
resolveAll
Resolves all socket addresses associated to the specified socket address.
- Parameters:
socketAddress
- a socket address- Returns:
- a mono emitting a list of socket addresses
-
getResolver
AddressResolverGroup<InetSocketAddress> getResolver()Returns the DNS resolver.
- Returns:
- the name resolver
-
getByteBufAllocator
ByteBufAllocator getByteBufAllocator()Returns a
ByteBuf
allocator.As for event loop groups, this service shall provide optimized
ByteBuf
allocators.- Returns:
- a byte buf allocator
-
getDirectByteBufAllocator
ByteBufAllocator getDirectByteBufAllocator()Returns a direct
ByteBuf
allocator.As for event loop groups, this service shall provide optimized
ByteBuf
allocators.- Returns:
- a byte buf allocator
-