Java Code Examples for com.google.protobuf.DescriptorProtos.MethodDescriptorProto#getClientStreaming()

The following examples show how to use com.google.protobuf.DescriptorProtos.MethodDescriptorProto#getClientStreaming() . 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: PrintServiceFile.java    From saluki with Apache License 2.0 6 votes vote down vote up
private String generateMethod(MethodDescriptorProto method, String inPutType, String outPutType,
    String methodName, String inputValue) {
  String methodStr =
      "public " + outPutType + " " + methodName + "(" + inPutType + " " + inputValue + ");";
  boolean isClientStream = !method.getServerStreaming() && method.getClientStreaming();
  boolean isBidiStream = method.getServerStreaming() && method.getClientStreaming();
  boolean isServerStream = method.getServerStreaming() && !method.getClientStreaming();
  if (isClientStream || isBidiStream) {
    methodStr =
        "public " + inPutType + " " + methodName + "(" + outPutType + " responseObserver);";
  } else if (isServerStream) {
    methodStr = "public void " + methodName + "(" + inPutType + " " + inputValue + ","
        + outPutType + " responseObserver);";
  }
  return methodStr;
}
 
Example 2
Source File: Generator.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private static ClassName routeInterfaceClass(final MethodDescriptorProto methodProto, final boolean blocking) {
    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? blocking ? BlockingStreamingRoute : StreamingRoute :
                    blocking ? BlockingRequestStreamingRoute : RequestStreamingRoute) :
            (methodProto.getServerStreaming() ? blocking ? BlockingResponseStreamingRoute : ResponseStreamingRoute
                    : blocking ? BlockingRoute : Route);
}
 
Example 3
Source File: Generator.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private static ClassName clientCallClass(final MethodDescriptorProto methodProto, final boolean blocking) {
    if (!blocking) {
        return methodProto.getClientStreaming() ?
                (methodProto.getServerStreaming() ? StreamingClientCall : RequestStreamingClientCall) :
                (methodProto.getServerStreaming() ? ResponseStreamingClientCall : ClientCall);
    }

    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? BlockingStreamingClientCall : BlockingRequestStreamingClientCall) :
            (methodProto.getServerStreaming() ? BlockingResponseStreamingClientCall : BlockingClientCall);
}
 
Example 4
Source File: ReactiveGrpcGenerator.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations, int methodNumber) {
    MethodContext methodContext = new MethodContext();
    methodContext.methodName = lowerCaseFirst(methodProto.getName());
    methodContext.inputType = typeMap.toJavaTypeName(methodProto.getInputType());
    methodContext.outputType = typeMap.toJavaTypeName(methodProto.getOutputType());
    methodContext.deprecated = methodProto.getOptions() != null && methodProto.getOptions().getDeprecated();
    methodContext.isManyInput = methodProto.getClientStreaming();
    methodContext.isManyOutput = methodProto.getServerStreaming();
    methodContext.methodNumber = methodNumber;

    Location methodLocation = locations.stream()
            .filter(location ->
                location.getPathCount() == METHOD_NUMBER_OF_PATHS &&
                    location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber
            )
            .findFirst()
            .orElseGet(Location::getDefaultInstance);
    methodContext.javaDoc = getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix());

    if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "oneToOne";
        methodContext.grpcCallsMethodName = "asyncUnaryCall";
    }
    if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "oneToMany";
        methodContext.grpcCallsMethodName = "asyncServerStreamingCall";
    }
    if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "manyToOne";
        methodContext.grpcCallsMethodName = "asyncClientStreamingCall";
    }
    if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "manyToMany";
        methodContext.grpcCallsMethodName = "asyncBidiStreamingCall";
    }
    return methodContext;
}
 
Example 5
Source File: PrintServiceFile.java    From saluki with Apache License 2.0 5 votes vote down vote up
@Override
protected List<String> collectFileData() {
  String className = super.getClassName();
  String packageName = super.getSourcePackageName().toLowerCase();
  List<String> fileData = Lists.newArrayList();
  fileData.add("package " + packageName + ";");
  fileData.add("public interface " + className + "{");
  for (MethodDescriptorProto method : serviceMethods) {
    String outPutType = method.getOutputType();
    String inPutType = method.getInputType();
    String methodName = method.getName();
    inPutType = CommonUtils.findPojoTypeFromCache(inPutType, pojoTypeCache);
    outPutType = CommonUtils.findPojoTypeFromCache(outPutType, pojoTypeCache);
    String stream = generateGrpcStream(method, inPutType, outPutType);
    if (method.getServerStreaming() || method.getClientStreaming()) {
      outPutType = "io.grpc.stub.StreamObserver<" + outPutType + ">";
    }
    String inputValue = CommonUtils.findNotIncludePackageType(inPutType).toLowerCase();
    if (method.getClientStreaming()) {
      inPutType = "io.grpc.stub.StreamObserver<" + inPutType + ">";
    }
    if (stream != null)
      fileData.add(stream);
    String methodStr = generateMethod(method, inPutType, outPutType, methodName, inputValue);
    fileData.add(methodStr);
  }
  fileData.add("}");
  return fileData;
}
 
