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

public abstract Class MessageAggregator<I, S, C extends AutoCloseable, A extends AutoCloseable>

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
<A>
the type of the aggregated message
Imports
io.netty5.buffer.BufferAllocator, io.netty5.channel.ChannelFutureListeners, .ChannelHandler, .ChannelHandlerContext, .ChannelOption, .ChannelPipeline, io.netty5.util.concurrent.Future, .FutureContextListener

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(AutoCloseable) 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 FutureContextListener<ChannelHandlerContext, Void>
private ChannelHandlerContext
private A
private boolean
private final 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.netty5.handler.codec.MessageToMessageDecoder.acceptInboundMessage.

Returns true if the given message should be handled.
protected abstract void
aggregate(BufferAllocator allocator, A aggregated, C content)

Aggregated the passed content in the passed aggregate.

protected abstract A
beginAggregation(BufferAllocator allocator, S start)

Creates a new aggregated message from the specified start message.

public void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public void
channelReadComplete(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object).
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 another one
msg
)

Overrides io.netty5.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to another.
protected void
finishAggregation(BufferAllocator allocator, A aggregated)

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

private void
finishAggregation0(BufferAllocator allocator, A aggregated)

protected void
handleOversizedMessage(ChannelHandlerContext ctx, Object
the accumulated message up to this point.
oversized
)

Invoked when an incoming request exceeds the maximum content length.

public void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.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 default io.netty5.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(Object 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
isLastContentMessage(C msg)

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

protected abstract int

Returns:

Length in bytes of the passed message.
lengthForAggregation
(A
to calculate length.
msg
)

Returns the length in bytes of the passed message.

protected abstract int

Returns:

Length in bytes of the passed message.
lengthForContent
(C
to calculate length.
msg
)

Returns the length in bytes of the passed message.

public final int
maxContentLength()

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

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
protected abstract C
tryContentMessage(Object msg)

If the passed msg is a content message then cast and return the same, else return null.

protected abstract S
tryStartMessage(Object msg)

If the passed msg is a start message then cast and return the same, else return null.

private static void
validateMaxContentLength(int maxContentLength)

Inherited from io.netty5.handler.codec.MessageToMessageDecoder:
channelReaddecodeAndClose

Field Detail

aggregatingback to summary
private boolean aggregating
continueResponseWriteListenerback to summary
private FutureContextListener<ChannelHandlerContext, Void> continueResponseWriteListener
ctxback to summary
private ChannelHandlerContext ctx
currentMessageback to summary
private A currentMessage
handlingOversizedMessageback to summary
private boolean handlingOversizedMessage
maxContentLengthback to summary
private final int maxContentLength

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.netty5.handler.codec.MessageToMessageDecoder.acceptInboundMessage.

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

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

Annotations
@Override
aggregateback to summary
protected abstract void aggregate(BufferAllocator allocator, A aggregated, C content) throws Exception

Aggregated the passed content in the passed aggregate.

beginAggregationback to summary
protected abstract A beginAggregation(BufferAllocator allocator, S start) throws Exception

Creates a new aggregated message from the specified start message.

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

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

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

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Doc from io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object). If ChannelOption#AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker#read(ReadBufferAllocator) is called.

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) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageDecoder.decode.

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

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

The message will be disposed of after this call.

Subclasses that wish to sometimes pass messages through, should instead override the decodeAndClose(ChannelHandlerContext, Object) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:I

the message to decode to another one

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
finishAggregationback to summary
protected void finishAggregation(BufferAllocator allocator, A 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(BufferAllocator allocator, A aggregated) throws Exception
handleOversizedMessageback to summary
protected void handleOversizedMessage(ChannelHandlerContext ctx, Object oversized) throws Exception

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

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext

oversized:Object

the accumulated message up to this point.

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

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.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 default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.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 tryContentMessage(Object) returns a non null value.

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, Object oversized) throws Exception
isAggregatedback to summary
protected abstract boolean isAggregated(Object 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.

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();
lengthForAggregationback to summary
protected abstract int lengthForAggregation(A msg)

Returns the length in bytes of the passed message.

Parameters
msg:A

to calculate length.

Returns:int

Length in bytes of the passed message.

lengthForContentback to summary
protected abstract int lengthForContent(C msg)

Returns the length in bytes of the passed message.

Parameters
msg:C

to calculate length.

Returns:int

Length in bytes of the passed message.

maxContentLengthback to summary
public final int maxContentLength()

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

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() throws Exception
tryContentMessageback to summary
protected abstract C tryContentMessage(Object msg)

If the passed msg is a content message then cast and return the same, else return null.

tryStartMessageback to summary
protected abstract S tryStartMessage(Object msg)

If the passed msg is a start message then cast and return the same, else return null.

validateMaxContentLengthback to summary
private static void validateMaxContentLength(int maxContentLength)