public class TcpResources extends Object implements ConnectionProvider, LoopResources
ConnectionProvider.AllocationStrategy<A extends ConnectionProvider.AllocationStrategy<A>>, ConnectionProvider.Builder, ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>, ConnectionProvider.HostSpecificSpec, ConnectionProvider.MeterRegistrarDisposable.Composite, Disposable.SwapDEFAULT_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_LIFODEFAULT_IO_SELECT_COUNT, DEFAULT_IO_WORKER_COUNT, DEFAULT_NATIVE, DEFAULT_SHUTDOWN_QUIET_PERIOD, DEFAULT_SHUTDOWN_TIMEOUT| Modifier | Constructor and Description |
|---|---|
protected |
TcpResources(LoopResources defaultLoops,
ConnectionProvider defaultProvider) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_dispose()
Dispose underlying resources
|
protected Mono<Void> |
_disposeLater(Duration quietPeriod,
Duration timeout)
Dispose underlying resources in a listenable fashion.
|
Mono<? extends Connection> |
acquire(TransportConfig config,
ConnectionObserver observer,
Supplier<? extends SocketAddress> remoteAddress,
AddressResolverGroup<?> resolverGroup)
Return an existing or new
Connection on subscribe. |
boolean |
daemon()
return true if
EventLoopGroup should not be shutdown |
void |
dispose()
This has a
NOOP implementation by default in order to prevent unintended disposal of
the global TCP resources which has a longer lifecycle than regular LoopResources
and ConnectionProvider. |
Mono<Void> |
disposeLater()
This has a
NOOP implementation by default in order to prevent unintended disposal of
the global TCP resources which has a longer lifecycle than regular LoopResources
and ConnectionProvider. |
Mono<Void> |
disposeLater(Duration quietPeriod,
Duration timeout)
This has a
NOOP implementation by default in order to prevent unintended disposal of
the global TCP resources which has a longer lifecycle than regular LoopResources
and ConnectionProvider. |
static void |
disposeLoopsAndConnections()
Shutdown the global
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. |
static Mono<Void> |
disposeLoopsAndConnectionsLater()
Prepare to shutdown the global
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. |
static Mono<Void> |
disposeLoopsAndConnectionsLater(Duration quietPeriod,
Duration timeout)
Prepare to shutdown the global
TcpResources 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> |
getOrCreate(AtomicReference<T> ref,
LoopResources loops,
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<?> |
getOrCreateDefaultResolver()
Safely checks whether a name resolver exists and proceed with a creation if it does not exist.
|
boolean |
isDisposed() |
int |
maxConnections()
Returns the maximum number of connections before starting pending
|
Map<SocketAddress,Integer> |
maxConnectionsPerHost()
Returns the maximum number of connections per host before starting pending
|
ConnectionProvider.Builder |
mutate()
Returns a builder to mutate properties of this
ConnectionProvider |
String |
name()
Returns
ConnectionProvider name used for metrics |
<CHANNEL extends Channel> |
onChannel(Class<CHANNEL> channelType,
EventLoopGroup group)
Callback for a
Channel selection. |
<CHANNEL extends Channel> |
onChannelClass(Class<CHANNEL> channelType,
EventLoopGroup group)
Callback for a
Channel class selection. |
EventLoopGroup |
onClient(boolean useNative)
Callback for client
EventLoopGroup creation. |
EventLoopGroup |
onServer(boolean useNative)
Callback for server
EventLoopGroup creation,
this is the EventLoopGroup for the child channel. |
EventLoopGroup |
onServerSelect(boolean useNative)
Callback for server select
EventLoopGroup creation,
this is the EventLoopGroup 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, create, create, create, newConnectioncolocate, create, create, create, hasNativeSupportprotected TcpResources(LoopResources defaultLoops, ConnectionProvider defaultProvider)
public static void disposeLoopsAndConnections()
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones.
This method is NOT blocking. It is implemented as fire-and-forget.
Use disposeLoopsAndConnectionsLater() when you need to observe
the final status of the operation, combined with Mono.block()
if you need to synchronously wait for the underlying resources to be disposed.public static Mono<Void> disposeLoopsAndConnectionsLater()
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. This only
occurs when the returned Mono is subscribed to.
The quiet period will be 2s and the timeout will be 15sMono triggering the disposeLoopsAndConnections() when subscribed to.public static Mono<Void> disposeLoopsAndConnectionsLater(Duration quietPeriod, Duration timeout)
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. This only
occurs when the returned Mono is subscribed to.
It is guaranteed that the disposal of the underlying LoopResources will not happen before
quietPeriod is over. If a task is submitted during the quietPeriod,
it is guaranteed to be accepted and the quietPeriod will start over.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 periodMono triggering the disposeLoopsAndConnections() when subscribed to.public static TcpResources get()
public static TcpResources reset()
public static TcpResources set(ConnectionProvider provider)
ConnectionProvider will be disposed.provider - a new ConnectionProvider to replace the currentpublic static TcpResources set(LoopResources loops)
LoopResources will be disposed.loops - a new LoopResources to replace the currentpublic Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup)
ConnectionProviderConnection on subscribe.acquire in interface ConnectionProviderconfig - the transport configurationobserver - the ConnectionObserverremoteAddress - the SocketAddress to connect toresolverGroup - the resolver which will resolve the address of the unresolved named addressMono of Connectionpublic boolean daemon()
LoopResourcesEventLoopGroup should not be shutdowndaemon in interface LoopResourcesEventLoopGroup should not be shutdownpublic void dispose()
NOOP implementation by default in order to prevent unintended disposal of
the global TCP resources which has a longer lifecycle than regular LoopResources
and ConnectionProvider.
If a disposal of the global TCP resources is needed,
disposeLoopsAndConnections() should be used instead.dispose in interface Disposabledispose in interface ConnectionProviderdispose in interface LoopResourcespublic Mono<Void> disposeLater()
NOOP implementation by default in order to prevent unintended disposal of
the global TCP resources which has a longer lifecycle than regular LoopResources
and ConnectionProvider.
If a disposal of the global TCP resources is needed,
disposeLoopsAndConnectionsLater() should be used instead.disposeLater in interface ConnectionProviderdisposeLater in interface LoopResourcespublic Mono<Void> disposeLater(Duration quietPeriod, Duration timeout)
NOOP implementation by default in order to prevent unintended disposal of
the global TCP resources which has a longer lifecycle than regular LoopResources
and ConnectionProvider.
If a disposal of the global TCP resources is needed,
disposeLoopsAndConnectionsLater(Duration, Duration) should be used instead.disposeLater in interface LoopResourcesquietPeriod - 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 periodpublic void disposeWhen(SocketAddress remoteAddress)
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 to disposeLoopsAndConnections() than
to dispose()).
disposeWhen in interface ConnectionProviderremoteAddress - the remote addresspublic boolean isDisposed()
isDisposed in interface Disposablepublic int maxConnections()
ConnectionProvidermaxConnections in interface ConnectionProviderpublic Map<SocketAddress,Integer> maxConnectionsPerHost()
ConnectionProvidermaxConnectionsPerHost in interface ConnectionProviderpublic ConnectionProvider.Builder mutate()
ConnectionProviderConnectionProvidermutate in interface ConnectionProviderConnectionProviderpublic String name()
ConnectionProviderConnectionProvider name used for metricsname in interface ConnectionProviderConnectionProvider name used for metricspublic <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, EventLoopGroup group)
LoopResourcesChannel selection.onChannel in interface LoopResourcesCHANNEL - the Channel implementationchannelType - the channel typegroup - the source EventLoopGroup to assign a loop fromChannel instancepublic <CHANNEL extends Channel> Class<? extends CHANNEL> onChannelClass(Class<CHANNEL> channelType, EventLoopGroup group)
LoopResourcesChannel class selection.onChannelClass in interface LoopResourcesCHANNEL - the Channel implementationchannelType - the channel typegroup - the source EventLoopGroup to assign a loop fromChannel classpublic EventLoopGroup onClient(boolean useNative)
LoopResourcesEventLoopGroup creation.onClient in interface LoopResourcesuseNative - should use native group if current environment supports itEventLoopGrouppublic EventLoopGroup onServer(boolean useNative)
LoopResourcesEventLoopGroup creation,
this is the EventLoopGroup for the child channel.onServer in interface LoopResourcesuseNative - should use native group if current environment supports itEventLoopGrouppublic EventLoopGroup onServerSelect(boolean useNative)
LoopResourcesEventLoopGroup creation,
this is the EventLoopGroup for the acceptor channel.onServerSelect in interface LoopResourcesuseNative - should use native group if current environment supports itEventLoopGroupprotected void _dispose()
protected Mono<Void> _disposeLater(Duration quietPeriod, Duration timeout)
quietPeriod is over. If a task is submitted during the quietPeriod,
it is guaranteed to be accepted and the quietPeriod will start over.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 periodprotected AddressResolverGroup<?> getOrCreateDefaultResolver()
LoopResources that are configured.
Guarantees that always one and the same instance is returned for a given LoopResources
and if the LoopResources is updated the name resolver is also updated.AddressResolverGroupprotected static <T extends TcpResources> T getOrCreate(AtomicReference<T> ref, @Nullable LoopResources loops, @Nullable ConnectionProvider provider, BiFunction<LoopResources,ConnectionProvider,T> onNew, String name)
T - the reified type of TcpResourcesref - the resources atomic referenceloops - the eventual new LoopResourcesprovider - the eventual new ConnectionProvideronNew - a TcpResources factoryname - a name for resourcesTcpResources