use of org.apache.ratis.experiments.nettyzerocopy.objects.RequestData in project incubator-ratis by apache.
the class RequestDecoder method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
if (msg.readableBytes() >= 8) {
int id = msg.readInt();
int buflen = msg.readInt();
if (msg.readableBytes() >= buflen) {
RequestData req = new RequestData();
req.setDataId(id);
// System.out.printf("msg id and buflen %d and %d bytes\n", id, buflen, msg.readableBytes());
try {
ByteBuf bf = msg.slice(msg.readerIndex(), buflen);
req.setBuff(bf.nioBuffer());
} catch (Exception e) {
System.out.println(e);
}
msg.readerIndex(msg.readerIndex() + buflen);
msg.markReaderIndex();
out.add(req);
} else {
msg.resetReaderIndex();
return;
}
} else {
return;
}
}
use of org.apache.ratis.experiments.nettyzerocopy.objects.RequestData in project incubator-ratis by apache.
the class NettyClient method startTransfer.
public void startTransfer() throws InterruptedException {
int cur = 1;
ByteBuffer bf = ByteBuffer.allocateDirect(1024 * 1024);
for (int i = 0; i < bf.capacity(); i++) {
bf.put((byte) 'a');
}
bf.flip();
startTime = System.nanoTime();
while (cur <= times) {
RequestData msg = new RequestData();
msg.setDataId(cur);
bf.position(0).limit(bf.capacity());
msg.setBuff(bf.slice());
transferMessage(msg);
cur++;
}
System.out.println("Sent all messages.");
}
Aggregations