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.
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 RedisAsyncConnectionImpl<K,V>> |
connectAsyncImpl(CommandHandler<K,V> handler,
T connection,
com.google.common.base.Supplier<SocketAddress> socketAddressSupplier) |
protected void |
connectionBuilder(CommandHandler<?,?> handler,
RedisChannelHandler<?,?> connection,
com.google.common.base.Supplier<SocketAddress> socketAddressSupplier,
ConnectionBuilder connectionBuilder,
RedisURI redisURI)
Populate connection builder with necessary resources.
|
protected int |
getChannelCount() |
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) |
void |
removeListener(RedisConnectionStateListener listener)
Removes a listener.
|
void |
setDefaultTimeout(long timeout,
TimeUnit unit)
Set the default timeout for
connections created by this client. |
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.
|
protected static <K,V> Object |
syncHandler(RedisChannelHandler<K,V> connection,
Class<?>... interfaceClasses) |
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 RedisAsyncConnectionImpl<K,V>> T connectAsyncImpl(CommandHandler<K,V> handler, T connection, com.google.common.base.Supplier<SocketAddress> socketAddressSupplier)
protected void connectionBuilder(CommandHandler<?,?> handler, RedisChannelHandler<?,?> connection, com.google.common.base.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)
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
protected int getResourceCount()
protected int getChannelCount()
protected static <K,V> Object syncHandler(RedisChannelHandler<K,V> connection, Class<?>... interfaceClasses)
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 clientpublic void setOptions(ClientOptions clientOptions)
ClientOptions
for the client.clientOptions
- client options for the client and connections that are created after setting the optionsCopyright © 2016. All rights reserved.