Top Description Fields Constructors Methods
reactor.netty5.tcp

public Class TcpResources

extends Object
implements ConnectionProvider, LoopResources
Class Inheritance
All Implemented Interfaces
reactor.netty5.resources.LoopResources, reactor.core.Disposable, reactor.netty5.resources.ConnectionProvider
Imports
java.net.ProtocolFamily, .SocketAddress, java.time.Duration, java.util.Map, java.util.concurrent.atomic.AtomicReference, java.util.function.BiFunction, .Supplier, io.netty5.channel.Channel, .EventLoop, .EventLoopGroup, .ServerChannel, io.netty5.resolver.AddressResolverGroup, reactor.core.publisher.Mono, reactor.netty5.Connection, .ConnectionObserver, reactor.netty5.resources.ConnectionProvider, .LoopResources, reactor.netty5.transport.NameResolverProvider, .TransportConfig, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable

Hold the default Tcp resources
Author
Stephane Maldini
Since
0.6

Field Summary

Modifier and TypeField and Description
pack-priv static final NameResolverProvider
pack-priv final LoopResources
pack-priv final ConnectionProvider
pack-priv final AtomicReference<AddressResolverGroup<?>>
pack-priv static final Logger
pack-priv static final BiFunction<LoopResources, ConnectionProvider, TcpResources>
pack-priv static final AtomicReference<TcpResources>

Constructor Summary

AccessConstructor and Description
protected
TcpResources(LoopResources defaultLoops, ConnectionProvider defaultProvider)

Method Summary

Modifier and TypeMethod and Description
protected void
_dispose()

Dispose underlying resources

protected Mono<Void>

Returns:

the Mono that represents the end of disposal
_disposeLater
(Duration
the quiet period as described above
quietPeriod
,
Duration
the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period
timeout
)

Dispose underlying resources in a listenable fashion.

pack-priv void
pack-priv Mono<Void>
public Mono<? extends Connection>
acquire(TransportConfig
the transport configuration
config
,
ConnectionObserver observer, Supplier<? extends SocketAddress>
the SocketAddress to connect to
remoteAddress
,
AddressResolverGroup<?>
the resolver which will resolve the address of the unresolved named address
resolverGroup
)

Implements reactor.netty5.resources.ConnectionProvider.acquire.

Return an existing or new Connection on subscribe.
pack-priv static <T extends TcpResources> T
public boolean
daemon()

Overrides default reactor.netty5.resources.LoopResources.daemon.

return true if EventLoopGroup should not be shutdown
public void
dispose()

Overrides default reactor.netty5.resources.ConnectionProvider.dispose, reactor.netty5.resources.LoopResources.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.
public Mono<Void>
disposeLater()

Overrides default reactor.netty5.resources.ConnectionProvider.disposeLater, reactor.netty5.resources.LoopResources.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.
public Mono<Void>
disposeLater(Duration
the quiet period as described above
quietPeriod
,
Duration
the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period
timeout
)

Overrides default reactor.netty5.resources.LoopResources.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.
public static void
disposeLoopsAndConnections()

Shutdown the global TcpResources without resetting them, effectively cleaning up associated resources without creating new ones.

public static Mono<Void>

Returns:

a Mono triggering the disposeLoopsAndConnections() when subscribed to.
disposeLoopsAndConnectionsLater
()

Prepare to shutdown the global TcpResources without resetting them, effectively cleaning up associated resources without creating new ones.

public static Mono<Void>

Returns:

a Mono triggering the disposeLoopsAndConnections() when subscribed to.
disposeLoopsAndConnectionsLater
(Duration
the quiet period as described above
quietPeriod
,
Duration
the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period
timeout
)

Prepare to shutdown the global TcpResources without resetting them, effectively cleaning up associated resources without creating new ones.

public void
disposeWhen(SocketAddress
the remote address
remoteAddress
)

Overrides default reactor.netty5.resources.ConnectionProvider.disposeWhen.

Dispose all connection pools for the specified remote address.
public static TcpResources

Returns:

the global TCP resources for event loops and pooling
get
()

Return the global TCP resources for event loops and pooling

protected static <
the reified type of TcpResources
T extends TcpResources
>
T

Returns:

an existing or new TcpResources
getOrCreate
(AtomicReference<T>
the resources atomic reference
ref
,
LoopResources
the eventual new LoopResources
loops
,
ConnectionProvider
the eventual new ConnectionProvider
provider
,
BiFunction<LoopResources, ConnectionProvider, T>
a TcpResources factory
onNew
,
String
a name for resources
name
)

