Last active
August 29, 2015 14:07
-
-
Save normanmaurer/f0b6086a6002891a43a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.netty.example.http.snoop; | |
import io.netty.buffer.ByteBuf; | |
import io.netty.channel.ChannelHandlerContext; | |
import io.netty.channel.ChannelOutboundHandlerAdapter; | |
import io.netty.channel.ChannelPromise; | |
public class HttpResponseDelayHandler extends ChannelOutboundHandlerAdapter { | |
@Override | |
public void write(ChannelHandlerContext ctx, Object msg, final ChannelPromise promise) { | |
ByteBuf buf = (ByteBuf) msg; | |
int totalSize = buf.readableBytes(); | |
int slice1 = totalSize/2; | |
int slice2 = totalSize - slice1; | |
ByteBuf out = buf.readSlice(slice1).retain(); | |
final ByteBuf out2 = buf.readSlice(slice2).retain(); | |
ctx.write(out); | |
ctx.executor().schedule(new Runnable() { | |
@Override | |
public void run() { | |
ctx.writeAndFlush(out2, promise); | |
} | |
}, 3, TimeUnit.SECONDS); | |
buf.release(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment