Package io.netty.handler.codec.redis
Class RedisBulkStringAggregator
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.MessageToMessageDecoder<RedisMessage>
io.netty.handler.codec.MessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>
io.netty.handler.codec.redis.RedisBulkStringAggregator
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
@UnstableApi
public final class RedisBulkStringAggregator
extends MessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>
A
ChannelHandler
that aggregates an BulkStringHeaderRedisMessage
and its following BulkStringRedisContent
s into a single FullBulkStringRedisMessage
with no following BulkStringRedisContent
s. It is useful when you don't want to take
care of RedisMessage
s whose transfer encoding is 'chunked'. Insert this
handler after RedisDecoder
in the ChannelPipeline
:
Be aware that you need to have theChannelPipeline
p = ...; ... p.addLast("encoder", newRedisEncoder
()); p.addLast("decoder", newRedisDecoder
()); p.addLast("aggregator", newRedisBulkStringAggregator
()); ... p.addLast("handler", new HttpRequestHandler());
RedisEncoder
before the RedisBulkStringAggregator
in the ChannelPipeline
.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected FullBulkStringRedisMessage
beginAggregation
(BulkStringHeaderRedisMessage start, ByteBuf content) Creates a new aggregated message from the specified start message and the specified content.protected boolean
Determine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
is written.protected boolean
Determine if all objects for the current request/response should be ignored or not.protected boolean
isAggregated
(RedisMessage msg) Returnstrue
if and only if the specified message is already aggregated.protected boolean
isContentLengthInvalid
(BulkStringHeaderRedisMessage start, int maxContentLength) Determine if the messagestart
's content length is known, and if it greater thanmaxContentLength
.protected boolean
Returnstrue
if and only if the specified message is a content message.protected boolean
Returnstrue
if and only if the specified message is the last content message.protected boolean
Returnstrue
if and only if the specified message is a start message.protected Object
newContinueResponse
(BulkStringHeaderRedisMessage start, int maxContentLength, ChannelPipeline pipeline) Returns the 'continue response' for the specified start message if necessary.Methods inherited from class io.netty.handler.codec.MessageAggregator
acceptInboundMessage, aggregate, channelInactive, channelReadComplete, ctx, decode, finishAggregation, handleOversizedMessage, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponents
Methods inherited from class io.netty.handler.codec.MessageToMessageDecoder
channelRead
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Constructor Details
-
RedisBulkStringAggregator
public RedisBulkStringAggregator()Creates a new instance.
-
-
Method Details
-
isStartMessage
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is a start message. Typically, this method is implemented as a singlereturn
statement withinstanceof
:return msg instanceof MyStartMessage;
- Specified by:
isStartMessage
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Throws:
Exception
-
isContentMessage
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is a content message. Typically, this method is implemented as a singlereturn
statement withinstanceof
:return msg instanceof MyContentMessage;
- Specified by:
isContentMessage
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Throws:
Exception
-
isLastContentMessage
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is the last content message. Typically, this method is implemented as a singlereturn
statement withinstanceof
:return msg instanceof MyLastContentMessage;
or withinstanceof
and boolean field check:return msg instanceof MyContentMessage invalid input: '&'invalid input: '&' msg.isLastFragment();
- Specified by:
isLastContentMessage
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Throws:
Exception
-
isAggregated
Description copied from class:MessageAggregator
Returnstrue
if and only if the specified message is already aggregated. If this method returnstrue
, this handler will simply forward the message to the next handler as-is.- Specified by:
isAggregated
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Throws:
Exception
-
isContentLengthInvalid
protected boolean isContentLengthInvalid(BulkStringHeaderRedisMessage start, int maxContentLength) throws Exception Description copied from class:MessageAggregator
Determine if the messagestart
's content length is known, and if it greater thanmaxContentLength
.- Specified by:
isContentLengthInvalid
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Parameters:
start
- The message which may indicate the content length.maxContentLength
- The maximum allowed content length.- Returns:
true
if the messagestart
's content length is known, and if it greater thanmaxContentLength
.false
otherwise.- Throws:
Exception
-
newContinueResponse
protected Object newContinueResponse(BulkStringHeaderRedisMessage start, int maxContentLength, ChannelPipeline pipeline) throws Exception Description copied from class:MessageAggregator
Returns the 'continue response' for the specified start message if necessary. For example, this method is useful to handle an HTTP 100-continue header.- Specified by:
newContinueResponse
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Returns:
- the 'continue response', or
null
if there's no message to send - Throws:
Exception
-
closeAfterContinueResponse
Description copied from class:MessageAggregator
Determine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
is written.- Specified by:
closeAfterContinueResponse
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Parameters:
msg
- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
.- Returns:
true
if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
is written.false
otherwise.- Throws:
Exception
-
ignoreContentAfterContinueResponse
Description copied from class:MessageAggregator
Determine if all objects for the current request/response should be ignored or not. Messages will stop being ignored the next timeMessageAggregator.isContentMessage(Object)
returnstrue
.- Specified by:
ignoreContentAfterContinueResponse
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Parameters:
msg
- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
.- Returns:
true
if all objects for the current request/response should be ignored or not.false
otherwise.- Throws:
Exception
-
beginAggregation
protected FullBulkStringRedisMessage beginAggregation(BulkStringHeaderRedisMessage start, ByteBuf content) throws Exception Description copied from class:MessageAggregator
Creates a new aggregated message from the specified start message and the specified content. If the start message implementsByteBufHolder
, its content is appended to the specifiedcontent
. This aggregator will continue to append the received content to the specifiedcontent
.- Specified by:
beginAggregation
in classMessageAggregator<RedisMessage,
BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage> - Throws:
Exception
-