Top Description Fields Constructors Methods
io.netty.handler.codec

public abstract Class MessageAggregator<I, S, C extends io.netty.buffer.ByteBufHolder, O extends io.netty.buffer.ByteBufHolder>

extends MessageToMessageDecoder<I>
Class Inheritance
Type Parameters
<I>
the type that covers both start message and content message
<S>
the type of the start message
<C>
the type of the content message (must be a subtype of ByteBufHolder)
<O>
the type of the aggregated message (must be a subtype of S and ByteBufHolder)
Imports
io.netty.buffer.ByteBuf, .ByteBufHolder, .CompositeByteBuf, io.netty.channel.ChannelFuture, .ChannelFutureListener, .ChannelHandler, .ChannelHandlerContext, .ChannelPipeline, io.netty.util.ReferenceCountUtil, java.util.List

An abstract ChannelHandler that aggregates a series of message objects into a single aggregated message.

'A series of messages' is composed of the following:

The content of the aggregated message will be the merged content of the start message and its following content messages. If this aggregator encounters a content message where isLastContentMessage(ByteBufHolder) return true for, the aggregator will finish the aggregation and produce the aggregated message and expect another start message.

Field Summary

Modifier and TypeField and Description
private boolean
private ChannelFutureListener
private ChannelHandlerContext
private O
private static final int
private boolean
private boolean
private final int
private int

Constructor Summary

AccessConstructor and Description
protected
MessageAggregator(int
the maximum length of the aggregated content. If the length of the aggregated content exceeds this value, handleOversizedMessage(ChannelHandlerContext, Object) will be called.
maxContentLength
)

Creates a new instance.

protected
MessageAggregator(int maxContentLength, Class<? extends I> inboundMessageType)

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptInboundMessage(Object msg)

Overrides io.netty.handler.codec.MessageToMessageDecoder.acceptInboundMessage.

Returns true if the given message should be handled.
protected void
aggregate(O aggregated, C content)

Transfers the information provided by the specified content message to the specified aggregated message.

private static void
protected abstract O
beginAggregation(S start, ByteBuf content)

Creates a new aggregated message from the specified start message and the specified content.

public void
public void
protected abstract boolean

Returns:

true if the channel should be closed after the result of newContinueResponse(Object, int, ChannelPipeline) is written. false otherwise.
closeAfterContinueResponse
(Object msg)

Determine if the channel should be closed after the result of newContinueResponse(Object, int, ChannelPipeline) is written.

protected final ChannelHandlerContext
ctx()

protected void
decode(final ChannelHandlerContext ctx, I
the message to decode to an other one
msg
,
List<Object>
the List to which decoded messages should be added
out
)

Implements abstract io.netty.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to an other.
protected void
finishAggregation(O aggregated)

Invoked when the specified aggregated message is about to be passed to the next handler in the pipeline.

private void
finishAggregation0(O aggregated)

protected void
handleOversizedMessage(ChannelHandlerContext ctx, S
the accumulated message up to this point, whose type is S or O
oversized
)

Invoked when an incoming request exceeds the maximum content length.

public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
protected abstract boolean

Returns:

true if all objects for the current request/response should be ignored or not. false otherwise.
ignoreContentAfterContinueResponse
(Object msg)

Determine if all objects for the current request/response should be ignored or not.

private void
protected abstract boolean
isAggregated(I msg)

Returns true if and only if the specified message is already aggregated.

protected abstract boolean

Returns:

true if the message start's content length is known, and if it greater than maxContentLength. false otherwise.
isContentLengthInvalid
(S
The message which may indicate the content length.
start
,
int
The maximum allowed content length.
maxContentLength
)

Determine if the message start's content length is known, and if it greater than maxContentLength.

protected abstract boolean
isContentMessage(I msg)

Returns true if and only if the specified message is a content message.

public final boolean
isHandlingOversizedMessage()

Deprecated This method will be removed in future releases.
protected abstract boolean
isLastContentMessage(C msg)

