|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectio.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
com.alipay.remoting.codec.AbstractBatchDecoder
public abstract class AbstractBatchDecoder
This class mainly hack the ByteToMessageDecoder to provide batch submission capability.
This can be used the same way as ByteToMessageDecoder except the case your following inbound handler may get a decoded msg,
which actually is an array list, then you can submit the list of msgs to an executor to process. For example
if (msg instanceof List) {
processorManager.getDefaultExecutor().execute(new Runnable() {
| Nested Class Summary | |
|---|---|
static interface |
AbstractBatchDecoder.Cumulator
Cumulate ByteBufs. |
| Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler |
|---|
io.netty.channel.ChannelHandler.Sharable |
| Field Summary | |
|---|---|
static AbstractBatchDecoder.Cumulator |
COMPOSITE_CUMULATOR
Cumulate ByteBufs by add them to a CompositeByteBuf and so do no memory copy whenever possible. |
static AbstractBatchDecoder.Cumulator |
MERGE_CUMULATOR
Cumulate ByteBufs by merge them into one ByteBuf's, using memory copies. |
| Constructor Summary | |
|---|---|
AbstractBatchDecoder()
|
|
| Method Summary | |
|---|---|
protected int |
actualReadableBytes()
Returns the actual number of readable bytes in the internal cumulative buffer of this decoder. |
protected void |
callDecode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out)
Called once data should be decoded from the given ByteBuf. |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
|
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg)
This method has been modified to check the size of decoded msgs, which is represented by the local variable RecyclableArrayList out. |
void |
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
|
protected abstract void |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out)
Decode the from one ByteBuf to an other. |
protected void |
decodeLast(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out)
Is called one last time when the ChannelHandlerContext goes in-active. |
protected void |
discardSomeReadBytes()
|
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
|
protected void |
handlerRemoved0(io.netty.channel.ChannelHandlerContext ctx)
Gets called after the ByteToMessageDecoder was removed from the actual context and it doesn't handle
events anymore. |
protected io.netty.buffer.ByteBuf |
internalBuffer()
Returns the internal cumulative buffer of this decoder. |
boolean |
isSingleDecode()
If true then only one message is decoded on each
channelRead(ChannelHandlerContext, Object) call. |
void |
setCumulator(AbstractBatchDecoder.Cumulator cumulator)
Set the AbstractBatchDecoder.Cumulator to use for cumulate the received ByteBufs. |
void |
setDiscardAfterReads(int discardAfterReads)
Set the number of reads after which ByteBuf.discardSomeReadBytes() are called and so free up memory. |
void |
setSingleDecode(boolean singleDecode)
If set then only one message is decoded on each channelRead(ChannelHandlerContext, Object)
call. |
| Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter |
|---|
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered |
| Methods inherited from class io.netty.channel.ChannelHandlerAdapter |
|---|
ensureNotSharable, handlerAdded, isSharable |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface io.netty.channel.ChannelHandler |
|---|
handlerAdded |
| Field Detail |
|---|
public static final AbstractBatchDecoder.Cumulator MERGE_CUMULATOR
ByteBufs by merge them into one ByteBuf's, using memory copies.
public static final AbstractBatchDecoder.Cumulator COMPOSITE_CUMULATOR
ByteBufs by add them to a CompositeByteBuf and so do no memory copy whenever possible.
Be aware that CompositeByteBuf use a more complex indexing implementation so depending on your use-case
and the decoder implementation this may be slower then just use the MERGE_CUMULATOR.
| Constructor Detail |
|---|
public AbstractBatchDecoder()
| Method Detail |
|---|
public void setSingleDecode(boolean singleDecode)
channelRead(ChannelHandlerContext, Object)
call. This may be useful if you need to do some protocol upgrade and want to make sure nothing is mixed up.
Default is false as this has performance impacts.
public boolean isSingleDecode()
true then only one message is decoded on each
channelRead(ChannelHandlerContext, Object) call.
Default is false as this has performance impacts.
public void setCumulator(AbstractBatchDecoder.Cumulator cumulator)
AbstractBatchDecoder.Cumulator to use for cumulate the received ByteBufs.
public void setDiscardAfterReads(int discardAfterReads)
ByteBuf.discardSomeReadBytes() are called and so free up memory.
The default is 16.
protected int actualReadableBytes()
internalBuffer().readableBytes().
protected io.netty.buffer.ByteBuf internalBuffer()
public final void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterException
protected void handlerRemoved0(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
ByteToMessageDecoder was removed from the actual context and it doesn't handle
events anymore.
Exception
public void channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg)
throws Exception
RecyclableArrayList out. If has decoded more than one msg,
then construct an array list to submit all decoded msgs to the pipeline.
channelRead in interface io.netty.channel.ChannelInboundHandlerchannelRead in class io.netty.channel.ChannelInboundHandlerAdapterctx - msg -
Exception
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelReadComplete in interface io.netty.channel.ChannelInboundHandlerchannelReadComplete in class io.netty.channel.ChannelInboundHandlerAdapterExceptionprotected final void discardSomeReadBytes()
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelInactive in interface io.netty.channel.ChannelInboundHandlerchannelInactive in class io.netty.channel.ChannelInboundHandlerAdapterException
protected void callDecode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out)
ByteBuf. This method will call
decode(ChannelHandlerContext, ByteBuf, List) as long as decoding should take place.
ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs toin - the ByteBuf from which to read dataout - the List to which decoded messages should be added
protected void decodeLast(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out)
throws Exception
ChannelHandlerContext goes in-active. Which means the
channelInactive(ChannelHandlerContext) was triggered.
By default this will just call decode(ChannelHandlerContext, ByteBuf, List) but sub-classes may
override this for some special cleanup operation.
Exception
protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out)
throws Exception
ByteBuf to an other. This method will be called till either the input
ByteBuf has nothing to read when return from this method or till nothing was read from the input
ByteBuf.
ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs toin - the ByteBuf from which to read dataout - the List to which decoded messages should be added
Exception - is thrown if an error accour
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||