use of org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver in project incubator-ratis by apache.
the class GrpcLogAppender method run.
@Override
public void run() throws IOException {
boolean installSnapshotRequired;
for (; isRunning(); mayWait()) {
installSnapshotRequired = false;
// HB period is expired OR we have messages OR follower is behind with commit index
if (shouldSendAppendEntries() || isFollowerCommitBehindLastCommitIndex()) {
if (installSnapshotEnabled) {
SnapshotInfo snapshot = shouldInstallSnapshot();
if (snapshot != null) {
installSnapshot(snapshot);
installSnapshotRequired = true;
}
} else {
TermIndex installSnapshotNotificationTermIndex = shouldNotifyToInstallSnapshot();
if (installSnapshotNotificationTermIndex != null) {
installSnapshot(installSnapshotNotificationTermIndex);
installSnapshotRequired = true;
}
}
appendLog(installSnapshotRequired || haveTooManyPendingRequests());
}
getLeaderState().checkHealth(getFollower());
}
Optional.ofNullable(appendLogRequestObserver).ifPresent(StreamObserver::onCompleted);
}
use of org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver 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();
}
};
}
use of org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver in project incubator-ratis by apache.
the class FileTransferFlatbufs method sendData.
@Override
public StreamObserver<TransferMsg> sendData(final StreamObserver<TransferReply> responseObserver) {
return new StreamObserver<TransferMsg>() {
private long rcvdDataSize = 0;
public long getRcvdDataSize() {
return rcvdDataSize;
}
@Override
public void onNext(TransferMsg msg) {
rcvdDataSize += msg.dataLength();
FlatBufferBuilder builder = new FlatBufferBuilder();
int off = TransferReply.createTransferReply(builder, msg.partId(), builder.createString("OK"));
builder.finish(off);
TransferReply rep = TransferReply.getRootAsTransferReply(builder.dataBuffer());
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() {
System.out.println(rcvdDataSize);
responseObserver.onCompleted();
}
};
}
Aggregations