Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.rhq.metrics.clients.ptrans;
 import java.util.List;
Batch several individual org.rhq.metrics.client.common.SingleMetric objects in a batch of minimumBatchSize items to reduce backend communication overhead.

Heiko W. Rupp
    private int minimumBatchSize;

Create a batcher with the passed batch size

subKey Identification of the metrics of this batcher
minimumBatchSize Size of batches. If the number is less than 1, then 1 is used.
    public MetricBatcher(String subKeyint minimumBatchSize) {
        this. = minimumBatchSize;
        if (this.<1) {
         = AttributeKey.valueOf("cachedMetrics."+subKey);
Batch up incoming SingleMetric messages. If the #minimumBatchSize is not yet reached, the messages are stored locally. Otherwise the list of messages will be forwarded to the next handler. This method will be called for each written message that can be handled by this encoder.

ctx the which this io.netty.handler.codec.MessageToMessageDecoder belongs to
msg the SingleMetric to be batched up
out the java.util.List to which decoded messages should be added if the batch size is reached
java.lang.Exception is thrown if an error occurs
    protected void decode(ChannelHandlerContext ctxSingleMetric msgList<Objectoutthrows Exception {
        List<SingleMetriccached = ctx.attr().get();
        if (cached==null) {
            cached = new ArrayList<>();
        if (cached.size()  >= ) {
            List<SingleMetrictoForward = new ArrayList<>(cached.size()+1);
        } else {
New to GrepCode? Check out our FAQ X