Safely check if existing resource exist and proceed to update/cleanup if new resources references are passed.

protected AddressResolverGroup<?>

Returns:

an existing or new AddressResolverGroup
getOrCreateDefaultResolver
()

Safely checks whether a name resolver exists and proceed with a creation if it does not exist.

public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public int
maxConnections()

Overrides default reactor.netty5.resources.ConnectionProvider.maxConnections.

Returns the maximum number of connections before starting pending
public Map<SocketAddress, Integer>
maxConnectionsPerHost()

Overrides default reactor.netty5.resources.ConnectionProvider.maxConnectionsPerHost.

Returns the maximum number of connections per host before starting pending
public ConnectionProvider.Builder
mutate()

Overrides default reactor.netty5.resources.ConnectionProvider.mutate.

Returns a builder to mutate properties of this ConnectionProvider
public String
name()

Overrides default reactor.netty5.resources.ConnectionProvider.name.

Returns ConnectionProvider name used for metrics
public <CHANNEL extends Channel> CHANNEL
onChannel(Class<CHANNEL>
the channel type
channelType
,
EventLoop
the EventLoop to assign
eventLoop
,
ProtocolFamily
the configured ProtocolFamily to run with
protocolFamily
)

Overrides default reactor.netty5.resources.LoopResources.onChannel.

Callback for a Channel selection.
public EventLoopGroup
onClient(boolean
should use native group if current environment supports it
useNative
)

Overrides default reactor.netty5.resources.LoopResources.onClient.

Callback for client EventLoopGroup creation.
public EventLoopGroup
onServer(boolean
should use native group if current environment supports it
useNative
)

Implements reactor.netty5.resources.LoopResources.onServer.

Callback for server EventLoopGroup creation, this is the EventLoopGroup for the child channel.
public <SERVERCHANNEL extends ServerChannel> SERVERCHANNEL
onServerChannel(Class<SERVERCHANNEL>
the channel type
channelType
,
EventLoop
the EventLoop to assign
eventLoop
,
EventLoopGroup
the EventLoop to assign for child Channel
childEventLoopGroup
,
ProtocolFamily
the configured ProtocolFamily to run with
protocolFamily
)

Overrides default reactor.netty5.resources.LoopResources.onServerChannel.

Callback for a Channel selection.
public EventLoopGroup
onServerSelect(boolean
should use native group if current environment supports it
useNative
)

Overrides default reactor.netty5.resources.LoopResources.onServerSelect.

Callback for server select EventLoopGroup creation, this is the EventLoopGroup for the acceptor channel.
public static TcpResources

Returns:

the global TCP resources
reset
()

Reset TCP resources to default and return its instance

public static TcpResources

Returns:

the global TCP resources
set
(ConnectionProvider
a new ConnectionProvider to replace the current
provider
)

Update pooling resources and return the global TCP resources.

public static TcpResources

Returns:

the global TCP resources
set
(LoopResources
a new LoopResources to replace the current
loops
)

Update event loops resources and return the global TCP resources.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_NAME_RESOLVER_PROVIDERback to summary
pack-priv static final NameResolverProvider DEFAULT_NAME_RESOLVER_PROVIDER
defaultLoopsback to summary
pack-priv final LoopResources defaultLoops
defaultProviderback to summary
pack-priv final ConnectionProvider defaultProvider
defaultResolverback to summary
pack-priv final AtomicReference<AddressResolverGroup<?>> defaultResolver
logback to summary
pack-priv static final Logger log
ON_TCP_NEWback to summary
pack-priv static final BiFunction<LoopResources, ConnectionProvider, TcpResources> ON_TCP_NEW
tcpResourcesback to summary
pack-priv static final AtomicReference<TcpResources> tcpResources

Constructor Detail

TcpResourcesback to summary
protected TcpResources(LoopResources defaultLoops, ConnectionProvider defaultProvider)

Method Detail

_disposeback to summary
protected void _dispose()

Dispose underlying resources

_disposeLaterback to summary
protected Mono<Void> _disposeLater(Duration quietPeriod, Duration timeout)

Dispose underlying resources in a listenable fashion. 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.

Parameters
quietPeriod:Duration

the quiet period as described above

timeout:Duration

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:Mono<Void>

the Mono that represents the end of disposal

_disposeResolverback to summary
pack-priv void _disposeResolver()
_disposeResolverLaterback to summary
pack-priv Mono<Void> _disposeResolverLater()
acquireback to summary
public Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, Supplier<? extends SocketAddress> remoteAddress, AddressResolverGroup<?> resolverGroup)

