public class TcpResources extends Object implements ConnectionProvider, LoopResources
ConnectionProvider.Builder, ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>, ConnectionProvider.HostSpecificSpec
Disposable.Composite, Disposable.Swap
DEFAULT_POOL_ACQUIRE_TIMEOUT, DEFAULT_POOL_LEASING_STRATEGY, DEFAULT_POOL_MAX_CONNECTIONS, DEFAULT_POOL_MAX_IDLE_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 Mono<Void> |
_disposeLater()
Deprecated.
as of 0.9.3. Use
_disposeLater(Duration, Duration) |
protected Mono<Void> |
_disposeLater(java.time.Duration quietPeriod,
java.time.Duration timeout)
Dispose underlying resources in a listenable fashion.
|
Mono<? extends Connection> |
acquire(Bootstrap bootstrap)
Return an existing or new
Connection on subscribe. |
boolean |
daemon()
return true if
EventLoopGroup should not be shutdown |
void |
dispose()
|
Mono<Void> |
disposeLater()
|
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(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(SocketAddress address) |
static TcpResources |
get()
Return the global HTTP resources for event loops and pooling
|
protected static <T extends TcpResources> |
getOrCreate(AtomicReference<T> ref,
LoopResources loops,
ConnectionProvider provider,
java.util.function.BiFunction<LoopResources,ConnectionProvider,T> onNew,
String name)
Safely check if existing resource exist and proceed to update/cleanup if new
resources references are passed.
|
boolean |
isDisposed() |
<CHANNEL extends Channel> |
onChannel(Class<CHANNEL> channelType,
EventLoopGroup group)
Callback for a
Channel selection. |
Class<? extends Channel> |
onChannel(EventLoopGroup group)
Callback for client or generic channel factory selection.
|
EventLoopGroup |
onClient(boolean useNative)
Callback for client
EventLoopGroup creation. |
Class<? extends DatagramChannel> |
onDatagramChannel(EventLoopGroup group)
Callback for UDP channel factory selection.
|
EventLoopGroup |
onServer(boolean useNative)
Callback for server
EventLoopGroup creation,
this is the EventLoopGroup for the child channel. |
Class<? extends ServerChannel> |
onServerChannel(EventLoopGroup group)
Callback for server channel factory selection.
|
EventLoopGroup |
onServerSelect(boolean useNative)
Callback for server select
EventLoopGroup creation,
this is the EventLoopGroup for the acceptor channel. |
boolean |
preferNative()
Return true if should default to native
EventLoopGroup and Channel |
static TcpResources |
reset()
Reset http resources to default and return its instance
|
static TcpResources |
set(ConnectionProvider provider)
Update provider resources and return the global HTTP resources
|
static TcpResources |
set(LoopResources loops)
Update pooling resources and return the global HTTP resources
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
builder, create, create, elastic, elastic, elastic, fixed, fixed, fixed, fixed, fixed, maxConnections, newConnection
colocate, create, create, create, disposeLater, hasNativeSupport
protected TcpResources(LoopResources defaultLoops, ConnectionProvider defaultProvider)
public static TcpResources get()
public static TcpResources set(ConnectionProvider provider)
public static TcpResources set(LoopResources loops)
public static TcpResources reset()
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 15s
Mono
triggering the disposeLoopsAndConnections()
when subscribed to.public static Mono<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 void dispose()
dispose
in interface Disposable
dispose
in interface ConnectionProvider
dispose
in interface LoopResources
public Mono<Void> disposeLater()
disposeLater
in interface ConnectionProvider
disposeLater
in interface LoopResources
protected void _dispose()
@Deprecated protected Mono<Void> _disposeLater()
_disposeLater(Duration, Duration)
2s
and the timeout will be 15s
protected Mono<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 periodpublic boolean isDisposed()
isDisposed
in interface Disposable
public void disposeWhen(@NonNull SocketAddress address)
disposeWhen
in interface ConnectionProvider
public Mono<? extends Connection> acquire(Bootstrap bootstrap)
ConnectionProvider
Connection
on subscribe.acquire
in interface ConnectionProvider
bootstrap
- the client connection Bootstrap
Mono
of Connection
public Class<? extends Channel> onChannel(EventLoopGroup group)
LoopResources
onChannel
in interface LoopResources
group
- the source EventLoopGroup
to assign a loop fromClass
target for the underlying Channel
factorypublic <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, 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 EventLoopGroup onClient(boolean useNative)
LoopResources
EventLoopGroup
creation.onClient
in interface LoopResources
useNative
- should use native group if current environment supports itEventLoopGroup
public Class<? extends DatagramChannel> onDatagramChannel(EventLoopGroup group)
LoopResources
onDatagramChannel
in interface LoopResources
group
- the source EventLoopGroup
to assign a loop fromClass
target for the underlying Channel
factorypublic 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 Class<? extends ServerChannel> onServerChannel(EventLoopGroup group)
LoopResources
onServerChannel
in interface LoopResources
group
- the source EventLoopGroup
to assign a loop fromClass
target for the underlying ServerChannel
factorypublic 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
public boolean preferNative()
LoopResources
EventLoopGroup
and Channel
preferNative
in interface LoopResources
EventLoopGroup
and Channel
public boolean daemon()
LoopResources
EventLoopGroup
should not be shutdowndaemon
in interface LoopResources
EventLoopGroup
should not be shutdownprotected static <T extends TcpResources> T getOrCreate(AtomicReference<T> ref, @Nullable LoopResources loops, @Nullable ConnectionProvider provider, java.util.function.BiFunction<LoopResources,ConnectionProvider,T> onNew, 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