public class TcpResources extends java.lang.Object implements ConnectionProvider, LoopResources
ConnectionProvider.Builder, ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>, ConnectionProvider.HostSpecificSpec, ConnectionProvider.MeterRegistrar
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
DEFAULT_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 reactor.core.publisher.Mono<java.lang.Void> |
_disposeLater(java.time.Duration quietPeriod,
java.time.Duration timeout)
Dispose underlying resources in a listenable fashion.
|
reactor.core.publisher.Mono<? extends Connection> |
acquire(TransportConfig config,
ConnectionObserver observer,
java.util.function.Supplier<? extends java.net.SocketAddress> remoteAddress,
io.netty.resolver.AddressResolverGroup<?> resolverGroup)
Return an existing or new
Connection on subscribe. |
boolean |
daemon()
return true if
EventLoopGroup should not be shutdown |
void |
dispose()
|
reactor.core.publisher.Mono<java.lang.Void> |
disposeLater()
|
static void |
disposeLoopsAndConnections()
Shutdown the global
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. |
static reactor.core.publisher.Mono<java.lang.Void> |
disposeLoopsAndConnectionsLater()
Prepare to shutdown the global
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. |
static reactor.core.publisher.Mono<java.lang.Void> |
disposeLoopsAndConnectionsLater(java.time.Duration quietPeriod,
java.time.Duration timeout)
Prepare to shutdown the global
TcpResources without resetting them,
effectively cleaning up associated resources without creating new ones. |
void |
disposeWhen(java.net.SocketAddress address) |
static TcpResources |
get()
Return the global TCP resources for event loops and pooling
|
protected static <T extends TcpResources> |
getOrCreate(java.util.concurrent.atomic.AtomicReference<T> ref,
LoopResources loops,
ConnectionProvider provider,
java.util.function.BiFunction<LoopResources,ConnectionProvider,T> onNew,
java.lang.String name)
Safely check if existing resource exist and proceed to update/cleanup if new
resources references are passed.
|
boolean |
isDisposed() |
int |
maxConnections()
Returns the maximum number of connections before starting pending
|
java.util.Map<java.net.SocketAddress,java.lang.Integer> |
maxConnectionsPerHost()
Returns the maximum number of connections per host before starting pending
|
<CHANNEL extends io.netty.channel.Channel> |
onChannel(java.lang.Class<CHANNEL> channelType,
io.netty.channel.EventLoopGroup group)
Callback for a
Channel selection. |
<CHANNEL extends io.netty.channel.Channel> |
onChannelClass(java.lang.Class<CHANNEL> channelType,
io.netty.channel.EventLoopGroup group)
Callback for a
Channel class selection. |
io.netty.channel.EventLoopGroup |
onClient(boolean useNative)
Callback for client
EventLoopGroup creation. |
io.netty.channel.EventLoopGroup |
onServer(boolean useNative)
Callback for server
EventLoopGroup creation,
this is the EventLoopGroup for the child channel. |
io.netty.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, wait
builder, create, create, newConnection
colocate, create, create, create, disposeLater, hasNativeSupport
protected 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 reactor.core.publisher.Mono<java.lang.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 15s
Mono
triggering the disposeLoopsAndConnections()
when subscribed to.public static reactor.core.publisher.Mono<java.lang.Void> disposeLoopsAndConnectionsLater(java.time.Duration quietPeriod, java.time.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 reactor.core.publisher.Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, @Nullable java.util.function.Supplier<? extends java.net.SocketAddress> remoteAddress, @Nullable io.netty.resolver.AddressResolverGroup<?> resolverGroup)
ConnectionProvider
Connection
on subscribe.acquire
in interface ConnectionProvider
config
- the transport configurationobserver
- the ConnectionObserver
remoteAddress
- the SocketAddress
to connect toresolverGroup
- the resolver which will resolve the address of the unresolved named addressMono
of Connection
public boolean daemon()
LoopResources
EventLoopGroup
should not be shutdowndaemon
in interface LoopResources
EventLoopGroup
should not be shutdownpublic void dispose()
dispose
in interface reactor.core.Disposable
dispose
in interface ConnectionProvider
dispose
in interface LoopResources
public reactor.core.publisher.Mono<java.lang.Void> disposeLater()
disposeLater
in interface ConnectionProvider
disposeLater
in interface LoopResources
public void disposeWhen(java.net.SocketAddress address)
disposeWhen
in interface ConnectionProvider
public boolean isDisposed()
isDisposed
in interface reactor.core.Disposable
public int maxConnections()
ConnectionProvider
maxConnections
in interface ConnectionProvider
public java.util.Map<java.net.SocketAddress,java.lang.Integer> maxConnectionsPerHost()
ConnectionProvider
maxConnectionsPerHost
in interface ConnectionProvider
public <CHANNEL extends io.netty.channel.Channel> CHANNEL onChannel(java.lang.Class<CHANNEL> channelType, io.netty.channel.EventLoopGroup group)
LoopResources
Channel
selection.onChannel
in interface LoopResources
CHANNEL
- the Channel
implementationchannelType
- the channel typegroup
- the source EventLoopGroup
to assign a loop fromChannel
instancepublic <CHANNEL extends io.netty.channel.Channel> java.lang.Class<? extends CHANNEL> onChannelClass(java.lang.Class<CHANNEL> channelType, io.netty.channel.EventLoopGroup group)
LoopResources
Channel
class selection.onChannelClass
in interface LoopResources
CHANNEL
- the Channel
implementationchannelType
- the channel typegroup
- the source EventLoopGroup
to assign a loop fromChannel
classpublic io.netty.channel.EventLoopGroup onClient(boolean useNative)
LoopResources
EventLoopGroup
creation.onClient
in interface LoopResources
useNative
- should use native group if current environment supports itEventLoopGroup
public io.netty.channel.EventLoopGroup onServer(boolean useNative)
LoopResources
EventLoopGroup
creation,
this is the EventLoopGroup
for the child channel.onServer
in interface LoopResources
useNative
- should use native group if current environment supports itEventLoopGroup
public io.netty.channel.EventLoopGroup onServerSelect(boolean useNative)
LoopResources
EventLoopGroup
creation,
this is the EventLoopGroup
for the acceptor channel.onServerSelect
in interface LoopResources
useNative
- should use native group if current environment supports itEventLoopGroup
protected void _dispose()
protected reactor.core.publisher.Mono<java.lang.Void> _disposeLater(java.time.Duration quietPeriod, java.time.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 static <T extends TcpResources> T getOrCreate(java.util.concurrent.atomic.AtomicReference<T> ref, @Nullable LoopResources loops, @Nullable ConnectionProvider provider, java.util.function.BiFunction<LoopResources,ConnectionProvider,T> onNew, java.lang.String name)
T
- the reified type of TcpResources
ref
- the resources atomic referenceloops
- the eventual new LoopResources
provider
- the eventual new ConnectionProvider
onNew
- a TcpResources
factoryname
- a name for resourcesTcpResources