Implements reactor.netty5.resources.ConnectionProvider.acquire.

Doc from reactor.netty5.resources.ConnectionProvider.acquire.

Return an existing or new Connection on subscribe.

Parameters
config:TransportConfig

the transport configuration

observer:ConnectionObserver

the ConnectionObserver

remoteAddress:Supplier<? extends SocketAddress>

the SocketAddress to connect to

resolverGroup:AddressResolverGroup<?>

the resolver which will resolve the address of the unresolved named address

Returns:Mono<? extends Connection>

an existing or new Mono of Connection

Annotations
@Override
createback to summary
pack-priv static <T extends TcpResources> T create(T previous, LoopResources loops, ConnectionProvider provider, String name, BiFunction<LoopResources, ConnectionProvider, T> onNew)
daemonback to summary
public boolean daemon()

Overrides default reactor.netty5.resources.LoopResources.daemon.

Doc from reactor.netty5.resources.LoopResources.daemon.

return true if EventLoopGroup should not be shutdown

Returns:boolean

true if EventLoopGroup should not be shutdown

Annotations
@Override
disposeback to summary
public void dispose()

Overrides default reactor.netty5.resources.ConnectionProvider.dispose, reactor.netty5.resources.LoopResources.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. If a disposal of the global TCP resources is needed, disposeLoopsAndConnections() should be used instead.

Annotations
@Override
disposeLaterback to summary
public Mono<Void> disposeLater()

Overrides default reactor.netty5.resources.ConnectionProvider.disposeLater, reactor.netty5.resources.LoopResources.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. If a disposal of the global TCP resources is needed, disposeLoopsAndConnectionsLater() should be used instead.

Returns:Mono<Void>

Doc from reactor.netty5.resources.ConnectionProvider.disposeLater.

a Mono representing the completion of the ConnectionProvider disposal.

Annotations
@Override
disposeLaterback to summary
public Mono<Void> disposeLater(Duration quietPeriod, Duration timeout)

Overrides default reactor.netty5.resources.LoopResources.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. If a disposal of the global TCP resources is needed, disposeLoopsAndConnectionsLater(Duration, Duration) should be used instead.

Parameters
quietPeriod:Duration

Doc from reactor.netty5.resources.LoopResources.disposeLater.

the quiet period as described above

timeout:Duration

Doc from reactor.netty5.resources.LoopResources.disposeLater.

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:Mono<Void>

Doc from reactor.netty5.resources.LoopResources.disposeLater.

a Mono representing the completion of the LoopResources disposal.

Annotations
@Override
disposeLoopsAndConnectionsback to summary
public static void disposeLoopsAndConnections()

Shutdown the global 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.

disposeLoopsAndConnectionsLaterback to summary
public static Mono<Void> disposeLoopsAndConnectionsLater()

Prepare to shutdown the global 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

Returns:Mono<Void>

a Mono triggering the disposeLoopsAndConnections() when subscribed to.

disposeLoopsAndConnectionsLaterback to summary
public 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. 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.

Parameters
quietPeriod:Duration

the quiet period as described above

timeout:Duration

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:Mono<Void>

a Mono triggering the disposeLoopsAndConnections() when subscribed to.

Since
0.9.3
disposeWhenback to summary
public void disposeWhen(SocketAddress remoteAddress)

Overrides default reactor.netty5.resources.ConnectionProvider.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 to disposeLoopsAndConnections() than to dispose()).

Parameters
remoteAddress:SocketAddress

the remote address

Annotations
@Override
getback to summary
public static TcpResources get()

Return the global TCP resources for event loops and pooling

Returns:TcpResources

the global TCP resources for event loops and pooling

getOrCreateback to summary
protected static <T extends TcpResources> T 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.

Parameters
<T>
the reified type of TcpResources
ref:AtomicReference<T>

the resources atomic reference

loops:LoopResources

the eventual new LoopResources

provider:ConnectionProvider

the eventual new ConnectionProvider

onNew:BiFunction<LoopResources, ConnectionProvider, T>

a TcpResources factory

name:String

a name for resources

Returns:T

an existing or new TcpResources

getOrCreateDefaultResolverback to summary
protected AddressResolverGroup<?> 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 the 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.

Returns:AddressResolverGroup<?>

an existing or new AddressResolverGroup

isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
maxConnectionsback to summary
public int maxConnections()

Overrides default reactor.netty5.resources.ConnectionProvider.maxConnections.

Doc from reactor.netty5.resources.ConnectionProvider.maxConnections.

Returns the maximum number of connections before starting pending

Returns:int

the maximum number of connections before starting pending

