Java Code Examples for com.google.protobuf.Empty#getDefaultInstance()

The following examples show how to use com.google.protobuf.Empty#getDefaultInstance() . 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: FluxMethodBridge.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private FluxInvocation(FluxSink<Object> sink, Object[] args) {
    StreamObserver<Object> grpcStreamObserver = new ClientResponseObserver<Object, Object>() {
        @Override
        public void beforeStart(ClientCallStreamObserver requestStream) {
            sink.onCancel(() -> requestStream.cancel("React subscription cancelled", null));
        }

        @Override
        public void onNext(Object value) {
            sink.next(value);
        }

        @Override
        public void onError(Throwable error) {
            sink.error(error);
        }

        @Override
        public void onCompleted() {
            sink.complete();
        }
    };

    Object[] grpcArgs = new Object[]{
            grpcArgPos < 0 ? Empty.getDefaultInstance() : args[grpcArgPos],
            grpcStreamObserver
    };

    GRPC_STUB invocationStub = handleCallMetadata(args)
            .withDeadline(Deadline.after(timeout.toMillis(), TimeUnit.MILLISECONDS));

    try {
        grpcMethod.invoke(invocationStub, grpcArgs);
    } catch (Exception e) {
        sink.error(e);
    }
}
 
Example 2
Source File: ChatImpl.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Empty broadcast(ChatProto.ChatMessage message) {
    logger.info(message.getAuthor() + ": " + message.getMessage());
    broadcast.onNext(message);
    return Empty.getDefaultInstance();
}
 
Example 3
Source File: SeedLibrarySchemaModule.java    From rejoiner with Apache License 2.0 4 votes vote down vote up
@Mutation("seed")
Empty seed(
    ShelfServiceGrpc.ShelfServiceBlockingStub shelfClient,
    BookServiceGrpc.BookServiceBlockingStub bookClient) {

  String greatExpectations =
      bookClient
          .createBook(
              CreateBookRequest.newBuilder()
                  .setBook(
                      Book.newBuilder()
                          .setAuthor("Charles Dickens")
                          .setTitle("Great Expectations")
                          .setRead(false))
                  .build())
          .getId();
  String thinkingFastAndSlow =
      bookClient
          .createBook(
              CreateBookRequest.newBuilder()
                  .setBook(
                      Book.newBuilder()
                          .setAuthor("Daniel Kahnemann")
                          .setTitle("Thinking, Fast and Slow")
                          .setRead(true))
                  .build())
          .getId();
  String theCatcherInTheRye =
      bookClient
          .createBook(
              CreateBookRequest.newBuilder()
                  .setBook(
                      Book.newBuilder()
                          .setAuthor("J. D. Salinger")
                          .setTitle("The Catcher in the Rye")
                          .setRead(false))
                  .build())
          .getId();
  String huckleberryFinn =
      bookClient
          .createBook(
              CreateBookRequest.newBuilder()
                  .setBook(
                      Book.newBuilder()
                          .setAuthor("Mark Twain")
                          .setTitle("The Adventures of Huckleberry Finn")
                          .setRead(false))
                  .build())
          .getId();
  String masterAndMargarita =
      bookClient
          .createBook(
              CreateBookRequest.newBuilder()
                  .setBook(
                      Book.newBuilder()
                          .setAuthor("Mikhail Bulgakov")
                          .setTitle("The Master and Margarita")
                          .setRead(false))
                  .build())
          .getId();
  String warAndPeace =
      bookClient
          .createBook(
              CreateBookRequest.newBuilder()
                  .setBook(
                      Book.newBuilder()
                          .setAuthor("Leo Tolstoy")
                          .setTitle("War and Peace")
                          .setRead(true))
                  .build())
          .getId();

  shelfClient.createShelf(
      CreateShelfRequest.newBuilder()
          .setShelf(
              Shelf.newBuilder()
                  .setTheme("Satire")
                  .addAllBookIds(ImmutableList.of(greatExpectations, thinkingFastAndSlow))
                  .build())
          .build());
  shelfClient.createShelf(
      CreateShelfRequest.newBuilder()
          .setShelf(
              Shelf.newBuilder()
                  .setTheme("Classics")
                  .addAllBookIds(ImmutableList.of(theCatcherInTheRye, huckleberryFinn))
                  .build())
          .build());
  shelfClient.createShelf(
      CreateShelfRequest.newBuilder()
          .setShelf(
              Shelf.newBuilder()
                  .setTheme("Russian")
                  .addAllBookIds(ImmutableList.of(masterAndMargarita, warAndPeace))
                  .build())
          .build());
  return Empty.getDefaultInstance();
}
 
Example 4
Source File: MonoMethodBridge.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private MonoInvocation(MonoSink<Object> sink, Object[] args) {
    StreamObserver<Object> grpcStreamObserver = new ClientResponseObserver<Object, Object>() {
        @Override
        public void beforeStart(ClientCallStreamObserver requestStream) {
            sink.onCancel(() -> requestStream.cancel("React subscription cancelled", null));
        }

        @Override
        public void onNext(Object value) {
            if (emptyToVoidReply) {
                sink.success();
            } else {
                sink.success(value);
            }
        }

        @Override
        public void onError(Throwable error) {
            sink.error(error);
        }

        @Override
        public void onCompleted() {
            sink.success();
        }
    };

    Object[] grpcArgs = new Object[]{
            grpcArgPos < 0 ? Empty.getDefaultInstance() : args[grpcArgPos],
            grpcStreamObserver
    };

    GRPC_STUB invocationStub = handleCallMetadata(args)
            .withDeadline(Deadline.after(timeout.toMillis(), TimeUnit.MILLISECONDS));

    try {
        grpcMethod.invoke(invocationStub, grpcArgs);
    } catch (Exception e) {
        sink.error(e);
    }
}