Returns true if and only if the specified message is the last content message.

protected abstract boolean
isStartMessage(I msg)

Returns true if and only if the specified message is a start message.

public final int
maxContentLength()

Returns the maximum allowed length of the aggregated message in bytes.

public final int
maxCumulationBufferComponents()

Returns the maximum number of components in the cumulation buffer.

protected abstract Object

Returns:

the 'continue response', or null if there's no message to send
newContinueResponse
(S start, int maxContentLength, ChannelPipeline pipeline)

Returns the 'continue response' for the specified start message if necessary.

private void
public final void
setMaxCumulationBufferComponents(int maxCumulationBufferComponents)

Sets the maximum number of components in the cumulation buffer.

private static void
validateMaxContentLength(int maxContentLength)

Inherited from io.netty.handler.codec.MessageToMessageDecoder:
channelRead

Field Detail

aggregatingback to summary
private boolean aggregating
continueResponseWriteListenerback to summary
private ChannelFutureListener continueResponseWriteListener
ctxback to summary
private ChannelHandlerContext ctx
currentMessageback to summary
private O currentMessage
DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTSback to summary
private static final int DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
handleIncompleteAggregateDuringCloseback to summary
private boolean handleIncompleteAggregateDuringClose
handlingOversizedMessageback to summary
private boolean handlingOversizedMessage
maxContentLengthback to summary
private final int maxContentLength
maxCumulationBufferComponentsback to summary
private int maxCumulationBufferComponents

Constructor Detail

MessageAggregatorback to summary
protected MessageAggregator(int maxContentLength)

Creates a new instance.

Parameters
maxContentLength:int

the maximum length of the aggregated content. If the length of the aggregated content exceeds this value, handleOversizedMessage(ChannelHandlerContext, Object) will be called.

MessageAggregatorback to summary
protected MessageAggregator(int maxContentLength, Class<? extends I> inboundMessageType)

Method Detail

acceptInboundMessageback to summary
public boolean acceptInboundMessage(Object msg) throws Exception

Overrides io.netty.handler.codec.MessageToMessageDecoder.acceptInboundMessage.

Doc from io.netty.handler.codec.MessageToMessageDecoder.acceptInboundMessage.

Returns true if the given message should be handled. If false it will be passed to the next ChannelInboundHandler in the ChannelPipeline.

Annotations
@Override
aggregateback to summary
protected void aggregate(O aggregated, C content) throws Exception

Transfers the information provided by the specified content message to the specified aggregated message. Note that the content of the specified content message has been appended to the content of the specified aggregated message already, so that you don't need to. Use this method to transfer the additional information that the content message provides to aggregated.

appendPartialContentback to summary
private static void appendPartialContent(CompositeByteBuf content, ByteBuf partialContent)
beginAggregationback to summary
protected abstract O beginAggregation(S start, ByteBuf content) throws Exception

Creates a new aggregated message from the specified start message and the specified content. If the start message implements ByteBufHolder, its content is appended to the specified content. This aggregator will continue to append the received content to the specified content.

channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Calls ChannelHandlerContext#fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelReadCompleteback to summary
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Calls ChannelHandlerContext#fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
closeAfterContinueResponseback to summary
protected abstract boolean closeAfterContinueResponse(Object msg) throws Exception

Determine if the channel should be closed after the result of newContinueResponse(Object, int, ChannelPipeline) is written.

Parameters
msg:Object

The return value from newContinueResponse(Object, int, ChannelPipeline).

Returns:boolean

true if the channel should be closed after the result of newContinueResponse(Object, int, ChannelPipeline) is written. false otherwise.