Annotations
@Override
maxConnectionsPerHostback to summary
public Map<SocketAddress, Integer> maxConnectionsPerHost()

Overrides default reactor.netty5.resources.ConnectionProvider.maxConnectionsPerHost.

Doc from reactor.netty5.resources.ConnectionProvider.maxConnectionsPerHost.

Returns the maximum number of connections per host before starting pending

Returns:Map<SocketAddress, Integer>

the maximum number of connections per host before starting pending

Annotations
@Override
mutateback to summary
public ConnectionProvider.Builder mutate()

Overrides default reactor.netty5.resources.ConnectionProvider.mutate.

Doc from reactor.netty5.resources.ConnectionProvider.mutate.

Returns a builder to mutate properties of this ConnectionProvider

Returns:ConnectionProvider.Builder

a builder to mutate properties of this ConnectionProvider

Annotations
@Override
nameback to summary
public String name()

Overrides default reactor.netty5.resources.ConnectionProvider.name.

Doc from reactor.netty5.resources.ConnectionProvider.name.

Returns ConnectionProvider name used for metrics

Returns:String

ConnectionProvider name used for metrics

Annotations
@Override
onChannelback to summary
public <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, EventLoop eventLoop, ProtocolFamily protocolFamily)

Overrides default reactor.netty5.resources.LoopResources.onChannel.

Doc from reactor.netty5.resources.LoopResources.onChannel.

Callback for a Channel selection.

Parameters
<CHANNEL>
the Channel implementation
channelType:Class<CHANNEL>

the channel type

eventLoop:EventLoop

the EventLoop to assign

protocolFamily:ProtocolFamily

the configured ProtocolFamily to run with

Returns:CHANNEL

a Channel instance

Annotations
@Override
onClientback to summary
public EventLoopGroup onClient(boolean useNative)

Overrides default reactor.netty5.resources.LoopResources.onClient.

Doc from reactor.netty5.resources.LoopResources.onClient.

Callback for client EventLoopGroup creation.

Parameters
useNative:boolean

should use native group if current environment supports it

Returns:EventLoopGroup

a new EventLoopGroup

Annotations
@Override
onServerback to summary
public EventLoopGroup onServer(boolean useNative)

Implements reactor.netty5.resources.LoopResources.onServer.

Doc from reactor.netty5.resources.LoopResources.onServer.

Callback for server EventLoopGroup creation, this is the EventLoopGroup for the child channel.

Parameters
useNative:boolean

should use native group if current environment supports it

Returns:EventLoopGroup

a new EventLoopGroup

Annotations
@Override
onServerChannelback to summary
public <SERVERCHANNEL extends ServerChannel> SERVERCHANNEL onServerChannel(Class<SERVERCHANNEL> channelType, EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ProtocolFamily protocolFamily)

Overrides default reactor.netty5.resources.LoopResources.onServerChannel.

Doc from reactor.netty5.resources.LoopResources.onServerChannel.

Callback for a Channel selection.

Parameters
<SERVERCHANNEL>
the ServerChannel implementation
channelType:Class<SERVERCHANNEL>

the channel type

eventLoop:EventLoop

the EventLoop to assign

childEventLoopGroup:EventLoopGroup

the EventLoop to assign for child Channel

protocolFamily:ProtocolFamily

the configured ProtocolFamily to run with

Returns:SERVERCHANNEL

a ServerChannel instance

Annotations
@Override
onServerSelectback to summary
public EventLoopGroup onServerSelect(boolean useNative)

Overrides default reactor.netty5.resources.LoopResources.onServerSelect.

Doc from reactor.netty5.resources.LoopResources.onServerSelect.

Callback for server select EventLoopGroup creation, this is the EventLoopGroup for the acceptor channel.

Parameters
useNative:boolean

should use native group if current environment supports it

Returns:EventLoopGroup

a new EventLoopGroup

Annotations
@Override
resetback to summary
public static TcpResources reset()

Reset TCP resources to default and return its instance

Returns:TcpResources

the global TCP resources

setback to summary
public static TcpResources set(ConnectionProvider provider)

Update pooling resources and return the global TCP resources.

Note

The previous ConnectionProvider will be disposed.

Parameters
provider:ConnectionProvider

a new ConnectionProvider to replace the current

Returns:TcpResources

the global TCP resources

setback to summary
public static TcpResources set(LoopResources loops)

Update event loops resources and return the global TCP resources.

Note

The previous LoopResources will be disposed.

Parameters
loops:LoopResources

a new LoopResources to replace the current

Returns:TcpResources

the global TCP resources