@@ -0,0 +1,2300 @@
+package com.tacitknowledge.performance.data;%0A%0Aimport org.apache.commons.lang.math.RandomUtils;%0A%0Aimport com.tacitknowledge.performance.Component;%0A%0Aimport io.netty.buffer.ByteBuf;%0Aimport io.netty.channel.ChannelFuture;%0Aimport io.netty.channel.ChannelFutureListener;%0Aimport io.netty.channel.ChannelHandlerContext;%0Aimport io.netty.channel.ChannelInboundHandlerAdapter;%0Aimport io.netty.channel.socket.SocketChannel;%0A%0A/** @author Ivan Frolov (ifrolov@tacitknowledge.com) */%0Apublic class RandomBinary implements Component%0A%7B%0A    private final static int BUF_SIZE = 2048;%0A%0A    private final int maxSize;%0A%0A    public RandomBinary(final int maxSize)%0A    %7B%0A        this.maxSize = maxSize;%0A    %7D%0A%0A    @Override%0A    public void initChannel(final SocketChannel ch)%0A    %7B%0A        ch.pipeline().addLast(new ChannelInboundHandlerAdapter()%7B%0A            @Override%0A            public void channelActive(final ChannelHandlerContext ctx) throws Exception%0A            %7B%0A                ctx.executor().submit(new Task(ctx));%0A            %7D%0A%0A            @Override%0A            public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception%0A            %7B%0A                ctx.channel().close();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private final class Task implements Runnable%7B%0A        private final ChannelHandlerContext ctx;%0A        private int totalSent = 0;%0A%0A        private Task(final ChannelHandlerContext ctx)%0A        %7B%0A            this.ctx = ctx;%0A        %7D%0A%0A        @Override%0A        public void run()%0A        %7B%0A            int toSend = Math.min(BUF_SIZE, maxSize - totalSent);%0A            ByteBuf buf = ctx.channel().alloc().buffer(toSend);%0A            totalSent += toSend;%0A%0A            while(buf.isWritable()) %7B%0A                buf.writeByte(RandomUtils.nextInt(256));%0A            %7D%0A%0A            ctx.channel().writeAndFlush(buf).addListener(new ChannelFutureListener()%7B%0A                @Override%0A                public void operationComplete(final ChannelFuture future) throws Exception%0A                %7B%0A                    if(future.isSuccess() && totalSent %3C maxSize) %7B%0A                        ctx.executor().submit(Task.this);%0A                    %7D else %7B%0A                        ctx.channel().close();%0A                    %7D%0A                %7D%0A            %7D);%0A%0A        %7D%0A    %7D%0A%7D%0A

Implement random binary data generator