grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

CompletableFuture stubs

Open rmichela opened this issue 8 years ago • 9 comments

Hello, I'd like to start a discussion about adding a CompletableFuture-based stub implementations to gRPC. I understand that generated gRPC code must be backwards compatible with Java 6, so here are some alternative implementation strategies to consider.

  1. Implement CompletableFuture-based stubs in a stand-alone class generated by a stand-alone protoc plugin. The CF stub class would reference the public MethodDescriptors of the stock generated client. This option is easiest to implement, but presents a fragmented programming model.
  2. Implement CompletableFuture-based stubs inline with the existing generated stubs by adding @@protoc_insertion_points to the stock c++ generator. A protoc plugin would be used to populate the insertion points. This option has the benefit of presenting a homogenous programming model for this, and all future plugin-based stub extensions, but requires a coordinated one time change with the protoc project.
  3. Extend the c++ generator with optional support for CompletableFuture. Use a protoc flag to turn it on and off. Not a great option, but possible.

rmichela avatar Mar 07 '17 00:03 rmichela

Guava might have to face this sooner than we do, so they may make their futures Completable anyways, and you could just cast. gRPC could just ride this out.

carl-mastrangelo avatar Mar 07 '17 00:03 carl-mastrangelo

I get the impression from #2688 that Guava upgrades are problematic. Would Guava vNext introduce the same compatibility break that Guava 20 introduced?

rmichela avatar Mar 07 '17 00:03 rmichela

I just saw that Guava recommends future-converter.

ejona86 avatar Jun 28 '19 16:06 ejona86

FYI a comment in #6986 suggests that this will not happen anytime soon.

keithl-stripe avatar Aug 23 '21 19:08 keithl-stripe

#4671 tracks dropping Java 7 support and in #8100 warnings were issued when running on Java 7. Dropping Java 7 may happen this year.

But dropping Java 7 just lets us use Java 8 language features, because older Android versions don't have the Java 8 libraries. For this specific issue, we could maybe add CompletableFuture to full-proto codegen and not lite-proto codegen. Or we rely on users not to call the methods they can't use. But that'd have to be worked out.

ejona86 avatar Aug 24 '21 17:08 ejona86

@ejona86 Can you help me understand the current state of CompletableFuture support in GRPC now that Java 7 looks to have been removed (congrats, btw, that's a big deal!)?

silospen avatar Aug 02 '22 22:08 silospen

@silospen, Java 7 is dropped, but Android API level 19 is still supported. So what we mainly got was access to language features. We don't yet require Android users to enable library desugaring, which would be required to use CompletableFuture until we require API level 24+.

Note that the problem isn't as much the generated code as javalite codegen is separate from full protobuf. But the codegen uses grpc-stub for support, and that is still used on Android.

ejona86 avatar Aug 10 '22 17:08 ejona86