K
- Key type.V
- Value type.@ChannelHandler.Sharable public class StatefulRedisPubSubConnectionImpl<K,V> extends StatefulRedisConnectionImpl<K,V> implements StatefulRedisPubSubConnection<K,V>
StatefulRedisPubSubConnectionImpl
A ConnectionWatchdog
monitors each connection and reconnects automatically until RedisChannelHandler.close()
is called. All
pending commands will be (re)sent after successful reconnection.ChannelHandler.Sharable
Modifier and Type | Field and Description |
---|---|
protected Set<K> |
channels |
protected List<RedisPubSubListener<K,V>> |
listeners |
protected Set<K> |
patterns |
async, codec, multi, reactive, sync
timeout, unit
Constructor and Description |
---|
StatefulRedisPubSubConnectionImpl(RedisChannelWriter<K,V> writer,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Initialize a new connection.
|
Modifier and Type | Method and Description |
---|---|
void |
activated()
Notification when the connection becomes active (connected).
|
void |
addListener(RedisPubSubListener<K,V> listener)
Add a new listener.
|
RedisPubSubAsyncCommands<K,V> |
async()
Returns the
RedisAsyncCommands API for the current connection. |
void |
channelRead(Object msg)
Invoked on a channel read.
|
<T,C extends RedisCommand<K,V,T>> |
dispatch(C command)
Dispatch a command.
|
protected RedisPubSubAsyncCommandsImpl<K,V> |
newRedisAsyncCommandsImpl()
Create a new instance of
RedisAsyncCommandsImpl . |
protected RedisPubSubReactiveCommandsImpl<K,V> |
newRedisReactiveCommandsImpl()
Create a new instance of
RedisReactiveCommandsImpl . |
protected RedisPubSubCommands<K,V> |
newRedisSyncCommandsImpl()
Create a new instance of
RedisCommands . |
protected void |
notifyListeners(PubSubOutput<K,V,V> output) |
RedisPubSubReactiveCommands<K,V> |
reactive()
Returns the
RedisReactiveCommands API for the current connection. |
void |
removeListener(RedisPubSubListener<K,V> listener)
Remove an existing listener.
|
protected List<RedisFuture<Void>> |
resubscribe()
Re-subscribe to all previously subscribed channels and patterns.
|
RedisPubSubCommands<K,V> |
sync()
Returns the
RedisCommands API for the current connection. |
isMulti, setClientName
addListener, channelRead, channelRegistered, close, deactivated, flushCommands, getChannelWriter, getOptions, getTimeout, getTimeoutUnit, isClosed, isOpen, registerCloseables, reset, setAutoFlushCommands, setOptions, setTimeout, syncHandler
channelActive, channelInactive, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isMulti
close, flushCommands, getOptions, getTimeout, getTimeoutUnit, isOpen, reset, setAutoFlushCommands, setTimeout
handlerAdded, handlerRemoved
protected final List<RedisPubSubListener<K,V>> listeners
public StatefulRedisPubSubConnectionImpl(RedisChannelWriter<K,V> writer, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
writer
- the channel writercodec
- Codec used to encode/decode keys and values.timeout
- Maximum time to wait for a response.unit
- Unit of time for the timeout.public void addListener(RedisPubSubListener<K,V> listener)
addListener
in interface StatefulRedisPubSubConnection<K,V>
listener
- Listener.public void removeListener(RedisPubSubListener<K,V> listener)
removeListener
in interface StatefulRedisPubSubConnection<K,V>
listener
- Listener.public RedisPubSubAsyncCommands<K,V> async()
StatefulRedisConnection
RedisAsyncCommands
API for the current connection. Does not create a new connection.async
in interface StatefulRedisConnection<K,V>
async
in interface StatefulRedisPubSubConnection<K,V>
async
in class StatefulRedisConnectionImpl<K,V>
protected RedisPubSubAsyncCommandsImpl<K,V> newRedisAsyncCommandsImpl()
StatefulRedisConnectionImpl
RedisAsyncCommandsImpl
. Can be overriden to extend.newRedisAsyncCommandsImpl
in class StatefulRedisConnectionImpl<K,V>
public RedisPubSubCommands<K,V> sync()
StatefulRedisConnection
RedisCommands
API for the current connection. Does not create a new connection.sync
in interface StatefulRedisConnection<K,V>
sync
in interface StatefulRedisPubSubConnection<K,V>
sync
in class StatefulRedisConnectionImpl<K,V>
protected RedisPubSubCommands<K,V> newRedisSyncCommandsImpl()
StatefulRedisConnectionImpl
RedisCommands
. Can be overriden to extend.newRedisSyncCommandsImpl
in class StatefulRedisConnectionImpl<K,V>
public RedisPubSubReactiveCommands<K,V> reactive()
StatefulRedisConnection
RedisReactiveCommands
API for the current connection. Does not create a new connection.reactive
in interface StatefulRedisConnection<K,V>
reactive
in interface StatefulRedisPubSubConnection<K,V>
reactive
in class StatefulRedisConnectionImpl<K,V>
protected RedisPubSubReactiveCommandsImpl<K,V> newRedisReactiveCommandsImpl()
StatefulRedisConnectionImpl
RedisReactiveCommandsImpl
. Can be overriden to extend.newRedisReactiveCommandsImpl
in class StatefulRedisConnectionImpl<K,V>
public void channelRead(Object msg)
RedisChannelHandler
channelRead
in class RedisChannelHandler<K,V>
msg
- channel messagepublic void activated()
RedisChannelHandler
activated
in class StatefulRedisConnectionImpl<K,V>
public <T,C extends RedisCommand<K,V,T>> C dispatch(C command)
StatefulConnection
dispatch
in interface StatefulConnection<K,V>
dispatch
in class StatefulRedisConnectionImpl<K,V>
T
- result typeC
- command typecommand
- the Redis commandprotected List<RedisFuture<Void>> resubscribe()
protected void notifyListeners(PubSubOutput<K,V,V> output)
Copyright © 2018 lettuce.io. All rights reserved.