@Before public void initialize() { MockitoAnnotations.initMocks(this); when(context.nextInboundMessageBuffer()).thenReturn(buf); when(buf.add(anyObject())).thenReturn(true); when(context.nextOutboundMessageBuffer()).thenReturn(outboundBuf); }
@Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { log.info("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions()); final MessageBuf<Object> out = ctx.nextOutboundMessageBuffer(); out.add(message); ctx.flush(); }
@Override protected void messageReceived(final ChannelHandlerContext ctx, final UdtMessage message) throws Exception { final ByteBuf byteBuf = message.data(); meter.mark(byteBuf.readableBytes()); final MessageBuf<Object> out = ctx.nextOutboundMessageBuffer(); out.add(message); ctx.flush(); }
@Override public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { ByteBuf in = ctx.outboundByteBuffer(); try { MessageBuf<Object> out = ctx.nextOutboundMessageBuffer(); ByteBuf payload = Unpooled.buffer(in.readableBytes()); payload.writeBytes(in); out.add(new SctpMessage(streamIdentifier, protocolIdentifier, payload)); in.discardReadBytes(); } catch (Throwable t) { ctx.fireExceptionCaught(new EncoderException(t)); } ctx.flush(promise); }