use of org.apache.ratis.proto.ExperimentsProtos.TransferReplyProto in project incubator-ratis by apache.
the class ClientProto method execProto.
public void execProto(int reps) throws Exception {
System.out.println("Starting streaming with Protobuffers");
StreamObserver<TransferMsgProto> requestObserver = asyncStubProto.sendData(new StreamObserver<TransferReplyProto>() {
@Override
public void onNext(TransferReplyProto msg) {
available.release();
recv[0]++;
}
@Override
public void onError(Throwable t) {
Status status = Status.fromThrowable(t);
System.out.println(status);
System.out.println("Finished streaming with errors");
}
@Override
public void onCompleted() {
System.out.println("Finished streaming");
}
});
try {
int i = 0;
// allocate a byte buffer containing message data.
ByteBuffer bf = ByteBuffer.allocate(1024 * 1024);
if (bf.hasArray()) {
Arrays.fill(bf.array(), (byte) 'a');
}
while (i < reps) {
partId++;
available.acquire();
// using unsafewrap operations
// creates a ByteString refrencing buffer data. Avoids Copying.
// Something similar is missing in flatbuffers.
TransferMsgProto msg = TransferMsgProto.newBuilder().setPartId(partId).setData(UnsafeByteOperations.unsafeWrap(bf)).build();
requestObserver.onNext(msg);
i++;
}
} catch (Exception e) {
System.out.println(e);
}
requestObserver.onCompleted();
Thread.sleep(1000 * 100);
if (recv[0] == partId) {
System.out.println("Transfer Successfull....");
} else {
System.out.println("Some error occurred...");
}
}
use of org.apache.ratis.proto.ExperimentsProtos.TransferReplyProto in project incubator-ratis by apache.
the class FileTransferProtobufs method sendData.
@Override
public StreamObserver<TransferMsgProto> sendData(final StreamObserver<TransferReplyProto> responseObserver) {
return new StreamObserver<TransferMsgProto>() {
private long rcvdDataSize = 0;
public long getRcvdDataSize() {
return rcvdDataSize;
}
@Override
public void onNext(TransferMsgProto msg) {
rcvdDataSize += msg.getData().size();
TransferReplyProto rep = TransferReplyProto.newBuilder().setPartId(msg.getPartId()).setMessage("OK").build();
responseObserver.onNext(rep);
}
@Override
public void onError(Throwable t) {
Status status = Status.fromThrowable(t);
System.out.println(status);
System.out.println("Finished streaming with errors");
}
@Override
public void onCompleted() {
responseObserver.onCompleted();
}
};
}
Aggregations