Search in sources :

Example 1 with StreamObserver

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);
}
Also used : StreamObserver(org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver) SnapshotInfo(org.apache.ratis.statemachine.SnapshotInfo) TermIndex(org.apache.ratis.server.protocol.TermIndex)

Example 2 with StreamObserver

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();
        }
    };
}
Also used : StreamObserver(org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver) Status(org.apache.ratis.thirdparty.io.grpc.Status) TransferReplyProto(org.apache.ratis.proto.ExperimentsProtos.TransferReplyProto) TransferMsgProto(org.apache.ratis.proto.ExperimentsProtos.TransferMsgProto)

Example 3 with StreamObserver

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();
        }
    };
}
Also used : StreamObserver(org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver) Status(org.apache.ratis.thirdparty.io.grpc.Status) FlatBufferBuilder(org.apache.ratis.thirdparty.com.google.flatbuffers.FlatBufferBuilder) TransferReply(org.apache.ratis.flatbufs.TransferReply) TransferMsg(org.apache.ratis.flatbufs.TransferMsg)

Aggregations

StreamObserver (org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver)3 Status (org.apache.ratis.thirdparty.io.grpc.Status)2 TransferMsg (org.apache.ratis.flatbufs.TransferMsg)1 TransferReply (org.apache.ratis.flatbufs.TransferReply)1 TransferMsgProto (org.apache.ratis.proto.ExperimentsProtos.TransferMsgProto)1 TransferReplyProto (org.apache.ratis.proto.ExperimentsProtos.TransferReplyProto)1 TermIndex (org.apache.ratis.server.protocol.TermIndex)1 SnapshotInfo (org.apache.ratis.statemachine.SnapshotInfo)1 FlatBufferBuilder (org.apache.ratis.thirdparty.com.google.flatbuffers.FlatBufferBuilder)1