public abstract class AbstractRedisClient extends Object
ClientOptions
and the basic connection procedure. This
class creates the netty EventLoopGroup
s for NIO (NioEventLoopGroup
) and EPoll (
EpollEventLoopGroup
) with a default of Runtime.getRuntime().availableProcessors() * 4
threads. Reuse the instance as much as possible since the EventLoopGroup
instances are expensive and can consume a
huge part of your resources, if you create multiple instances.
You can set the number of threads per NioEventLoopGroup
by setting the io.netty.eventLoopThreads
system
property to a reasonable number of threads.
ClientResources
Modifier and Type | Field and Description |
---|---|
protected static PooledByteBufAllocator |
BUF_ALLOCATOR |
protected ChannelGroup |
channels |
protected ClientOptions |
clientOptions |
protected ClientResources |
clientResources |
protected Set<Closeable> |
closeableResources |
protected ConnectionEvents |
connectionEvents |
protected EventLoopGroup |
eventLoopGroup
Deprecated.
use map eventLoopGroups instead.
|
protected Map<Class<? extends EventLoopGroup>,EventLoopGroup> |
eventLoopGroups |
protected EventExecutorGroup |
genericWorkerPool |
protected static io.netty.util.internal.logging.InternalLogger |
logger |
protected long |
timeout |
protected HashedWheelTimer |
timer |
protected TimeUnit |
unit |
Modifier | Constructor and Description |
---|---|
protected |
AbstractRedisClient()
Deprecated.
|
protected |
AbstractRedisClient(ClientResources clientResources)
Create a new instance with client resources.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(RedisConnectionStateListener listener)
Add a listener for the RedisConnectionState.
|
protected void |
channelType(ConnectionBuilder connectionBuilder,
ConnectionPoint connectionPoint) |
protected <K,V,T extends RedisChannelHandler<K,V>> |
connectAsyncImpl(CommandHandler<K,V> handler,
T connection,
Supplier<SocketAddress> socketAddressSupplier) |
protected void |
connectionBuilder(CommandHandler<?,?> handler,
RedisChannelHandler<?,?> connection,
Supplier<SocketAddress> socketAddressSupplier,
ConnectionBuilder connectionBuilder,
RedisURI redisURI)
Populate connection builder with necessary resources.
|
protected int |
getChannelCount() |
protected <T> T |
getConnection(ConnectionFuture<T> connectionFuture)
Retrieve the connection from
ConnectionFuture . |
ClientOptions |
getOptions()
Returns the
ClientOptions which are valid for that client. |
protected int |
getResourceCount() |
protected <K,V,T extends RedisChannelHandler<K,V>> |
initializeChannel(ConnectionBuilder connectionBuilder)
Initialize the connection from
ConnectionBuilder . |
protected <K,V,T extends RedisChannelHandler<K,V>> |
initializeChannelAsync(ConnectionBuilder connectionBuilder)
Connect and initialize a channel from
ConnectionBuilder . |
void |
removeListener(RedisConnectionStateListener listener)
Removes a listener.
|
void |
setDefaultTimeout(long timeout,
TimeUnit unit)
Set the default timeout for
connections created by this client. |
protected void |
setOptions(ClientOptions clientOptions)
Set the
ClientOptions for the client. |
void |
shutdown()
Shutdown this client and close all open connections.
|
void |
shutdown(long quietPeriod,
long timeout,
TimeUnit timeUnit)
Shutdown this client and close all open connections.
|
CompletableFuture<Void> |
shutdownAsync()
Shutdown this client and close all open connections asynchronously.
|
CompletableFuture<Void> |
shutdownAsync(long quietPeriod,
long timeout,
TimeUnit timeUnit)
Shutdown this client and close all open connections asynchronously.
|
protected static final PooledByteBufAllocator BUF_ALLOCATOR
protected static final io.netty.util.internal.logging.InternalLogger logger
@Deprecated protected EventLoopGroup eventLoopGroup
protected EventExecutorGroup genericWorkerPool
protected final Map<Class<? extends EventLoopGroup>,EventLoopGroup> eventLoopGroups
protected final HashedWheelTimer timer
protected final ChannelGroup channels
protected final ClientResources clientResources
protected long timeout
protected TimeUnit unit
protected ConnectionEvents connectionEvents
protected volatile ClientOptions clientOptions
@Deprecated protected AbstractRedisClient()
AbstractRedisClient(ClientResources)
protected AbstractRedisClient(ClientResources clientResources)
clientResources
- the client resources. If null, the client will create a new dedicated instance of
client resources and keep track of them.public void setDefaultTimeout(long timeout, TimeUnit unit)
connections
created by this client. The timeout
applies to connection attempts and non-blocking commands.timeout
- Default connection timeout.unit
- Unit of time for the timeout.protected <K,V,T extends RedisChannelHandler<K,V>> T connectAsyncImpl(CommandHandler<K,V> handler, T connection, Supplier<SocketAddress> socketAddressSupplier)
protected void connectionBuilder(CommandHandler<?,?> handler, RedisChannelHandler<?,?> connection, Supplier<SocketAddress> socketAddressSupplier, ConnectionBuilder connectionBuilder, RedisURI redisURI)
handler
- instance of a CommandHandler for writing redis commandsconnection
- implementation of a RedisConnectionsocketAddressSupplier
- address supplier for initial connect and re-connectconnectionBuilder
- connection builder to configure the connectionredisURI
- URI of the Redis instanceprotected void channelType(ConnectionBuilder connectionBuilder, ConnectionPoint connectionPoint)
protected <K,V,T extends RedisChannelHandler<K,V>> T initializeChannel(ConnectionBuilder connectionBuilder)
ConnectionBuilder
.connectionBuilder
- must not be null.CompletableFuture
to synchronize the connection process.protected <T> T getConnection(ConnectionFuture<T> connectionFuture)
ConnectionFuture
. Performs a blocking ConnectionFuture.get()
to synchronize
the channel/connection initialization. Any exception is rethrown as RedisConnectionException
.T
- Connection type.connectionFuture
- must not be null.RedisConnectionException
- in case of connection failures.protected <K,V,T extends RedisChannelHandler<K,V>> ConnectionFuture<T> initializeChannelAsync(ConnectionBuilder connectionBuilder)
ConnectionBuilder
.connectionBuilder
- must not be null.ConnectionFuture
to synchronize the connection process.public void shutdown()
public void shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)
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 of quietPeriod
and timeout
public CompletableFuture<Void> shutdownAsync()
public CompletableFuture<Void> shutdownAsync(long quietPeriod, long timeout, TimeUnit timeUnit)
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 of quietPeriod
and timeout
protected int getResourceCount()
protected int getChannelCount()
public void addListener(RedisConnectionStateListener listener)
listener
- must not be nullpublic void removeListener(RedisConnectionStateListener listener)
listener
- must not be nullpublic ClientOptions getOptions()
ClientOptions
which are valid for that client. Connections inherit the current options at the moment
the connection is created. Changes to options will not affect existing connections.ClientOptions
for this clientprotected void setOptions(ClientOptions clientOptions)
ClientOptions
for the client.clientOptions
- client options for the client and connections that are created after setting the optionsCopyright © 2018 lettuce.io. All rights reserved.