Search in sources :

Example 1 with ResponseData

use of org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData in project incubator-ratis by apache.

the class NettyClient method getClientHandler.

/**
 * Client handler for server messages.
 * @return ChannelInboundHandler
 */
private ChannelInboundHandler getClientHandler() {
    return new ChannelInboundHandlerAdapter() {

        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws InterruptedException {
            final ResponseData reply = (ResponseData) msg;
            if (reply.getId() == times) {
                System.out.println("Received all messages, closing client.");
                timeClient();
                closeClient();
            }
        }
    };
}
Also used : ResponseData(org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData)

Example 2 with ResponseData

use of org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData in project incubator-ratis by apache.

the class ResponseDecoder method decode.

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
    ResponseData reply = new ResponseData();
    reply.setId(byteBuf.readInt());
    list.add(reply);
}
Also used : ResponseData(org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData)

Example 3 with ResponseData

use of org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData in project incubator-ratis by apache.

the class NettyServer method getServerHandler.

/**
 * Casts inbound message as {@link RequestDataComposite}
 * because a NIO CompositeByteBuf interface is needed to allow for zero-copy.
 * @return ChannelInboundHandler
 */
private ChannelInboundHandler getServerHandler() {
    return new ChannelInboundHandlerAdapter() {

        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            final ResponseData reply = new ResponseData();
            RequestDataComposite req = (RequestDataComposite) msg;
            req.getBuff().release();
            reply.setId(req.getDataId());
            ctx.writeAndFlush(reply);
        }
    };
}
Also used : RequestDataComposite(org.apache.ratis.experiments.nettyzerocopy.objects.RequestDataComposite) ResponseData(org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData)

Aggregations

ResponseData (org.apache.ratis.experiments.nettyzerocopy.objects.ResponseData)3 RequestDataComposite (org.apache.ratis.experiments.nettyzerocopy.objects.RequestDataComposite)1