Package reactor.netty.tcp
Class TcpResources
java.lang.Object
reactor.netty.tcp.TcpResources
- All Implemented Interfaces:
Disposable
,ConnectionProvider
,LoopResources
- Direct Known Subclasses:
HttpResources
Hold the default Tcp resources.
- Since:
- 0.6
- Author:
- Stephane Maldini
-
Nested Class Summary
Nested classes/interfaces inherited from interface reactor.netty.resources.ConnectionProvider
ConnectionProvider.AllocationStrategy<A extends ConnectionProvider.AllocationStrategy<A>>, ConnectionProvider.Builder, ConnectionProvider.ConnectionMetadata, ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>, ConnectionProvider.HostSpecificSpec, ConnectionProvider.MeterRegistrar
Nested classes/interfaces inherited from interface reactor.core.Disposable
Disposable.Composite, Disposable.Swap
-
Field Summary
Fields inherited from interface reactor.netty.resources.ConnectionProvider
DEFAULT_POOL_ACQUIRE_TIMEOUT, DEFAULT_POOL_LEASING_STRATEGY, DEFAULT_POOL_MAX_CONNECTIONS, DEFAULT_POOL_MAX_IDLE_TIME, DEFAULT_POOL_MAX_LIFE_TIME, LEASING_STRATEGY_FIFO, LEASING_STRATEGY_LIFO
Fields inherited from interface reactor.netty.resources.LoopResources
DEFAULT_IO_SELECT_COUNT, DEFAULT_IO_WORKER_COUNT, DEFAULT_NATIVE, DEFAULT_SHUTDOWN_QUIET_PERIOD, DEFAULT_SHUTDOWN_TIMEOUT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TcpResources
(LoopResources defaultLoops, ConnectionProvider defaultProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
_dispose()
Dispose underlying resources._disposeLater
(Duration quietPeriod, Duration timeout) Dispose underlying resources in a listenable fashion.Mono<? extends Connection>
acquire
(TransportConfig config, ConnectionObserver observer, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup) Return an existing or newConnection
on subscribe.boolean
daemon()
return true ifEventLoopGroup
should not be shutdown.void
dispose()
This has aNOOP
implementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResources
andConnectionProvider
.This has aNOOP
implementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResources
andConnectionProvider
.disposeLater
(Duration quietPeriod, Duration timeout) This has aNOOP
implementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResources
andConnectionProvider
.static void
Shutdown the globalTcpResources
without resetting them, effectively cleaning up associated resources without creating new ones.Prepare to shutdown the globalTcpResources
without resetting them, effectively cleaning up associated resources without creating new ones.disposeLoopsAndConnectionsLater
(Duration quietPeriod, Duration timeout) Prepare to shutdown the globalTcpResources
without resetting them, effectively cleaning up associated resources without creating new ones.void
disposeWhen
(SocketAddress remoteAddress) Dispose all connection pools for the specified remote address.static TcpResources
get()
Return the global TCP resources for event loops and pooling.protected static <T extends TcpResources>
TgetOrCreate
(AtomicReference<@Nullable T> ref, @Nullable LoopResources loops, @Nullable ConnectionProvider provider, BiFunction<LoopResources, ConnectionProvider, T> onNew, String name) Safely check if existing resource exist and proceed to update/cleanup if new resources references are passed.protected AddressResolverGroup<?>
Safely checks whether a name resolver exists and proceed with a creation if it does not exist.boolean
int
Returns the maximum number of connections before starting pending.@Nullable Map<SocketAddress,
Integer> Returns the maximum number of connections per host before starting pending.@Nullable ConnectionProvider.Builder
mutate()
Returns a builder to mutate properties of thisConnectionProvider
.@Nullable String
name()
ReturnsConnectionProvider
name used for metrics.<CHANNEL extends Channel>
CHANNELonChannel
(Class<CHANNEL> channelType, EventLoopGroup group) Callback for aChannel
selection.onChannelClass
(Class<CHANNEL> channelType, EventLoopGroup group) Callback for aChannel
class selection.onClient
(boolean useNative) Callback for clientEventLoopGroup
creation.onServer
(boolean useNative) Callback for serverEventLoopGroup
creation, this is theEventLoopGroup
for the child channel.onServerSelect
(boolean useNative) Callback for server selectEventLoopGroup
creation, this is theEventLoopGroup
for the acceptor channel.static TcpResources
reset()
Reset TCP resources to default and return its instance.static TcpResources
set
(ConnectionProvider provider) Update pooling resources and return the global TCP resources.static TcpResources
set
(LoopResources loops) Update event loops resources and return the global TCP resources.
-
Constructor Details
-
TcpResources
-
-
Method Details
-
disposeLoopsAndConnections
public static void disposeLoopsAndConnections()Shutdown the globalTcpResources
without resetting them, effectively cleaning up associated resources without creating new ones. This method is NOT blocking. It is implemented as fire-and-forget. UsedisposeLoopsAndConnectionsLater()
when you need to observe the final status of the operation, combined withMono.block()
if you need to synchronously wait for the underlying resources to be disposed. -
disposeLoopsAndConnectionsLater
Prepare to shutdown the globalTcpResources
without resetting them, effectively cleaning up associated resources without creating new ones. This only occurs when the returnedMono
is subscribed to. The quiet period will be2s
and the timeout will be15s
- Returns:
- a
Mono
triggering thedisposeLoopsAndConnections()
when subscribed to.
-
disposeLoopsAndConnectionsLater
Prepare to shutdown the globalTcpResources
without resetting them, effectively cleaning up associated resources without creating new ones. This only occurs when the returnedMono
is subscribed to. It is guaranteed that the disposal of the underlying LoopResources will not happen beforequietPeriod
is over. If a task is submitted during thequietPeriod
, it is guaranteed to be accepted and thequietPeriod
will start over.- Parameters:
quietPeriod
- the quiet period as described abovetimeout
- the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period- Returns:
- a
Mono
triggering thedisposeLoopsAndConnections()
when subscribed to. - Since:
- 0.9.3
-
get
Return the global TCP resources for event loops and pooling.- Returns:
- the global TCP resources for event loops and pooling
-
reset
Reset TCP resources to default and return its instance.- Returns:
- the global TCP resources
-
set
Update pooling resources and return the global TCP resources. Note: The previousConnectionProvider
will be disposed.- Parameters:
provider
- a newConnectionProvider
to replace the current- Returns:
- the global TCP resources
-
set
Update event loops resources and return the global TCP resources. Note: The previousLoopResources
will be disposed.- Parameters:
loops
- a newLoopResources
to replace the current- Returns:
- the global TCP resources
-
acquire
public Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup) Description copied from interface:ConnectionProvider
Return an existing or newConnection
on subscribe.- Specified by:
acquire
in interfaceConnectionProvider
- Parameters:
config
- the transport configurationobserver
- theConnectionObserver
remoteAddress
- theSocketAddress
to connect toresolverGroup
- the resolver which will resolve the address of the unresolved named address- Returns:
- an existing or new
Mono
ofConnection
-
daemon
public boolean daemon()Description copied from interface:LoopResources
return true ifEventLoopGroup
should not be shutdown.- Specified by:
daemon
in interfaceLoopResources
- Returns:
- true if
EventLoopGroup
should not be shutdown
-
dispose
public void dispose()This has aNOOP
implementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResources
andConnectionProvider
. If a disposal of the global TCP resources is needed,disposeLoopsAndConnections()
should be used instead.- Specified by:
dispose
in interfaceConnectionProvider
- Specified by:
dispose
in interfaceDisposable
- Specified by:
dispose
in interfaceLoopResources
-
disposeLater
This has aNOOP
implementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResources
andConnectionProvider
. If a disposal of the global TCP resources is needed,disposeLoopsAndConnectionsLater()
should be used instead.- Specified by:
disposeLater
in interfaceConnectionProvider
- Specified by:
disposeLater
in interfaceLoopResources
- Returns:
- a Mono representing the completion of the ConnectionProvider disposal.
-
disposeLater
This has aNOOP
implementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResources
andConnectionProvider
. If a disposal of the global TCP resources is needed,disposeLoopsAndConnectionsLater(Duration, Duration)
should be used instead.- Specified by:
disposeLater
in interfaceLoopResources
- Parameters:
quietPeriod
- the quiet period as described abovetimeout
- the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period- Returns:
- a Mono representing the completion of the LoopResources disposal.
-
disposeWhen
Dispose all connection pools for the specified remote address.As opposed to
dispose()
, this method delegates to the underlying connection provider. It has a global effect and removes all connection pools for this remote address from the global TCP resources (making it closer todisposeLoopsAndConnections()
than todispose()
).- Specified by:
disposeWhen
in interfaceConnectionProvider
- Parameters:
remoteAddress
- the remote address
-
isDisposed
public boolean isDisposed()- Specified by:
isDisposed
in interfaceDisposable
-
maxConnections
public int maxConnections()Description copied from interface:ConnectionProvider
Returns the maximum number of connections before starting pending.- Specified by:
maxConnections
in interfaceConnectionProvider
- Returns:
- the maximum number of connections before starting pending
-
maxConnectionsPerHost
Description copied from interface:ConnectionProvider
Returns the maximum number of connections per host before starting pending.- Specified by:
maxConnectionsPerHost
in interfaceConnectionProvider
- Returns:
- the maximum number of connections per host before starting pending
-
mutate
Description copied from interface:ConnectionProvider
Returns a builder to mutate properties of thisConnectionProvider
.- Specified by:
mutate
in interfaceConnectionProvider
- Returns:
- a builder to mutate properties of this
ConnectionProvider
-
name
Description copied from interface:ConnectionProvider
ReturnsConnectionProvider
name used for metrics.- Specified by:
name
in interfaceConnectionProvider
- Returns:
ConnectionProvider
name used for metrics
-
onChannel
public <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, EventLoopGroup group) Description copied from interface:LoopResources
Callback for aChannel
selection.- Specified by:
onChannel
in interfaceLoopResources
- Type Parameters:
CHANNEL
- theChannel
implementation- Parameters:
channelType
- the channel typegroup
- the sourceEventLoopGroup
to assign a loop from- Returns:
- a
Channel
instance
-
onChannelClass
public <CHANNEL extends Channel> Class<? extends CHANNEL> onChannelClass(Class<CHANNEL> channelType, EventLoopGroup group) Description copied from interface:LoopResources
Callback for aChannel
class selection.- Specified by:
onChannelClass
in interfaceLoopResources
- Type Parameters:
CHANNEL
- theChannel
implementation- Parameters:
channelType
- the channel typegroup
- the sourceEventLoopGroup
to assign a loop from- Returns:
- a
Channel
class
-
onClient
Description copied from interface:LoopResources
Callback for clientEventLoopGroup
creation.- Specified by:
onClient
in interfaceLoopResources
- Parameters:
useNative
- should use native group if current environment supports it- Returns:
- a new
EventLoopGroup
-
onServer
Description copied from interface:LoopResources
Callback for serverEventLoopGroup
creation, this is theEventLoopGroup
for the child channel.- Specified by:
onServer
in interfaceLoopResources
- Parameters:
useNative
- should use native group if current environment supports it- Returns:
- a new
EventLoopGroup
-
onServerSelect
Description copied from interface:LoopResources
Callback for server selectEventLoopGroup
creation, this is theEventLoopGroup
for the acceptor channel.- Specified by:
onServerSelect
in interfaceLoopResources
- Parameters:
useNative
- should use native group if current environment supports it- Returns:
- a new
EventLoopGroup
-
_dispose
protected void _dispose()Dispose underlying resources. -
_disposeLater
Dispose underlying resources in a listenable fashion. It is guaranteed that the disposal of the underlying LoopResources will not happen beforequietPeriod
is over. If a task is submitted during thequietPeriod
, it is guaranteed to be accepted and thequietPeriod
will start over.- Parameters:
quietPeriod
- the quiet period as described abovetimeout
- the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period- Returns:
- the Mono that represents the end of disposal
-
getOrCreateDefaultResolver
Safely checks whether a name resolver exists and proceed with a creation if it does not exist. The name resolver uses as an event loop group theLoopResources
that are configured. Guarantees that always one and the same instance is returned for a givenLoopResources
and if theLoopResources
is updated the name resolver is also updated.- Returns:
- an existing or new
AddressResolverGroup
-
getOrCreate
protected static <T extends TcpResources> T getOrCreate(AtomicReference<@Nullable T> ref, @Nullable LoopResources loops, @Nullable ConnectionProvider provider, BiFunction<LoopResources, ConnectionProvider, T> onNew, String name) Safely check if existing resource exist and proceed to update/cleanup if new resources references are passed.- Type Parameters:
T
- the reified type ofTcpResources
- Parameters:
ref
- the resources atomic referenceloops
- the eventual newLoopResources
provider
- the eventual newConnectionProvider
onNew
- aTcpResources
factoryname
- a name for resources- Returns:
- an existing or new
TcpResources
-