Ejemplo n.º 1
0
 @Before
 public void initialize() {
   MockitoAnnotations.initMocks(this);
   when(context.nextInboundMessageBuffer()).thenReturn(buf);
   when(buf.add(anyObject())).thenReturn(true);
   when(context.nextOutboundMessageBuffer()).thenReturn(outboundBuf);
 }
Ejemplo n.º 2
0
 @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();
 }
Ejemplo n.º 3
0
 @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);
  }