java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.lettuce.core.protocol.CommandHandler
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
- Direct Known Subclasses:
PubSubCommandHandler
public class CommandHandler extends ChannelDuplexHandler
A netty
ChannelHandler responsible for writing redis commands and reading responses from the server.- Author:
- Will Glozer, Mark Paluch, Jongyeol Choi, Grzegorz Szpak, Daniel Albuquerque, Gavin Cook, Anuraag Agrawal
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandHandler.LifecycleStateNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
Constructors Constructor Description CommandHandler(ClientOptions clientOptions, ClientResources clientResources, Endpoint endpoint)Initialize a new instance that handles commands from the supplied queue. -
Method Summary
Modifier and Type Method Description protected voidafterDecode(ChannelHandlerContext ctx, RedisCommand<?,?,?> command)Hook method called after command completion.protected booleancanComplete(RedisCommand<?,?,?> command)Decoding hook: Can the command be completed.protected booleancanDecode(ByteBuf buffer)Decoding hook: Can the buffer be decoded to a command.voidchannelActive(ChannelHandlerContext ctx)voidchannelInactive(ChannelHandlerContext ctx)voidchannelRead(ChannelHandlerContext ctx, Object msg)voidchannelRegistered(ChannelHandlerContext ctx)voidchannelUnregistered(ChannelHandlerContext ctx)protected voidcomplete(RedisCommand<?,?,?> command)Decoding hook: Complete a command.protected booleandecode(ByteBuf buffer, CommandOutput<?,?,?> output)protected booleandecode(ByteBuf buffer, RedisCommand<?,?,?> command, CommandOutput<?,?,?> output)protected voiddecode(ChannelHandlerContext ctx, ByteBuf buffer)Collection<RedisCommand<?,?,?>>drainQueue()voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause)StringgetChannelId()protected CommandOutput<?,?,?>getCommandOutput(RedisCommand<?,?,?> command)Decoding hook: RetrieveCommandOutputforRedisCommanddecoding.EndpointgetEndpoint()Queue<RedisCommand<?,?,?>>getStack()protected CommandHandler.LifecycleStategetState()booleanisClosed()protected booleanisPushDecode(ByteBuf buffer)protected voidnotifyPushListeners(PushMessage notification)protected voidsetState(CommandHandler.LifecycleState lifecycleState)voiduserEventTriggered(ChannelHandlerContext ctx, Object evt)voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelReadComplete, channelWritabilityChangedMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
CommandHandler
public CommandHandler(ClientOptions clientOptions, ClientResources clientResources, Endpoint endpoint)Initialize a new instance that handles commands from the supplied queue.- Parameters:
clientOptions- client options for this connection, must not benullclientResources- client resources for this connection, must not benullendpoint- must not benull.
-
-
Method Details
-
getEndpoint
-
getStack
-
setState
-
drainQueue
-
getState
-
isClosed
public boolean isClosed() -
channelRegistered
- Specified by:
channelRegisteredin interfaceChannelInboundHandler- Overrides:
channelRegisteredin classChannelInboundHandlerAdapter- Throws:
Exception- See Also:
ChannelInboundHandlerAdapter.channelRegistered(io.netty.channel.ChannelHandlerContext)
-
channelUnregistered
- Specified by:
channelUnregisteredin interfaceChannelInboundHandler- Overrides:
channelUnregisteredin classChannelInboundHandlerAdapter- Throws:
Exception- See Also:
ChannelInboundHandlerAdapter.channelUnregistered(io.netty.channel.ChannelHandlerContext)
-
userEventTriggered
- Specified by:
userEventTriggeredin interfaceChannelInboundHandler- Overrides:
userEventTriggeredin classChannelInboundHandlerAdapter- Throws:
Exception- See Also:
ChannelInboundHandlerAdapter.userEventTriggered(io.netty.channel.ChannelHandlerContext, Object)
-
exceptionCaught
- Specified by:
exceptionCaughtin interfaceChannelHandler- Specified by:
exceptionCaughtin interfaceChannelInboundHandler- Overrides:
exceptionCaughtin classChannelInboundHandlerAdapter- Throws:
Exception
-
channelActive
- Specified by:
channelActivein interfaceChannelInboundHandler- Overrides:
channelActivein classChannelInboundHandlerAdapter- Throws:
Exception- See Also:
ChannelInboundHandlerAdapter.channelActive(io.netty.channel.ChannelHandlerContext)
-
channelInactive
- Specified by:
channelInactivein interfaceChannelInboundHandler- Overrides:
channelInactivein classChannelInboundHandlerAdapter- Throws:
Exception- See Also:
ChannelInboundHandlerAdapter.channelInactive(io.netty.channel.ChannelHandlerContext)
-
write
- Specified by:
writein interfaceChannelOutboundHandler- Overrides:
writein classChannelDuplexHandler- Throws:
Exception- See Also:
ChannelDuplexHandler.write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise)
-
channelRead
- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin classChannelInboundHandlerAdapter- Throws:
Exception- See Also:
ChannelInboundHandlerAdapter.channelRead(io.netty.channel.ChannelHandlerContext, java.lang.Object)
-
decode
- Throws:
InterruptedException
-
notifyPushListeners
-
canDecode
Decoding hook: Can the buffer be decoded to a command.- Parameters:
buffer-- Returns:
-
isPushDecode
-
canComplete
Decoding hook: Can the command be completed.- Parameters:
command-- Returns:
-
complete
Decoding hook: Complete a command.- Parameters:
command-- See Also:
RedisCommand.complete()
-
getCommandOutput
Decoding hook: RetrieveCommandOutputforRedisCommanddecoding.- Parameters:
command-- Returns:
- See Also:
RedisCommand.getOutput()
-
decode
-
decode
protected boolean decode(ByteBuf buffer, RedisCommand<?,?,?> command, CommandOutput<?,?,?> output) -
afterDecode
Hook method called after command completion.- Parameters:
ctx-command-
-
getChannelId
- Returns:
- the channel Id.
- Since:
- 6.1
-