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.MeterRegistrarNested 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_LIFOFields 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
ConstructorsModifierConstructorDescriptionprotectedTcpResources(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 newConnectionon subscribe.booleandaemon()return true ifEventLoopGroupshould not be shutdown.voiddispose()This has aNOOPimplementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResourcesandConnectionProvider.This has aNOOPimplementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResourcesandConnectionProvider.disposeLater(Duration quietPeriod, Duration timeout) This has aNOOPimplementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResourcesandConnectionProvider.static voidShutdown the globalTcpResourceswithout resetting them, effectively cleaning up associated resources without creating new ones.Prepare to shutdown the globalTcpResourceswithout resetting them, effectively cleaning up associated resources without creating new ones.disposeLoopsAndConnectionsLater(Duration quietPeriod, Duration timeout) Prepare to shutdown the globalTcpResourceswithout resetting them, effectively cleaning up associated resources without creating new ones.voiddisposeWhen(SocketAddress remoteAddress) Dispose all connection pools for the specified remote address.static TcpResourcesget()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.booleanintReturns 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.Buildermutate()Returns a builder to mutate properties of thisConnectionProvider.@Nullable Stringname()ReturnsConnectionProvidername used for metrics.<CHANNEL extends Channel>
CHANNELonChannel(Class<CHANNEL> channelType, EventLoopGroup group) Callback for aChannelselection.onChannelClass(Class<CHANNEL> channelType, EventLoopGroup group) Callback for aChannelclass selection.onClient(boolean useNative) Callback for clientEventLoopGroupcreation.onServer(boolean useNative) Callback for serverEventLoopGroupcreation, this is theEventLoopGroupfor the child channel.onServerSelect(boolean useNative) Callback for server selectEventLoopGroupcreation, this is theEventLoopGroupfor the acceptor channel.static TcpResourcesreset()Reset TCP resources to default and return its instance.static TcpResourcesset(ConnectionProvider provider) Update pooling resources and return the global TCP resources.static TcpResourcesset(LoopResources loops) Update event loops resources and return the global TCP resources.
-
Constructor Details
-
TcpResources
-
-
Method Details
-
disposeLoopsAndConnections
public static void disposeLoopsAndConnections()Shutdown the globalTcpResourceswithout 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 globalTcpResourceswithout resetting them, effectively cleaning up associated resources without creating new ones. This only occurs when the returnedMonois subscribed to. The quiet period will be2sand the timeout will be15s- Returns:
- a
Monotriggering thedisposeLoopsAndConnections()when subscribed to.
-
disposeLoopsAndConnectionsLater
Prepare to shutdown the globalTcpResourceswithout resetting them, effectively cleaning up associated resources without creating new ones. This only occurs when the returnedMonois subscribed to. It is guaranteed that the disposal of the underlying LoopResources will not happen beforequietPeriodis over. If a task is submitted during thequietPeriod, it is guaranteed to be accepted and thequietPeriodwill 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
Monotriggering 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 previousConnectionProviderwill be disposed.- Parameters:
provider- a newConnectionProviderto replace the current- Returns:
- the global TCP resources
-
set
Update event loops resources and return the global TCP resources. Note: The previousLoopResourceswill be disposed.- Parameters:
loops- a newLoopResourcesto 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:ConnectionProviderReturn an existing or newConnectionon subscribe.- Specified by:
acquirein interfaceConnectionProvider- Parameters:
config- the transport configurationobserver- theConnectionObserverremoteAddress- theSocketAddressto connect toresolverGroup- the resolver which will resolve the address of the unresolved named address- Returns:
- an existing or new
MonoofConnection
-
daemon
public boolean daemon()Description copied from interface:LoopResourcesreturn true ifEventLoopGroupshould not be shutdown.- Specified by:
daemonin interfaceLoopResources- Returns:
- true if
EventLoopGroupshould not be shutdown
-
dispose
public void dispose()This has aNOOPimplementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResourcesandConnectionProvider. If a disposal of the global TCP resources is needed,disposeLoopsAndConnections()should be used instead.- Specified by:
disposein interfaceConnectionProvider- Specified by:
disposein interfaceDisposable- Specified by:
disposein interfaceLoopResources
-
disposeLater
This has aNOOPimplementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResourcesandConnectionProvider. If a disposal of the global TCP resources is needed,disposeLoopsAndConnectionsLater()should be used instead.- Specified by:
disposeLaterin interfaceConnectionProvider- Specified by:
disposeLaterin interfaceLoopResources- Returns:
- a Mono representing the completion of the ConnectionProvider disposal.
-
disposeLater
This has aNOOPimplementation by default in order to prevent unintended disposal of the global TCP resources which has a longer lifecycle than regularLoopResourcesandConnectionProvider. If a disposal of the global TCP resources is needed,disposeLoopsAndConnectionsLater(Duration, Duration)should be used instead.- Specified by:
disposeLaterin 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:
disposeWhenin interfaceConnectionProvider- Parameters:
remoteAddress- the remote address
-
isDisposed
public boolean isDisposed()- Specified by:
isDisposedin interfaceDisposable
-
maxConnections
public int maxConnections()Description copied from interface:ConnectionProviderReturns the maximum number of connections before starting pending.- Specified by:
maxConnectionsin interfaceConnectionProvider- Returns:
- the maximum number of connections before starting pending
-
maxConnectionsPerHost
Description copied from interface:ConnectionProviderReturns the maximum number of connections per host before starting pending.- Specified by:
maxConnectionsPerHostin interfaceConnectionProvider- Returns:
- the maximum number of connections per host before starting pending
-
mutate
Description copied from interface:ConnectionProviderReturns a builder to mutate properties of thisConnectionProvider.- Specified by:
mutatein interfaceConnectionProvider- Returns:
- a builder to mutate properties of this
ConnectionProvider
-
name
Description copied from interface:ConnectionProviderReturnsConnectionProvidername used for metrics.- Specified by:
namein interfaceConnectionProvider- Returns:
ConnectionProvidername used for metrics
-
onChannel
public <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, EventLoopGroup group) Description copied from interface:LoopResourcesCallback for aChannelselection.- Specified by:
onChannelin interfaceLoopResources- Type Parameters:
CHANNEL- theChannelimplementation- Parameters:
channelType- the channel typegroup- the sourceEventLoopGroupto assign a loop from- Returns:
- a
Channelinstance
-
onChannelClass
public <CHANNEL extends Channel> Class<? extends CHANNEL> onChannelClass(Class<CHANNEL> channelType, EventLoopGroup group) Description copied from interface:LoopResourcesCallback for aChannelclass selection.- Specified by:
onChannelClassin interfaceLoopResources- Type Parameters:
CHANNEL- theChannelimplementation- Parameters:
channelType- the channel typegroup- the sourceEventLoopGroupto assign a loop from- Returns:
- a
Channelclass
-
onClient
Description copied from interface:LoopResourcesCallback for clientEventLoopGroupcreation.- Specified by:
onClientin interfaceLoopResources- Parameters:
useNative- should use native group if current environment supports it- Returns:
- a new
EventLoopGroup
-
onServer
Description copied from interface:LoopResourcesCallback for serverEventLoopGroupcreation, this is theEventLoopGroupfor the child channel.- Specified by:
onServerin interfaceLoopResources- Parameters:
useNative- should use native group if current environment supports it- Returns:
- a new
EventLoopGroup
-
onServerSelect
Description copied from interface:LoopResourcesCallback for server selectEventLoopGroupcreation, this is theEventLoopGroupfor the acceptor channel.- Specified by:
onServerSelectin 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 beforequietPeriodis over. If a task is submitted during thequietPeriod, it is guaranteed to be accepted and thequietPeriodwill 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 theLoopResourcesthat are configured. Guarantees that always one and the same instance is returned for a givenLoopResourcesand if theLoopResourcesis 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 newLoopResourcesprovider- the eventual newConnectionProvideronNew- aTcpResourcesfactoryname- a name for resources- Returns:
- an existing or new
TcpResources
-