Package io.netty.handler.codec.redis
Class RedisBulkStringAggregator
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageDecoder<I>
-
- 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>
AChannelHandlerthat aggregates anBulkStringHeaderRedisMessageand its followingBulkStringRedisContents into a singleFullBulkStringRedisMessagewith no followingBulkStringRedisContents. It is useful when you don't want to take care ofRedisMessages whose transfer encoding is 'chunked'. Insert this handler afterRedisDecoderin theChannelPipeline:
Be aware that you need to have theChannelPipelinep = ...; ... p.addLast("encoder", newRedisEncoder()); p.addLast("decoder", newRedisDecoder()); p.addLast("aggregator", newRedisBulkStringAggregator()); ... p.addLast("handler", new HttpRequestHandler());RedisEncoderbefore theRedisBulkStringAggregatorin theChannelPipeline.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description RedisBulkStringAggregator()Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected FullBulkStringRedisMessagebeginAggregation(BulkStringHeaderRedisMessage start, ByteBuf content)Creates a new aggregated message from the specified start message and the specified content.protected booleancloseAfterContinueResponse(java.lang.Object msg)Determine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.protected booleanignoreContentAfterContinueResponse(java.lang.Object msg)Determine if all objects for the current request/response should be ignored or not.protected booleanisAggregated(RedisMessage msg)Returnstrueif and only if the specified message is already aggregated.protected booleanisContentLengthInvalid(BulkStringHeaderRedisMessage start, int maxContentLength)Determine if the messagestart's content length is known, and if it greater thanmaxContentLength.protected booleanisContentMessage(RedisMessage msg)Returnstrueif and only if the specified message is a content message.protected booleanisLastContentMessage(BulkStringRedisContent msg)Returnstrueif and only if the specified message is the last content message.protected booleanisStartMessage(RedisMessage msg)Returnstrueif and only if the specified message is a start message.protected java.lang.ObjectnewContinueResponse(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
-
-
-
-
Method Detail
-
isStartMessage
protected boolean isStartMessage(RedisMessage msg) throws java.lang.Exception
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is a start message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyStartMessage;
- Specified by:
isStartMessagein classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Throws:
java.lang.Exception
-
isContentMessage
protected boolean isContentMessage(RedisMessage msg) throws java.lang.Exception
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is a content message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyContentMessage;
- Specified by:
isContentMessagein classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Throws:
java.lang.Exception
-
isLastContentMessage
protected boolean isLastContentMessage(BulkStringRedisContent msg) throws java.lang.Exception
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is the last content message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyLastContentMessage;
or withinstanceofand boolean field check:return msg instanceof MyContentMessage && msg.isLastFragment();
- Specified by:
isLastContentMessagein classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Throws:
java.lang.Exception
-
isAggregated
protected boolean isAggregated(RedisMessage msg) throws java.lang.Exception
Description copied from class:MessageAggregatorReturnstrueif 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:
isAggregatedin classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Throws:
java.lang.Exception
-
isContentLengthInvalid
protected boolean isContentLengthInvalid(BulkStringHeaderRedisMessage start, int maxContentLength) throws java.lang.Exception
Description copied from class:MessageAggregatorDetermine if the messagestart's content length is known, and if it greater thanmaxContentLength.- Specified by:
isContentLengthInvalidin classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Parameters:
start- The message which may indicate the content length.maxContentLength- The maximum allowed content length.- Returns:
trueif the messagestart's content length is known, and if it greater thanmaxContentLength.falseotherwise.- Throws:
java.lang.Exception
-
newContinueResponse
protected java.lang.Object newContinueResponse(BulkStringHeaderRedisMessage start, int maxContentLength, ChannelPipeline pipeline) throws java.lang.Exception
Description copied from class:MessageAggregatorReturns 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:
newContinueResponsein classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Returns:
- the 'continue response', or
nullif there's no message to send - Throws:
java.lang.Exception
-
closeAfterContinueResponse
protected boolean closeAfterContinueResponse(java.lang.Object msg) throws java.lang.ExceptionDescription copied from class:MessageAggregatorDetermine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.- Specified by:
closeAfterContinueResponsein classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Parameters:
msg- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline).- Returns:
trueif the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.falseotherwise.- Throws:
java.lang.Exception
-
ignoreContentAfterContinueResponse
protected boolean ignoreContentAfterContinueResponse(java.lang.Object msg) throws java.lang.ExceptionDescription copied from class:MessageAggregatorDetermine 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:
ignoreContentAfterContinueResponsein classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Parameters:
msg- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline).- Returns:
trueif all objects for the current request/response should be ignored or not.falseotherwise.- Throws:
java.lang.Exception
-
beginAggregation
protected FullBulkStringRedisMessage beginAggregation(BulkStringHeaderRedisMessage start, ByteBuf content) throws java.lang.Exception
Description copied from class:MessageAggregatorCreates 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:
beginAggregationin classMessageAggregator<RedisMessage,BulkStringHeaderRedisMessage,BulkStringRedisContent,FullBulkStringRedisMessage>- Throws:
java.lang.Exception
-
-