ctxback to summary
protected final ChannelHandlerContext ctx()
decodeback to summary
protected void decode(final ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageDecoder.decode.

Doc from io.netty.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:I

the message to decode to an other one

out:List<Object>

the List to which decoded messages should be added

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
finishAggregationback to summary
protected void finishAggregation(O aggregated) throws Exception

Invoked when the specified aggregated message is about to be passed to the next handler in the pipeline.

finishAggregation0back to summary
private void finishAggregation0(O aggregated) throws Exception
handleOversizedMessageback to summary
protected void handleOversizedMessage(ChannelHandlerContext ctx, S oversized) throws Exception

Invoked when an incoming request exceeds the maximum content length. The default behvaior is to trigger an exceptionCaught() event with a TooLongFrameException.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext

oversized:S

the accumulated message up to this point, whose type is S or O

handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
ignoreContentAfterContinueResponseback to summary
protected abstract boolean ignoreContentAfterContinueResponse(Object msg) throws Exception

Determine if all objects for the current request/response should be ignored or not. Messages will stop being ignored the next time isContentMessage(Object) returns true.

Parameters
msg:Object

The return value from newContinueResponse(Object, int, ChannelPipeline).

Returns:boolean

true if all objects for the current request/response should be ignored or not. false otherwise.

invokeHandleOversizedMessageback to summary
private void invokeHandleOversizedMessage(ChannelHandlerContext ctx, S oversized) throws Exception
isAggregatedback to summary
protected abstract boolean isAggregated(I msg) throws Exception

Returns true if and only if the specified message is already aggregated. If this method returns true, this handler will simply forward the message to the next handler as-is.

isContentLengthInvalidback to summary
protected abstract boolean isContentLengthInvalid(S start, int maxContentLength) throws Exception

Determine if the message start's content length is known, and if it greater than maxContentLength.

Parameters
start:S

The message which may indicate the content length.

maxContentLength:int

The maximum allowed content length.

Returns:boolean

true if the message start's content length is known, and if it greater than maxContentLength. false otherwise.

isContentMessageback to summary
protected abstract boolean isContentMessage(I msg) throws Exception

Returns true if and only if the specified message is a content message. Typically, this method is implemented as a single return statement with instanceof:

return msg instanceof MyContentMessage;
isHandlingOversizedMessageback to summary
public final boolean isHandlingOversizedMessage()

Deprecated

This method will be removed in future releases.

Annotations
@Deprecated
isLastContentMessageback to summary
protected abstract boolean isLastContentMessage(C msg) throws Exception

Returns true if and only if the specified message is the last content message. Typically, this method is implemented as a single return statement with instanceof:

return msg instanceof MyLastContentMessage;
or with instanceof and boolean field check:
return msg instanceof MyContentMessage && msg.isLastFragment();
isStartMessageback to summary
protected abstract boolean isStartMessage(I msg) throws Exception

Returns true if and only if the specified message is a start message. Typically, this method is implemented as a single return statement with instanceof:

return msg instanceof MyStartMessage;
maxContentLengthback to summary
public final int maxContentLength()

Returns the maximum allowed length of the aggregated message in bytes.

maxCumulationBufferComponentsback to summary
public final int maxCumulationBufferComponents()

Returns the maximum number of components in the cumulation buffer. If the number of the components in the cumulation buffer exceeds this value, the components of the cumulation buffer are consolidated into a single component, involving memory copies. The default value of this property is 1024.

newContinueResponseback to summary
protected abstract Object newContinueResponse(S start, int maxContentLength, ChannelPipeline pipeline) throws Exception

Returns the 'continue response' for the specified start message if necessary. For example, this method is useful to handle an HTTP 100-continue header.

Returns:Object

the 'continue response', or null if there's no message to send

releaseCurrentMessageback to summary
private void releaseCurrentMessage()
setMaxCumulationBufferComponentsback to summary
public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents)

Sets the maximum number of components in the cumulation buffer. If the number of the components in the cumulation buffer exceeds this value, the components of the cumulation buffer are consolidated into a single component, involving memory copies. The default value of this property is 1024 and its minimum allowed value is 2.

validateMaxContentLengthback to summary
private static void validateMaxContentLength(int maxContentLength)