Package io.netty.handler.codec
Class EspressoMessageAggregator<I,S,C extends io.netty.buffer.ByteBufHolder,O extends io.netty.buffer.ByteBufHolder>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.EspressoMessageToMessageDecoder<I>
-
- io.netty.handler.codec.EspressoMessageAggregator<I,S,C,O>
-
- Type Parameters:
I
- the type that covers both start message and content messageS
- the type of the start messageC
- the type of the content message (must be a subtype ofByteBufHolder
)O
- the type of the aggregated message (must be a subtype ofS
andByteBufHolder
)
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
- Direct Known Subclasses:
EspressoHttpObjectAggregator
public abstract class EspressoMessageAggregator<I,S,C extends io.netty.buffer.ByteBufHolder,O extends io.netty.buffer.ByteBufHolder> extends EspressoMessageToMessageDecoder<I>
Forked from Netty 4.1.42.Final. Main change is to avoid creatingTypeParameterMatcher
. An abstractChannelHandler
that aggregates a series of message objects into a single aggregated message.'A series of messages' is composed of the following:
- a single start message which optionally contains the first part of the content, and
- 1 or more content messages.
isLastContentMessage(ByteBufHolder)
returntrue
for, the aggregator will finish the aggregation and produce the aggregated message and expect another start message.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EspressoMessageAggregator(int maxContentLength)
Creates a new instance.protected
EspressoMessageAggregator(int maxContentLength, java.lang.Class<? extends I> inboundMessageType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
acceptInboundMessage(java.lang.Object msg)
Returnstrue
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.protected abstract O
beginAggregation(S start, io.netty.buffer.ByteBuf content)
Creates a new aggregated message from the specified start message and the specified content.void
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
void
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
protected abstract boolean
closeAfterContinueResponse(java.lang.Object msg)
Determine if the channel should be closed after the result ofnewContinueResponse(Object, int, ChannelPipeline)
is written.protected io.netty.channel.ChannelHandlerContext
ctx()
protected void
decode(io.netty.channel.ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out)
Decode from one message to an other.protected void
finishAggregation(O aggregated)
Invoked when the specifiedaggregated
message is about to be passed to the next handler in the pipeline.protected void
handleOversizedMessage(io.netty.channel.ChannelHandlerContext ctx, S oversized)
Invoked when an incoming request exceeds the maximum content length.void
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
void
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
protected abstract boolean
ignoreContentAfterContinueResponse(java.lang.Object msg)
Determine if all objects for the current request/response should be ignored or not.protected abstract boolean
isAggregated(I msg)
Returnstrue
if and only if the specified message is already aggregated.protected abstract boolean
isContentLengthInvalid(S start, int maxContentLength)
Determine if the messagestart
's content length is known, and if it greater thanmaxContentLength
.protected abstract boolean
isContentMessage(I msg)
Returnstrue
if and only if the specified message is a content message.boolean
isHandlingOversizedMessage()
Deprecated.This method will be removed in future releases.protected abstract boolean
isLastContentMessage(C msg)
Returnstrue
if and only if the specified message is the last content message.protected abstract boolean
isStartMessage(I msg)
Returnstrue
if and only if the specified message is a start message.int
maxContentLength()
Returns the maximum allowed length of the aggregated message in bytes.int
maxCumulationBufferComponents()
Returns the maximum number of components in the cumulation buffer.protected abstract java.lang.Object
newContinueResponse(S start, int maxContentLength, io.netty.channel.ChannelPipeline pipeline)
Returns the 'continue response' for the specified start message if necessary.void
setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
Sets the maximum number of components in the cumulation buffer.-
Methods inherited from class io.netty.handler.codec.EspressoMessageToMessageDecoder
channelRead
-
-
-
-
Constructor Detail
-
EspressoMessageAggregator
protected EspressoMessageAggregator(int maxContentLength)
Creates a new instance.- Parameters:
maxContentLength
- the maximum length of the aggregated content. If the length of the aggregated content exceeds this value,handleOversizedMessage(ChannelHandlerContext, Object)
will be called.
-
EspressoMessageAggregator
protected EspressoMessageAggregator(int maxContentLength, java.lang.Class<? extends I> inboundMessageType)
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(java.lang.Object msg) throws java.lang.Exception
Description copied from class:EspressoMessageToMessageDecoder
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Overrides:
acceptInboundMessage
in classEspressoMessageToMessageDecoder<I>
- Throws:
java.lang.Exception
-
isStartMessage
protected abstract boolean isStartMessage(I msg) throws java.lang.Exception
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;
- Throws:
java.lang.Exception
-
isContentMessage
protected abstract boolean isContentMessage(I msg) throws java.lang.Exception
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;
- Throws:
java.lang.Exception
-
isLastContentMessage
protected abstract boolean isLastContentMessage(C msg) throws java.lang.Exception
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 && msg.isLastFragment();
- Throws:
java.lang.Exception
-
isAggregated
protected abstract boolean isAggregated(I msg) throws java.lang.Exception
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.- Throws:
java.lang.Exception
-
maxContentLength
public final int maxContentLength()
Returns the maximum allowed length of the aggregated message in bytes.
-
maxCumulationBufferComponents
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.
-
setMaxCumulationBufferComponents
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 is2
.
-
isHandlingOversizedMessage
@Deprecated public final boolean isHandlingOversizedMessage()
Deprecated.This method will be removed in future releases.
-
ctx
protected final io.netty.channel.ChannelHandlerContext ctx()
-
decode
protected void decode(io.netty.channel.ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
Description copied from class:EspressoMessageToMessageDecoder
Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.- Specified by:
decode
in classEspressoMessageToMessageDecoder<I>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- theList
to which decoded messages should be added- Throws:
java.lang.Exception
- is thrown if an error occurs
-
isContentLengthInvalid
protected abstract boolean isContentLengthInvalid(S start, int maxContentLength) throws java.lang.Exception
Determine if the messagestart
's content length is known, and if it greater thanmaxContentLength
.- 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:
java.lang.Exception
-
newContinueResponse
protected abstract java.lang.Object newContinueResponse(S start, int maxContentLength, io.netty.channel.ChannelPipeline pipeline) throws java.lang.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:
- the 'continue response', or
null
if there's no message to send - Throws:
java.lang.Exception
-
closeAfterContinueResponse
protected abstract boolean closeAfterContinueResponse(java.lang.Object msg) throws java.lang.Exception
Determine if the channel should be closed after the result ofnewContinueResponse(Object, int, ChannelPipeline)
is written.- Parameters:
msg
- The return value fromnewContinueResponse(Object, int, ChannelPipeline)
.- Returns:
true
if the channel should be closed after the result ofnewContinueResponse(Object, int, ChannelPipeline)
is written.false
otherwise.- Throws:
java.lang.Exception
-
ignoreContentAfterContinueResponse
protected abstract boolean ignoreContentAfterContinueResponse(java.lang.Object msg) throws java.lang.Exception
Determine if all objects for the current request/response should be ignored or not. Messages will stop being ignored the next timeisContentMessage(Object)
returnstrue
.- Parameters:
msg
- The return value fromnewContinueResponse(Object, int, ChannelPipeline)
.- Returns:
true
if all objects for the current request/response should be ignored or not.false
otherwise.- Throws:
java.lang.Exception
-
beginAggregation
protected abstract O beginAggregation(S start, io.netty.buffer.ByteBuf content) throws java.lang.Exception
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
.- Throws:
java.lang.Exception
-
aggregate
protected void aggregate(O aggregated, C content) throws java.lang.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 toaggregated
.- Throws:
java.lang.Exception
-
finishAggregation
protected void finishAggregation(O aggregated) throws java.lang.Exception
Invoked when the specifiedaggregated
message is about to be passed to the next handler in the pipeline.- Throws:
java.lang.Exception
-
handleOversizedMessage
protected void handleOversizedMessage(io.netty.channel.ChannelHandlerContext ctx, S oversized) throws java.lang.Exception
Invoked when an incoming request exceeds the maximum content length. The default behvaior is to trigger anexceptionCaught()
event with aTooLongFrameException
.- Parameters:
ctx
- theChannelHandlerContext
oversized
- the accumulated message up to this point, whose type isS
orO
- Throws:
java.lang.Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelReadComplete
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelReadComplete
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
java.lang.Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerRemoved
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerRemoved
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
java.lang.Exception
-
-