Java Code Examples for io.grpc.stub.ServerCallStreamObserver#request()

The following examples show how to use io.grpc.stub.ServerCallStreamObserver#request() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoReflectionService.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public StreamObserver<ServerReflectionRequest> serverReflectionInfo(
    final StreamObserver<ServerReflectionResponse> responseObserver) {
  final ServerCallStreamObserver<ServerReflectionResponse> serverCallStreamObserver =
      (ServerCallStreamObserver<ServerReflectionResponse>) responseObserver;
  ProtoReflectionStreamObserver requestObserver =
      new ProtoReflectionStreamObserver(updateIndexIfNecessary(), serverCallStreamObserver);
  serverCallStreamObserver.setOnReadyHandler(requestObserver);
  serverCallStreamObserver.disableAutoInboundFlowControl();
  serverCallStreamObserver.request(1);
  return requestObserver;
}
 
Example 2
Source File: ByteStreamService.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private ServerCallStreamObserver<WriteResponse> initializeBackPressure(
    StreamObserver<WriteResponse> responseObserver) {
  final ServerCallStreamObserver<WriteResponse> serverCallStreamObserver =
      (ServerCallStreamObserver<WriteResponse>) responseObserver;
  serverCallStreamObserver.disableAutoInboundFlowControl();
  serverCallStreamObserver.request(1);
  return serverCallStreamObserver;
}
 
Example 3
Source File: ByteStreamService.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@Override
public StreamObserver<WriteRequest> write(StreamObserver<WriteResponse> responseObserver) {
  ServerCallStreamObserver<WriteResponse> serverCallStreamObserver =
      initializeBackPressure(responseObserver);
  return new WriteStreamObserver(
      instances,
      deadlineAfter,
      deadlineAfterUnits,
      () -> serverCallStreamObserver.request(1),
      responseObserver);
}
 
Example 4
Source File: GrpcFlowControlTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public StreamObserver<SimpleRequest> serverBackPressure(
        StreamObserver<SimpleResponse> rawResponseObserver) {
    final ServerCallStreamObserver<SimpleResponse> responseObserver =
            (ServerCallStreamObserver<SimpleResponse>) rawResponseObserver;
    responseObserver.disableAutoInboundFlowControl();
    final AtomicInteger numRequests = new AtomicInteger();
    responseObserver.request(1);
    return new StreamObserver<SimpleRequest>() {
        @Override
        public void onNext(SimpleRequest value) {
            if (numRequests.incrementAndGet() < CAPPED_NUM_MESSAGES) {
                responseObserver.request(1);
            } else {
                for (int i = 0; i < TOTAL_NUM_MESSAGES; i++) {
                    responseObserver.onNext(SimpleResponse.getDefaultInstance());
                }
                responseObserver.onCompleted();
            }
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onCompleted() {
        }
    };
}
 
Example 5
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public StreamObserver<ServerReflectionRequest> serverReflectionInfo(
    final StreamObserver<ServerReflectionResponse> responseObserver) {
  final ServerCallStreamObserver<ServerReflectionResponse> serverCallStreamObserver =
      (ServerCallStreamObserver<ServerReflectionResponse>) responseObserver;
  ProtoReflectionStreamObserver requestObserver =
      new ProtoReflectionStreamObserver(getRefreshedIndex(), serverCallStreamObserver);
  serverCallStreamObserver.setOnReadyHandler(requestObserver);
  serverCallStreamObserver.disableAutoRequest();
  serverCallStreamObserver.request(1);
  return requestObserver;
}