1. @Slf4j
    2. public class TestEmbeddedChannel {
    3. public static void main(String[] args) {
    4. ChannelInboundHandlerAdapter h1 = new ChannelInboundHandlerAdapter() {
    5. @Override
    6. public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    7. log.debug("1");
    8. super.channelRead(ctx, msg);
    9. }
    10. };
    11. ChannelInboundHandlerAdapter h2 = new ChannelInboundHandlerAdapter() {
    12. @Override
    13. public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    14. log.debug("2");
    15. super.channelRead(ctx, msg);
    16. }
    17. };
    18. ChannelOutboundHandlerAdapter h3 = new ChannelOutboundHandlerAdapter() {
    19. @Override
    20. public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    21. log.debug("3");
    22. super.write(ctx, msg, promise);
    23. }
    24. };
    25. ChannelOutboundHandlerAdapter h4 = new ChannelOutboundHandlerAdapter() {
    26. @Override
    27. public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    28. log.debug("4");
    29. super.write(ctx, msg, promise);
    30. }
    31. };
    32. EmbeddedChannel channel = new EmbeddedChannel(h1, h2, h3, h4);
    33. // 模拟入站操作
    34. // channel.writeInbound(ByteBufAllocator.DEFAULT.buffer().writeBytes("hello".getBytes()));
    35. // 模拟出站操作
    36. channel.writeOutbound(ByteBufAllocator.DEFAULT.buffer().writeBytes("world".getBytes()));
    37. }
    38. }