Example 6
Source File: Method.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private Method(Interface parent, MethodDescriptorProto proto, String path) {
  super(parent, proto.getName(), path);
  this.isDeprecated = proto.getOptions().getDeprecated();
  this.descriptor = new MethodDescriptor(proto);
  this.requestStreaming = proto.getClientStreaming();
  this.responseStreaming = proto.getServerStreaming();
}
 
Example 7
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private MethodSpec newRpcMethodSpec(final MethodDescriptorProto methodProto, final EnumSet<NewRpcMethodFlag> flags,
                                    final BiFunction<String, MethodSpec.Builder, MethodSpec.Builder>
                                            methodBuilderCustomizer) {

    final ClassName inClass = messageTypesMap.get(methodProto.getInputType());
    final ClassName outClass = messageTypesMap.get(methodProto.getOutputType());

    final String name = routeName(methodProto);

    final MethodSpec.Builder methodSpecBuilder = methodBuilderCustomizer.apply(name, methodBuilder(name))
            .addModifiers(PUBLIC);

    final Modifier[] mods = flags.contains(INTERFACE) ? new Modifier[0] : new Modifier[]{FINAL};

    if (flags.contains(BLOCKING)) {
        methodSpecBuilder.addException(Exception.class);

        if (methodProto.getClientStreaming()) {
            if (flags.contains(CLIENT)) {
                methodSpecBuilder.addParameter(ParameterizedTypeName.get(ClassName.get(Iterable.class),
                        inClass), request, mods);
            } else {
                methodSpecBuilder.addParameter(ParameterizedTypeName.get(BlockingIterable, inClass), request,
                        mods);
            }
        } else {
            methodSpecBuilder.addParameter(inClass, request, mods);
        }

        if (methodProto.getServerStreaming()) {
            if (flags.contains(CLIENT)) {
                methodSpecBuilder.returns(ParameterizedTypeName.get(BlockingIterable, outClass));
            } else {
                methodSpecBuilder.addParameter(ParameterizedTypeName.get(GrpcPayloadWriter, outClass),
                        "responseWriter", mods);
            }
        } else {
            methodSpecBuilder.returns(outClass);
        }
    } else {
        if (methodProto.getClientStreaming()) {
            methodSpecBuilder.addParameter(ParameterizedTypeName.get(Publisher, inClass), request, mods);
        } else {
            methodSpecBuilder.addParameter(inClass, request, mods);
        }

        if (methodProto.getServerStreaming()) {
            methodSpecBuilder.returns(ParameterizedTypeName.get(Publisher, outClass));
        } else {
            methodSpecBuilder.returns(ParameterizedTypeName.get(Single, outClass));
        }
    }

    return methodSpecBuilder.build();
}
 
Example 8
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static ClassName routeInterfaceClass(final MethodDescriptorProto methodProto) {
    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? StreamingRoute : RequestStreamingRoute) :
            (methodProto.getServerStreaming() ? ResponseStreamingRoute : Route);
}
 
Example 9
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static String routeFactoryMethodName(final MethodDescriptorProto methodProto) {
    return (methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? "streamingR" : "requestStreamingR") :
            (methodProto.getServerStreaming() ? "responseStreamingR" : "r")) +
            "outeFor";
}
 
Example 10
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static String streamingNameModifier(final MethodDescriptorProto methodProto) {
    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? "Streaming" : "RequestStreaming") :
            (methodProto.getServerStreaming() ? "ResponseStreaming" : "");
}
 
Example 11
Source File: AbstractGenerator.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations,
                                         int methodNumber) {
    MethodContext methodContext = new MethodContext();
    methodContext.setMethodName(lowerCaseFirst(methodProto.getName()));
    methodContext.setInputType(typeMap.toJavaTypeName(methodProto.getInputType()));
    methodContext.setOutputType(typeMap.toJavaTypeName(methodProto.getOutputType()));
    methodContext.setDeprecated(methodProto.getOptions() != null && methodProto.getOptions().getDeprecated());
    methodContext.setManyInput(methodProto.getClientStreaming());
    methodContext.setManyOutput(methodProto.getServerStreaming());
    methodContext.setMethodNumber(methodNumber);

    Optional<Location> found = Optional.empty();
    for (Location location : locations) {
        if (location.getPathCount() == METHOD_NUMBER_OF_PATHS &&
                location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber) {
            found = Optional.of(location);
            break;
        }
    }
    Location methodLocation = found
            .orElseGet(Location::getDefaultInstance);
    methodContext.setJavaDoc(getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix()));

    if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("oneToOne");
        methodContext.setGrpcCallsMethodName("asyncUnaryCall");
    }
    if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("oneToMany");
        methodContext.setGrpcCallsMethodName("asyncServerStreamingCall");
    }
    if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("manyToOne");
        methodContext.setGrpcCallsMethodName("asyncClientStreamingCall");
    }
    if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("manyToMany");
        methodContext.setGrpcCallsMethodName("asyncBidiStreamingCall");
    }
    return methodContext;
}