All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dreamhead.moco.internal.MocoAggregator Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.internal;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class MocoAggregator extends ChannelInboundHandlerAdapter {
    private CompositeByteBuf bufs =  ByteBufAllocator.DEFAULT.compositeBuffer();

    @Override
    public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
        if (msg instanceof ByteBuf) {
            ByteBuf buf = (ByteBuf) msg;
            bufs.addComponent(buf);
            bufs.writerIndex(bufs.writerIndex() + buf.writerIndex());
        }
    }

    @Override
    public void channelReadComplete(final ChannelHandlerContext ctx) throws Exception {
        if (bufs.numComponents() > 0) {
            ctx.fireChannelRead(bufs);
            bufs = ByteBufAllocator.DEFAULT.compositeBuffer();
        }

        ctx.fireChannelReadComplete();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy