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 BulkStringRedisContents into a single FullBulkStringRedisMessage
with no following BulkStringRedisContents. It is useful when you don't want to take
care of RedisMessages whose transfer encoding is 'chunked'. Insert this
handler after RedisDecoder in the ChannelPipeline:
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());
RedisEncoder before the RedisBulkStringAggregator
in the ChannelPipeline.-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.SharableModifier and TypeInterfaceDescriptionstatic @interfaceIndicates that the same instance of the annotatedChannelHandlercan be added to one or moreChannelPipelines multiple times without a race condition. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected FullBulkStringRedisMessagebeginAggregation(BulkStringHeaderRedisMessage start, ByteBuf content) Creates a new aggregated message from the specified start message and the specified content.protected booleanDetermine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.protected booleanDetermine 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 booleanReturnstrueif and only if the specified message is a content message.protected booleanReturnstrueif and only if the specified message is the last content message.protected booleanReturnstrueif and only if the specified message is a start message.protected ObjectnewContinueResponse(BulkStringHeaderRedisMessage start, int maxContentLength, ChannelPipeline pipeline) Returns the 'continue response' for the specified start message if necessary.Methods inherited from class MessageAggregator
acceptInboundMessage, aggregate, channelInactive, channelReadComplete, ctx, decode, finishAggregation, handleOversizedMessage, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponentsModifier and TypeMethodDescriptionbooleanReturnstrueif the given message should be handled.protected voidaggregate(FullBulkStringRedisMessage aggregated, BulkStringRedisContent content) Transfers the information provided by the specified content message to the specified aggregated message.voidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected final ChannelHandlerContextctx()protected voiddecode(ChannelHandlerContext ctx, RedisMessage msg, List<Object> out) Decode from one message to an other.protected voidfinishAggregation(FullBulkStringRedisMessage aggregated) Invoked when the specifiedaggregatedmessage is about to be passed to the next handler in the pipeline.protected voidhandleOversizedMessage(ChannelHandlerContext ctx, BulkStringHeaderRedisMessage oversized) Invoked when an incoming request exceeds the maximum content length.voidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.final booleanDeprecated.This method will be removed in future releases.final intReturns the maximum allowed length of the aggregated message in bytes.final intReturns the maximum number of components in the cumulation buffer.protected final voidfinal voidsetMaxCumulationBufferComponents(int maxCumulationBufferComponents) Sets the maximum number of components in the cumulation buffer.Methods inherited from class MessageToMessageDecoder
channelReadModifier and TypeMethodDescriptionvoidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredModifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelUnregistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelWritabilityChanged()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.voiduserEventTriggered(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableModifier and TypeMethodDescriptionprotected voidbooleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.
-
Constructor Details
-
RedisBulkStringAggregator
public RedisBulkStringAggregator()Creates a new instance.
-
-
Method Details
-
isStartMessage
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:
Exception
-
isContentMessage
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:
Exception
-
isLastContentMessage
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 invalid input: '&'invalid input: '&' msg.isLastFragment();
- Specified by:
isLastContentMessagein classMessageAggregator<RedisMessage, BulkStringHeaderRedisMessage, BulkStringRedisContent, FullBulkStringRedisMessage>- Throws:
Exception
-
isAggregated
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:
Exception
-
isContentLengthInvalid
protected boolean isContentLengthInvalid(BulkStringHeaderRedisMessage start, int maxContentLength) throws 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:
Exception
-
newContinueResponse
protected Object newContinueResponse(BulkStringHeaderRedisMessage start, int maxContentLength, ChannelPipeline pipeline) throws 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:
Exception
-
closeAfterContinueResponse
Description 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:
Exception
-
ignoreContentAfterContinueResponse
Description 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:
Exception
-
beginAggregation
protected FullBulkStringRedisMessage beginAggregation(BulkStringHeaderRedisMessage start, ByteBuf content) throws 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:
Exception
-