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();
}
}
};
}
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);
}
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);
}
};
}
Aggregations