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
限定符 | 构造器和说明 |
---|---|
protected |
MessageAggregator(int maxContentLength)
Creates a new instance.
|
protected |
MessageAggregator(int maxContentLength,
java.lang.Class<? extends I> inboundMessageType) |
限定符和类型 | 方法和说明 |
---|---|
boolean |
acceptInboundMessage(java.lang.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 ChannelInboundHandler in the ChannelPipeline . |
void |
channelReadComplete(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelReadComplete() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected abstract boolean |
closeAfterContinueResponse(java.lang.Object msg)
Determine if the channel should be closed after the result of
newContinueResponse(Object, int, ChannelPipeline) is written. |
protected ChannelHandlerContext |
ctx() |
protected void |
decode(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 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 |
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)
Returns
true if and only if the specified message is already aggregated. |
protected abstract boolean |
isContentLengthInvalid(S start,
int 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. |
boolean |
isHandlingOversizedMessage()
已过时。
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. |
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,
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.
|
channelRead
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, isSharable
protected 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.protected MessageAggregator(int maxContentLength, java.lang.Class<? extends I> inboundMessageType)
public boolean acceptInboundMessage(java.lang.Object msg) throws java.lang.Exception
MessageToMessageDecoder
true
if the given message should be handled. If false
it will be passed to the next
ChannelInboundHandler
in the ChannelPipeline
.acceptInboundMessage
在类中 MessageToMessageDecoder<I>
java.lang.Exception
protected abstract boolean isStartMessage(I msg) throws java.lang.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;
java.lang.Exception
protected abstract boolean isContentMessage(I msg) throws java.lang.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;
java.lang.Exception
protected abstract boolean isLastContentMessage(C msg) throws java.lang.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();
java.lang.Exception
protected abstract boolean isAggregated(I msg) throws java.lang.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.java.lang.Exception
public final int maxContentLength()
public final int maxCumulationBufferComponents()
public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
2
.@Deprecated public final boolean isHandlingOversizedMessage()
protected final ChannelHandlerContext ctx()
protected void decode(ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageDecoder
decode
在类中 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 addedjava.lang.Exception
- is thrown if an error occursprotected abstract boolean isContentLengthInvalid(S start, int maxContentLength) throws java.lang.Exception
start
's content length is known, and if it greater than
maxContentLength
.start
- The message which may indicate the content length.maxContentLength
- The maximum allowed content length.true
if the message start
's content length is known, and if it greater than
maxContentLength
. false
otherwise.java.lang.Exception
protected abstract java.lang.Object newContinueResponse(S start, int maxContentLength, ChannelPipeline pipeline) throws java.lang.Exception
null
if there's no message to sendjava.lang.Exception
protected abstract boolean closeAfterContinueResponse(java.lang.Object msg) throws java.lang.Exception
newContinueResponse(Object, int, ChannelPipeline)
is written.msg
- The return value from newContinueResponse(Object, int, ChannelPipeline)
.true
if the channel should be closed after the result of
newContinueResponse(Object, int, ChannelPipeline)
is written. false
otherwise.java.lang.Exception
protected abstract boolean ignoreContentAfterContinueResponse(java.lang.Object msg) throws java.lang.Exception
isContentMessage(Object)
returns true
.msg
- The return value from newContinueResponse(Object, int, ChannelPipeline)
.true
if all objects for the current request/response should be ignored or not.
false
otherwise.java.lang.Exception
protected abstract O beginAggregation(S start, ByteBuf content) throws java.lang.Exception
ByteBufHolder
, its content is appended to the specified content
.
This aggregator will continue to append the received content to the specified content
.java.lang.Exception
protected void aggregate(O aggregated, C content) throws java.lang.Exception
aggregated
.java.lang.Exception
protected void finishAggregation(O aggregated) throws java.lang.Exception
aggregated
message is about to be passed to the next handler in the pipeline.java.lang.Exception
protected void handleOversizedMessage(ChannelHandlerContext ctx, S oversized) throws java.lang.Exception
exceptionCaught()
event with a TooLongFrameException
.ctx
- the ChannelHandlerContext
oversized
- the accumulated message up to this point, whose type is S
or O
java.lang.Exception
public void channelReadComplete(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelReadComplete()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelReadComplete
在接口中 ChannelInboundHandler
channelReadComplete
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelInactive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelInactive
在接口中 ChannelInboundHandler
channelInactive
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerAdded
在接口中 ChannelHandler
handlerAdded
在类中 ChannelHandlerAdapter
java.lang.Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved
在接口中 ChannelHandler
handlerRemoved
在类中 ChannelHandlerAdapter
java.lang.Exception