Java Code Examples for io.grpc.MethodDescriptor.MethodType#CLIENT_STREAMING

The following examples show how to use io.grpc.MethodDescriptor.MethodType#CLIENT_STREAMING . 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: DynamicGrpcClient.java    From milkman with MIT License 5 votes vote down vote up
/**
 * Makes an rpc to the remote endpoint and respects the supplied callback. Returns a future which
 * terminates once the call has ended. For calls which are single-request, this throws
 * {@link IllegalArgumentException} if the size of {@code requests} is not exactly 1.
 */
public ListenableFuture<Void> call(
    ImmutableList<DynamicMessage> requests,
    StreamObserver<DynamicMessage> responseObserver,
    CallOptions callOptions) {
  Preconditions.checkArgument(!requests.isEmpty(), "Can't make call without any requests");
  MethodType methodType = getMethodType();
  long numRequests = requests.size();
  if (methodType == MethodType.UNARY) {
    logger.info("Making unary call");
    Preconditions.checkArgument(numRequests == 1,
        "Need exactly 1 request for unary call, but got: " + numRequests);
    return callUnary(requests.get(0), responseObserver, callOptions);
  } else if (methodType == MethodType.SERVER_STREAMING) {
    logger.info("Making server streaming call");
    Preconditions.checkArgument(numRequests == 1,
        "Need exactly 1 request for server streaming call, but got: " + numRequests);
    return callServerStreaming(requests.get(0), responseObserver, callOptions);
  } else if (methodType == MethodType.CLIENT_STREAMING) {
    logger.info("Making client streaming call with " + requests.size() + " requests");
    return callClientStreaming(requests, responseObserver, callOptions);
  } else {
    // Bidi streaming.
    logger.info("Making bidi streaming call with " + requests.size() + " requests");
    return callBidiStreaming(requests, responseObserver, callOptions);
  }
}
 
Example 2
Source File: DynamicGrpcClient.java    From milkman with MIT License 5 votes vote down vote up
/** Returns the appropriate method type based on whether the client or server expect streams. */
private MethodType getMethodType() {
  boolean clientStreaming = protoMethodDescriptor.toProto().getClientStreaming();
  boolean serverStreaming = protoMethodDescriptor.toProto().getServerStreaming();

  if (!clientStreaming && !serverStreaming) {
    return MethodType.UNARY;
  } else if (!clientStreaming && serverStreaming) {
    return MethodType.SERVER_STREAMING;
  } else if (clientStreaming && !serverStreaming) {
    return MethodType.CLIENT_STREAMING;
  } else {
    return MethodType.BIDI_STREAMING;
  }
}
 
Example 3
Source File: GrpcMethod.java    From java-grpc-prometheus with Apache License 2.0 4 votes vote down vote up
boolean streamsRequests() {
  return type == MethodType.CLIENT_STREAMING || type == MethodType.BIDI_STREAMING;
}