Package io.lettuce.core.pubsub
Class PubSubCommandHandler<K,V>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.lettuce.core.protocol.CommandHandler
-
- io.lettuce.core.pubsub.PubSubCommandHandler<K,V>
-
- Type Parameters:
K
- Key type.V
- Value type.
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
public class PubSubCommandHandler<K,V> extends CommandHandler
A nettyChannelHandler
responsible for writing Redis Pub/Sub commands and reading the response stream from the server.PubSubCommandHandler
accounts for Pub/Sub message notification calling backPubSubEndpoint.notifyMessage(PubSubMessage)
. Redis responses can be interleaved in the sense that a response contains a Pub/Sub message first, then a command response. Possible interleave is introspected viaPubSubCommandHandler.ResponseHeaderReplayOutput
and decoding hooks.- Author:
- Will Glozer, Mark Paluch
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.lettuce.core.protocol.CommandHandler
CommandHandler.LifecycleState
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description PubSubCommandHandler(ClientOptions clientOptions, ClientResources clientResources, RedisCodec<K,V> codec, PubSubEndpoint<K,V> endpoint)
Initialize a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterDecode(ChannelHandlerContext ctx, RedisCommand<?,?,?> command)
Hook method called after command completion.protected boolean
canComplete(RedisCommand<?,?,?> command)
Decoding hook: Can the command be completed.protected boolean
canDecode(ByteBuf buffer)
Decoding hook: Can the buffer be decoded to a command.void
channelInactive(ChannelHandlerContext ctx)
protected void
complete(RedisCommand<?,?,?> command)
Decoding hook: Complete a command.protected void
decode(ChannelHandlerContext ctx, ByteBuf buffer)
protected CommandOutput<?,?,?>
getCommandOutput(RedisCommand<?,?,?> command)
Decoding hook: RetrieveCommandOutput
forRedisCommand
decoding.protected void
notifyPushListeners(PushMessage notification)
-
Methods inherited from class io.lettuce.core.protocol.CommandHandler
channelActive, channelRead, channelRegistered, channelUnregistered, decode, decode, drainQueue, exceptionCaught, getChannelId, getEndpoint, getStack, getState, isClosed, isPushDecode, setState, userEventTriggered, write
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelReadComplete, channelWritabilityChanged
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
-
-
-
Constructor Detail
-
PubSubCommandHandler
public PubSubCommandHandler(ClientOptions clientOptions, ClientResources clientResources, RedisCodec<K,V> codec, PubSubEndpoint<K,V> endpoint)
Initialize a new instance.- Parameters:
clientOptions
- client options for this connection, must not benull
clientResources
- client resources for this connectioncodec
- Codec.endpoint
- the Pub/Sub endpoint for Pub/Sub callback.
-
-
Method Detail
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
- Specified by:
channelInactive
in interfaceChannelInboundHandler
- Overrides:
channelInactive
in classCommandHandler
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.channelInactive(io.netty.channel.ChannelHandlerContext)
-
decode
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer) throws InterruptedException
- Overrides:
decode
in classCommandHandler
- Throws:
InterruptedException
-
canDecode
protected boolean canDecode(ByteBuf buffer)
Description copied from class:CommandHandler
Decoding hook: Can the buffer be decoded to a command.- Overrides:
canDecode
in classCommandHandler
- Returns:
-
canComplete
protected boolean canComplete(RedisCommand<?,?,?> command)
Description copied from class:CommandHandler
Decoding hook: Can the command be completed.- Overrides:
canComplete
in classCommandHandler
- Returns:
-
complete
protected void complete(RedisCommand<?,?,?> command)
Description copied from class:CommandHandler
Decoding hook: Complete a command.- Overrides:
complete
in classCommandHandler
- See Also:
RedisCommand.complete()
-
getCommandOutput
protected CommandOutput<?,?,?> getCommandOutput(RedisCommand<?,?,?> command)
Description copied from class:CommandHandler
Decoding hook: RetrieveCommandOutput
forRedisCommand
decoding.- Overrides:
getCommandOutput
in classCommandHandler
- Returns:
- See Also:
RedisCommand.getOutput()
-
notifyPushListeners
protected void notifyPushListeners(PushMessage notification)
- Overrides:
notifyPushListeners
in classCommandHandler
-
afterDecode
protected void afterDecode(ChannelHandlerContext ctx, RedisCommand<?,?,?> command)
Description copied from class:CommandHandler
Hook method called after command completion.- Overrides:
afterDecode
in classCommandHandler
-
-