public class MetricBatcher extends io.netty.handler.codec.MessageToMessageDecoder<SingleMetric>
SingleMetric objects to reduce backend
communication overhead.
When creating the channel pipeline, an instance of
IdleStateHandler should be added just before an instance of this class. Metric
batcher instances handle read IdleStateEvents.
When such an event is captured, the batch is forwarded even if the size limit is not reached. Consequently, no
metric can stay in the cache several minutes before being sent to the server.
IdleStateHandler| Constructor and Description |
|---|
MetricBatcher(String subKey,
int minimumBatchSize)
Create a batcher with the passed batch size
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(io.netty.channel.ChannelHandlerContext ctx,
SingleMetric msg,
List<Object> out)
Batch up incoming SingleMetric messages.
|
void |
userEventTriggered(io.netty.channel.ChannelHandlerContext ctx,
Object evt) |
acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughthandlerAdded, handlerRemoved, isSharablepublic MetricBatcher(String subKey, int minimumBatchSize)
subKey - Identification of the metrics of this batcherminimumBatchSize - Size of batches. If the number is less than 1, then 1 is used.protected void decode(io.netty.channel.ChannelHandlerContext ctx,
SingleMetric msg,
List<Object> out)
throws Exception
decode in class io.netty.handler.codec.MessageToMessageDecoder<SingleMetric>ctx - the ChannelHandlerContext which this MessageToMessageDecoder belongs tomsg - the SingleMetric to be batched upout - the List to which decoded messages should be added if the batch size is reachedException - is thrown if an error occurspublic void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx,
Object evt)
throws Exception
userEventTriggered in interface io.netty.channel.ChannelInboundHandleruserEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapterExceptionCopyright © 2014–2015 Red Hat, Inc.. All rights reserved.