Package io.lettuce.core.protocol
Class CommandHandler
- 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 nettyChannelHandler
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 class
CommandHandler.LifecycleState
-
Nested 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
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
channelActive(ChannelHandlerContext ctx)
void
channelInactive(ChannelHandlerContext ctx)
void
channelRead(ChannelHandlerContext ctx, Object msg)
void
channelRegistered(ChannelHandlerContext ctx)
void
channelUnregistered(ChannelHandlerContext ctx)
protected void
complete(RedisCommand<?,?,?> command)
Decoding hook: Complete a command.protected boolean
decode(ByteBuf buffer, CommandOutput<?,?,?> output)
protected boolean
decode(ByteBuf buffer, RedisCommand<?,?,?> command, CommandOutput<?,?,?> output)
protected void
decode(ChannelHandlerContext ctx, ByteBuf buffer)
Collection<RedisCommand<?,?,?>>
drainQueue()
void
exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
String
getChannelId()
protected CommandOutput<?,?,?>
getCommandOutput(RedisCommand<?,?,?> command)
Decoding hook: RetrieveCommandOutput
forRedisCommand
decoding.Endpoint
getEndpoint()
Queue<RedisCommand<?,?,?>>
getStack()
protected CommandHandler.LifecycleState
getState()
boolean
isClosed()
protected boolean
isPushDecode(ByteBuf buffer)
protected void
notifyPushListeners(PushMessage notification)
protected void
setState(CommandHandler.LifecycleState lifecycleState)
void
userEventTriggered(ChannelHandlerContext ctx, Object evt)
void
write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
-
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
-
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 benull
clientResources
- client resources for this connection, must not benull
endpoint
- must not benull
.
-
-
Method Detail
-
getEndpoint
public Endpoint getEndpoint()
-
getStack
public Queue<RedisCommand<?,?,?>> getStack()
-
setState
protected void setState(CommandHandler.LifecycleState lifecycleState)
-
drainQueue
public Collection<RedisCommand<?,?,?>> drainQueue()
-
getState
protected CommandHandler.LifecycleState getState()
-
isClosed
public boolean isClosed()
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
- Specified by:
channelRegistered
in interfaceChannelInboundHandler
- Overrides:
channelRegistered
in classChannelInboundHandlerAdapter
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.channelRegistered(io.netty.channel.ChannelHandlerContext)
-
channelUnregistered
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception
- Specified by:
channelUnregistered
in interfaceChannelInboundHandler
- Overrides:
channelUnregistered
in classChannelInboundHandlerAdapter
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.channelUnregistered(io.netty.channel.ChannelHandlerContext)
-
userEventTriggered
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
- Specified by:
userEventTriggered
in interfaceChannelInboundHandler
- Overrides:
userEventTriggered
in classChannelInboundHandlerAdapter
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.userEventTriggered(io.netty.channel.ChannelHandlerContext, Object)
-
exceptionCaught
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
- Specified by:
exceptionCaught
in interfaceChannelHandler
- Specified by:
exceptionCaught
in interfaceChannelInboundHandler
- Overrides:
exceptionCaught
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws Exception
- Specified by:
channelActive
in interfaceChannelInboundHandler
- Overrides:
channelActive
in classChannelInboundHandlerAdapter
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.channelActive(io.netty.channel.ChannelHandlerContext)
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
- Specified by:
channelInactive
in interfaceChannelInboundHandler
- Overrides:
channelInactive
in classChannelInboundHandlerAdapter
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.channelInactive(io.netty.channel.ChannelHandlerContext)
-
write
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
- Specified by:
write
in interfaceChannelOutboundHandler
- Overrides:
write
in classChannelDuplexHandler
- Throws:
Exception
- See Also:
ChannelDuplexHandler.write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise)
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
- See Also:
ChannelInboundHandlerAdapter.channelRead(io.netty.channel.ChannelHandlerContext, java.lang.Object)
-
decode
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer) throws InterruptedException
- Throws:
InterruptedException
-
notifyPushListeners
protected void notifyPushListeners(PushMessage notification)
-
canDecode
protected boolean canDecode(ByteBuf buffer)
Decoding hook: Can the buffer be decoded to a command.- Parameters:
buffer
-- Returns:
-
isPushDecode
protected boolean isPushDecode(ByteBuf buffer)
-
canComplete
protected boolean canComplete(RedisCommand<?,?,?> command)
Decoding hook: Can the command be completed.- Parameters:
command
-- Returns:
-
complete
protected void complete(RedisCommand<?,?,?> command)
Decoding hook: Complete a command.- Parameters:
command
-- See Also:
RedisCommand.complete()
-
getCommandOutput
protected CommandOutput<?,?,?> getCommandOutput(RedisCommand<?,?,?> command)
Decoding hook: RetrieveCommandOutput
forRedisCommand
decoding.- Parameters:
command
-- Returns:
- See Also:
RedisCommand.getOutput()
-
decode
protected boolean decode(ByteBuf buffer, CommandOutput<?,?,?> output)
-
decode
protected boolean decode(ByteBuf buffer, RedisCommand<?,?,?> command, CommandOutput<?,?,?> output)
-
afterDecode
protected void afterDecode(ChannelHandlerContext ctx, RedisCommand<?,?,?> command)
Hook method called after command completion.- Parameters:
ctx
-command
-
-
getChannelId
public String getChannelId()
- Returns:
- the channel Id.
- Since:
- 6.1
-
-