Package io.lettuce.core.resource
Class DefaultClientResources
- java.lang.Object
-
- io.lettuce.core.resource.DefaultClientResources
-
- All Implemented Interfaces:
ClientResources
public class DefaultClientResources extends Object implements ClientResources
Default instance of the client resources.The
DefaultClientResources
instance is stateful, you have to shutdown the instance if you're no longer using it.DefaultClientResources
allow to configure:- a
addressResolverGroup
that is a provided instance ofAddressResolverGroup
. - a
commandLatencyRecorder
which is a provided instance ofCommandLatencyRecorder
- a
dnsResolver
which is a provided instance ofDnsResolver
. - an
eventBus
which is a provided instance ofEventBus
. .
- the
ioThreadPoolSize
, alternatively - a
eventLoopGroupProvider
which is a provided instance ofEventLoopGroupProvider
. Higher precedence thanioThreadPoolSize
. - computationThreadPoolSize
- a
eventExecutorGroup
which is a provided instance ofEventExecutorGroup
. Higher precedence thancomputationThreadPoolSize
. - a
nettyCustomizer
that is a provided instance ofNettyCustomizer
. - a
socketAddressResolver
which is a provided instance ofSocketAddressResolver
. - a
threadFactoryProvider
to provide aThreadFactory
for default timer, event loop and event executor instances. - a
timer
that is a provided instance ofHashedWheelTimer
. - a
tracing
that is a provided instance ofTracing
.
- Since:
- 3.4
- Author:
- Mark Paluch, Yohei Ueki
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultClientResources.Builder
Builder forDefaultClientResources
.
-
Field Summary
Fields Modifier and Type Field Description static AddressResolverGroup<?>
DEFAULT_ADDRESS_RESOLVER_GROUP
DefaultAddressResolverGroup
.static int
DEFAULT_COMPUTATION_THREADS
static int
DEFAULT_IO_THREADS
static NettyCustomizer
DEFAULT_NETTY_CUSTOMIZER
Default (no-op)NettyCustomizer
.static Supplier<Delay>
DEFAULT_RECONNECT_DELAY
Default delaySupplier
forDelay.exponential()
delay.protected static InternalLogger
logger
static int
MIN_COMPUTATION_THREADS
Minimum number of computation threads.static int
MIN_IO_THREADS
Minimum number of I/O threads.
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultClientResources(DefaultClientResources.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AddressResolverGroup<?>
addressResolverGroup()
Return theAddressResolverGroup
instance for DNS resolution.static DefaultClientResources.Builder
builder()
Returns a newDefaultClientResources.Builder
to constructDefaultClientResources
.EventPublisherOptions
commandLatencyPublisherOptions()
Return theEventPublisherOptions
for latency event publishing.CommandLatencyRecorder
commandLatencyRecorder()
Return theCommandLatencyRecorder
.int
computationThreadPoolSize()
Return the pool size (number of threads) for all computation tasks.static DefaultClientResources
create()
Create a newDefaultClientResources
using default settings.DnsResolver
dnsResolver()
Return theDnsResolver
.EventBus
eventBus()
Return the event bus used to publish events.EventExecutorGroup
eventExecutorGroup()
Return the computation pool used for internal operations.EventLoopGroupProvider
eventLoopGroupProvider()
Return theEventLoopGroupProvider
that provides access to the particularevent loop groups
.protected void
finalize()
int
ioThreadPoolSize()
Return the pool size (number of threads) for IO threads.DefaultClientResources.Builder
mutate()
Returns a builder to create newDefaultClientResources
whose settings are replicated from the currentDefaultClientResources
.NettyCustomizer
nettyCustomizer()
Return theNettyCustomizer
to customize netty components.Delay
reconnectDelay()
Return theDelay
for reconnect attempts.Future<Boolean>
shutdown()
Shutdown theClientResources
.Future<Boolean>
shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)
Shutdown theClientResources
.SocketAddressResolver
socketAddressResolver()
Return theSocketAddressResolver
.Timer
timer()
Return theTimer
to schedule events.Tracing
tracing()
Return theTracing
instance to support tracing of Redis commands.
-
-
-
Field Detail
-
logger
protected static final InternalLogger logger
-
MIN_IO_THREADS
public static final int MIN_IO_THREADS
Minimum number of I/O threads.- See Also:
- Constant Field Values
-
MIN_COMPUTATION_THREADS
public static final int MIN_COMPUTATION_THREADS
Minimum number of computation threads.- See Also:
- Constant Field Values
-
DEFAULT_IO_THREADS
public static final int DEFAULT_IO_THREADS
-
DEFAULT_COMPUTATION_THREADS
public static final int DEFAULT_COMPUTATION_THREADS
-
DEFAULT_RECONNECT_DELAY
public static final Supplier<Delay> DEFAULT_RECONNECT_DELAY
Default delaySupplier
forDelay.exponential()
delay.
-
DEFAULT_NETTY_CUSTOMIZER
public static final NettyCustomizer DEFAULT_NETTY_CUSTOMIZER
Default (no-op)NettyCustomizer
.
-
DEFAULT_ADDRESS_RESOLVER_GROUP
public static final AddressResolverGroup<?> DEFAULT_ADDRESS_RESOLVER_GROUP
DefaultAddressResolverGroup
.
-
-
Constructor Detail
-
DefaultClientResources
protected DefaultClientResources(DefaultClientResources.Builder builder)
-
-
Method Detail
-
create
public static DefaultClientResources create()
Create a newDefaultClientResources
using default settings.- Returns:
- a new instance of a default client resources.
-
builder
public static DefaultClientResources.Builder builder()
Returns a newDefaultClientResources.Builder
to constructDefaultClientResources
.- Returns:
- a new
DefaultClientResources.Builder
to constructDefaultClientResources
.
-
mutate
public DefaultClientResources.Builder mutate()
Returns a builder to create newDefaultClientResources
whose settings are replicated from the currentDefaultClientResources
.Note: The resulting
DefaultClientResources
retains shared state forTimer
,CommandLatencyRecorder
,EventExecutorGroup
, andEventLoopGroupProvider
if these are left unchanged. Thus you need only to shut down the last createdClientResources
instances. Shutdown affects any previously createdClientResources
.- Specified by:
mutate
in interfaceClientResources
- Returns:
- a
DefaultClientResources.Builder
to create newDefaultClientResources
whose settings are replicated from the currentDefaultClientResources
. - Since:
- 5.1
-
finalize
protected void finalize() throws Throwable
-
shutdown
public Future<Boolean> shutdown()
Shutdown theClientResources
.- Specified by:
shutdown
in interfaceClientResources
- Returns:
- eventually the success/failure of the shutdown without errors.
-
shutdown
public Future<Boolean> shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)
Shutdown theClientResources
.- Specified by:
shutdown
in interfaceClientResources
- Parameters:
quietPeriod
- the quiet period as described in the documentationtimeout
- the maximum amount of time to wait until the executor is shutdown regardless if a task was submitted during the quiet periodtimeUnit
- the unit ofquietPeriod
andtimeout
- Returns:
- eventually the success/failure of the shutdown without errors.
-
commandLatencyRecorder
public CommandLatencyRecorder commandLatencyRecorder()
Description copied from interface:ClientResources
Return theCommandLatencyRecorder
.- Specified by:
commandLatencyRecorder
in interfaceClientResources
- Returns:
- the command latency recorder.
-
commandLatencyPublisherOptions
public EventPublisherOptions commandLatencyPublisherOptions()
Description copied from interface:ClientResources
Return theEventPublisherOptions
for latency event publishing.- Specified by:
commandLatencyPublisherOptions
in interfaceClientResources
- Returns:
- the
EventPublisherOptions
for latency event publishing.
-
computationThreadPoolSize
public int computationThreadPoolSize()
Description copied from interface:ClientResources
Return the pool size (number of threads) for all computation tasks.- Specified by:
computationThreadPoolSize
in interfaceClientResources
- Returns:
- the pool size (number of threads to use).
-
dnsResolver
public DnsResolver dnsResolver()
Description copied from interface:ClientResources
Return theDnsResolver
.- Specified by:
dnsResolver
in interfaceClientResources
- Returns:
- the DNS resolver.
-
eventBus
public EventBus eventBus()
Description copied from interface:ClientResources
Return the event bus used to publish events.- Specified by:
eventBus
in interfaceClientResources
- Returns:
- the event bus
-
eventLoopGroupProvider
public EventLoopGroupProvider eventLoopGroupProvider()
Description copied from interface:ClientResources
Return theEventLoopGroupProvider
that provides access to the particularevent loop groups
. lettuce requires at least two implementations:NioEventLoopGroup
for TCP/IP connections andEpollEventLoopGroup
for unix domain socket connections (epoll). You can useDefaultEventLoopGroupProvider
as default implementation or implement an ownEventLoopGroupProvider
to share existingEventLoopGroup's
with lettuce.- Specified by:
eventLoopGroupProvider
in interfaceClientResources
- Returns:
- the
EventLoopGroupProvider
which provides access to the particularevent loop groups
-
eventExecutorGroup
public EventExecutorGroup eventExecutorGroup()
Description copied from interface:ClientResources
Return the computation pool used for internal operations. Such tasks are periodic Redis Cluster and Redis Sentinel topology updates and scheduling of connection reconnection byConnectionWatchdog
.- Specified by:
eventExecutorGroup
in interfaceClientResources
- Returns:
- the computation pool used for internal operations
-
ioThreadPoolSize
public int ioThreadPoolSize()
Description copied from interface:ClientResources
Return the pool size (number of threads) for IO threads. The indicated size does not reflect the number for all IO threads. TCP and socket connections (epoll) require different IO pool.- Specified by:
ioThreadPoolSize
in interfaceClientResources
- Returns:
- the pool size (number of threads) for all IO tasks.
-
nettyCustomizer
public NettyCustomizer nettyCustomizer()
Description copied from interface:ClientResources
Return theNettyCustomizer
to customize netty components.- Specified by:
nettyCustomizer
in interfaceClientResources
- Returns:
- the configured
NettyCustomizer
.
-
reconnectDelay
public Delay reconnectDelay()
Description copied from interface:ClientResources
Return theDelay
for reconnect attempts. May return a different instance on each call.- Specified by:
reconnectDelay
in interfaceClientResources
- Returns:
- the reconnect
Delay
.
-
socketAddressResolver
public SocketAddressResolver socketAddressResolver()
Description copied from interface:ClientResources
Return theSocketAddressResolver
.- Specified by:
socketAddressResolver
in interfaceClientResources
- Returns:
- the socket address resolver.
-
timer
public Timer timer()
Description copied from interface:ClientResources
Return theTimer
to schedule events. A timer object may run single- or multi-threaded but must be used for scheduling of short-running jobs only. Long-running jobs should be scheduled and executed usingClientResources.eventExecutorGroup()
.- Specified by:
timer
in interfaceClientResources
- Returns:
- the timer.
-
tracing
public Tracing tracing()
Description copied from interface:ClientResources
Return theTracing
instance to support tracing of Redis commands.- Specified by:
tracing
in interfaceClientResources
- Returns:
- the configured
Tracing
.
-
addressResolverGroup
public AddressResolverGroup<?> addressResolverGroup()
Description copied from interface:ClientResources
Return theAddressResolverGroup
instance for DNS resolution.- Specified by:
addressResolverGroup
in interfaceClientResources
- Returns:
- the address resolver group.
-
-