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 of ByteBufHolder)O - the type of the aggregated message (must be a subtype of S and ByteBufHolder)public abstract class MessageAggregator<I,S,C extends ByteBufHolder,O extends ByteBufHolder> extends MessageToMessageDecoder<I>
ChannelHandler that aggregates a series of message objects into a single aggregated message.
'A series of messages' is composed of the following:
isLastContentMessage(ByteBufHolder)
return true for, the aggregator will finish the aggregation and produce the aggregated message and expect
another start message.
ChannelHandler.Sharable, ChannelHandler.Skip| Modifier | Constructor and Description |
|---|---|
protected |
MessageAggregator(int maxContentLength)
Creates a new instance.
|
protected |
MessageAggregator(int maxContentLength,
Class<? extends I> inboundMessageType) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptInboundMessage(Object msg)
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.
|
protected abstract O |
beginAggregation(S start,
ByteBuf content)
Creates a new aggregated message from the specified start message and the specified content.
|
void |
channelInactive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelHandler in the ChannelPipeline. |
protected abstract long |
contentLength(S start)
Retrieves the length of the whole content from the specified start message.
|
protected ChannelHandlerContext |
ctx() |
protected void |
decode(ChannelHandlerContext ctx,
I msg,
List<Object> out)
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. |
protected void |
handleOversizedMessage(ChannelHandlerContext ctx,
S oversized)
Invoked when an incoming request exceeds the maximum content length.
|
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
protected abstract boolean |
hasContentLength(S start)
Returns
true if and only if the specified start message already contains the information about the
length of the whole content. |
protected abstract boolean |
isAggregated(I msg)
Returns
true if and only if the specified message is already aggregated. |
protected abstract boolean |
isContentMessage(I msg)
Returns
true if and only if the specified message is a content message. |
boolean |
isHandlingOversizedMessage() |
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. |
int |
maxContentLength()
Returns the maximum allowed length of the aggregated message.
|
int |
maxCumulationBufferComponents()
Returns the maximum number of components in the cumulation buffer.
|
protected abstract Object |
newContinueResponse(S start)
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.
|
channelReadbind, channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, isSharable, read, userEventTriggered, writeprotected MessageAggregator(int maxContentLength)
maxContentLength - the maximum length of the aggregated content.
If the length of the aggregated content exceeds this value,
handleOversizedMessage(ChannelHandlerContext, Object) will be called.public boolean acceptInboundMessage(Object msg) throws Exception
MessageToMessageDecodertrue if the given message should be handled. If false it will be passed to the next
ChannelHandler in the ChannelPipeline.acceptInboundMessage in class MessageToMessageDecoder<I>Exceptionprotected abstract boolean isStartMessage(I msg) throws Exception
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;
Exceptionprotected abstract boolean isContentMessage(I msg) throws Exception
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;
Exceptionprotected abstract boolean isLastContentMessage(C msg) throws Exception
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();
Exceptionprotected abstract boolean isAggregated(I msg) throws Exception
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.Exceptionpublic final int maxContentLength()
public final int maxCumulationBufferComponents()
public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
2.public final boolean isHandlingOversizedMessage()
protected final ChannelHandlerContext ctx()
protected void decode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
MessageToMessageDecoderdecode in class MessageToMessageDecoder<I>ctx - the ChannelHandlerContext which this MessageToMessageDecoder belongs tomsg - the message to decode to an other oneout - the List to which decoded messages should be addedException - is thrown if an error accourprotected abstract boolean hasContentLength(S start) throws Exception
true if and only if the specified start message already contains the information about the
length of the whole content.Exceptionprotected abstract long contentLength(S start) throws Exception
hasContentLength(Object) returned true.Exceptionprotected abstract Object newContinueResponse(S start) throws Exception
null if there's no message to sendExceptionprotected abstract O beginAggregation(S start, ByteBuf content) throws Exception
ByteBufHolder, its content is appended to the specified content.
This aggregator will continue to append the received content to the specified content.Exceptionprotected void aggregate(O aggregated, C content) throws Exception
aggregated.Exceptionprotected void finishAggregation(O aggregated) throws Exception
aggregated message is about to be passed to the next handler in the pipeline.Exceptionprotected void handleOversizedMessage(ChannelHandlerContext ctx, S oversized) throws Exception
exceptionCaught() event with a TooLongFrameException.ctx - the ChannelHandlerContextoversized - the accumulated message up to this point, whose type is S or OExceptionpublic void channelInactive(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelInactive in interface ChannelHandlerchannelInactive in class ChannelHandlerAdapterExceptionpublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionCopyright © 2008–2015 The Netty Project. All rights reserved.