Created
November 7, 2024 15:03
-
-
Save mgodave/9926d62e4bf9c2d3192d2dbf2299528b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12d11 | |
< import io.servicetalk.encoding.api.Identity; | |
15d13 | |
< import io.servicetalk.grpc.api.DefaultGrpcClientMetadata; | |
20d17 | |
< import io.servicetalk.grpc.api.GrpcClientMetadata; | |
24d20 | |
< import io.servicetalk.grpc.api.GrpcSerializationProvider; | |
30d25 | |
< import io.servicetalk.grpc.protobuf.ProtoBufSerializationProviderBuilder; | |
37d31 | |
< import java.time.Duration; | |
60,73d53 | |
< private static GrpcSerializationProvider initSerializationProvider( | |
< final List<ContentCodec> supportedMessageCodings) { | |
< ProtoBufSerializationProviderBuilder builder = new ProtoBufSerializationProviderBuilder(); | |
< builder.supportedMessageCodings(supportedMessageCodings); | |
< builder.registerMessageType(HelloRequest.class, HelloRequest.parser()); | |
< builder.registerMessageType(HelloReply.class, HelloReply.parser()); | |
< return builder.build(); | |
< } | |
< | |
< private static boolean isSupportedMessageCodingsEmpty( | |
< final List<ContentCodec> supportedMessageCodings) { | |
< return supportedMessageCodings.isEmpty() || (supportedMessageCodings.size() == 1 && Identity.identity().equals(supportedMessageCodings.get(0))); | |
< } | |
< | |
177,258d156 | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param service a service to handle incoming requests | |
< * @param supportedMessageCodings the set of allowed encodings | |
< * @deprecated Use {@link Builder#Builder()}, {@link Builder#bufferDecoderGroup(BufferDecoderGroup)}, and {@link Builder#bufferEncoders(List)}. | |
< */ | |
< @Deprecated | |
< public ServiceFactory(final GreeterService service, | |
< final List<ContentCodec> supportedMessageCodings) { | |
< this(new Builder(supportedMessageCodings).sayHello(service)); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param service a service to handle incoming requests | |
< * @param strategyFactory a factory that creates an execution strategy for different {@link io.servicetalk.router.api.RouteExecutionStrategy#id() id}s | |
< * @deprecated Use {@link Builder#Builder()} and set the custom strategy on {@link Builder#routeExecutionStrategyFactory(RouteExecutionStrategyFactory)} instead. | |
< */ | |
< @Deprecated | |
< public ServiceFactory(final GreeterService service, | |
< final RouteExecutionStrategyFactory<GrpcExecutionStrategy> strategyFactory) { | |
< this(new Builder(strategyFactory).sayHello(service)); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param service a service to handle incoming requests | |
< * @param strategyFactory a factory that creates an execution strategy for different {@link io.servicetalk.router.api.RouteExecutionStrategy#id() id}s | |
< * @param supportedMessageCodings the set of allowed encodings | |
< * @deprecated Use {@link Builder#Builder(RouteExecutionStrategyFactory)}, {@link Builder#bufferDecoderGroup(BufferDecoderGroup)}, and {@link Builder#bufferEncoders(List)}. | |
< */ | |
< @Deprecated | |
< public ServiceFactory(final GreeterService service, | |
< final RouteExecutionStrategyFactory<GrpcExecutionStrategy> strategyFactory, | |
< final List<ContentCodec> supportedMessageCodings) { | |
< this(new Builder(strategyFactory, supportedMessageCodings).sayHello(service)); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param service a service to handle incoming requests | |
< * @param supportedMessageCodings the set of allowed encodings | |
< * @deprecated Use {@link Builder#Builder()}, {@link Builder#bufferDecoderGroup(BufferDecoderGroup)}, and {@link Builder#bufferEncoders(List)}. | |
< */ | |
< @Deprecated | |
< public ServiceFactory(final BlockingGreeterService service, | |
< final List<ContentCodec> supportedMessageCodings) { | |
< this(new Builder(supportedMessageCodings).sayHelloBlocking(service)); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param service a service to handle incoming requests | |
< * @param strategyFactory a factory that creates an execution strategy for different {@link io.servicetalk.router.api.RouteExecutionStrategy#id() id}s | |
< * @deprecated Use {@link Builder#Builder()} and set the custom strategy on {@link Builder#routeExecutionStrategyFactory(RouteExecutionStrategyFactory)} instead. | |
< */ | |
< @Deprecated | |
< public ServiceFactory(final BlockingGreeterService service, | |
< final RouteExecutionStrategyFactory<GrpcExecutionStrategy> strategyFactory) { | |
< this(new Builder(strategyFactory).sayHelloBlocking(service)); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param service a service to handle incoming requests | |
< * @param strategyFactory a factory that creates an execution strategy for different {@link io.servicetalk.router.api.RouteExecutionStrategy#id() id}s | |
< * @param supportedMessageCodings the set of allowed encodings | |
< * @deprecated Use {@link Builder#Builder(RouteExecutionStrategyFactory)}, {@link Builder#bufferDecoderGroup(BufferDecoderGroup)}, and {@link Builder#bufferEncoders(List)}. | |
< */ | |
< @Deprecated | |
< public ServiceFactory(final BlockingGreeterService service, | |
< final RouteExecutionStrategyFactory<GrpcExecutionStrategy> strategyFactory, | |
< final List<ContentCodec> supportedMessageCodings) { | |
< this(new Builder(strategyFactory, supportedMessageCodings).sayHelloBlocking(service)); | |
< } | |
< | |
264,310d161 | |
< private final List<ContentCodec> supportedMessageCodings; | |
< | |
< /** | |
< * Create a new instance. | |
< */ | |
< public Builder() { | |
< this(Collections.emptyList()); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param supportedMessageCodings the set of allowed encodings | |
< * @deprecated Use {@link #bufferDecoderGroup(BufferDecoderGroup)} and {@link #bufferEncoders(List)}. | |
< */ | |
< @Deprecated | |
< public Builder(final List<ContentCodec> supportedMessageCodings) { | |
< this.supportedMessageCodings = supportedMessageCodings; | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param strategyFactory a factory that creates an execution strategy for different {@link io.servicetalk.router.api.RouteExecutionStrategy#id() id}s | |
< * @deprecated use {@link #routeExecutionStrategyFactory(RouteExecutionStrategyFactory)} on the Builder instead. | |
< */ | |
< @Deprecated | |
< public Builder( | |
< final RouteExecutionStrategyFactory<GrpcExecutionStrategy> strategyFactory) { | |
< this(strategyFactory, Collections.emptyList()); | |
< } | |
< | |
< /** | |
< * Create a new instance. | |
< * | |
< * @param strategyFactory a factory that creates an execution strategy for different {@link io.servicetalk.router.api.RouteExecutionStrategy#id() id}s | |
< * @param supportedMessageCodings the set of allowed encodings | |
< * @deprecated Use {@link #Builder(RouteExecutionStrategyFactory)}, {@link #bufferDecoderGroup(BufferDecoderGroup)}, and {@link #bufferEncoders(List)}. | |
< */ | |
< @Deprecated | |
< public Builder( | |
< final RouteExecutionStrategyFactory<GrpcExecutionStrategy> strategyFactory, | |
< final List<ContentCodec> supportedMessageCodings) { | |
< super(strategyFactory); | |
< this.supportedMessageCodings = supportedMessageCodings; | |
< } | |
< | |
342,346c193 | |
< if (supportedMessageCodings.isEmpty()) { | |
< addRoute(rpc.getClass(), SayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
< } else { | |
< addRoute(SayHelloRpc.PATH, rpc.getClass(), SayHelloRpc.methodDescriptor().javaMethodName(), route, HelloRequest.class, HelloReply.class, initSerializationProvider(supportedMessageCodings)); | |
< } | |
--- | |
> addRoute(rpc.getClass(), SayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
354,358c201 | |
< if (supportedMessageCodings.isEmpty()) { | |
< addRoute(strategy, SayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
< } else { | |
< addRoute(SayHelloRpc.PATH, strategy, route, HelloRequest.class, HelloReply.class, initSerializationProvider(supportedMessageCodings)); | |
< } | |
--- | |
> addRoute(strategy, SayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
365,369c208 | |
< if (supportedMessageCodings.isEmpty()) { | |
< addBlockingRoute(rpc.getClass(), BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
< } else { | |
< addBlockingRoute(BlockingSayHelloRpc.PATH, rpc.getClass(), BlockingSayHelloRpc.methodDescriptor().javaMethodName(), route, HelloRequest.class, HelloReply.class, initSerializationProvider(supportedMessageCodings)); | |
< } | |
--- | |
> addBlockingRoute(rpc.getClass(), BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
378,382c217 | |
< if (supportedMessageCodings.isEmpty()) { | |
< addBlockingRoute(strategy, BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
< } else { | |
< addBlockingRoute(BlockingSayHelloRpc.PATH, strategy, route, HelloRequest.class, HelloReply.class, initSerializationProvider(supportedMessageCodings)); | |
< } | |
--- | |
> addBlockingRoute(strategy, BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup, bufferEncoders, route); | |
392,403d226 | |
< /** | |
< * Adds a {@link BlockingGreeterService} implementation. | |
< * | |
< * @param service the {@link BlockingGreeterService} implementation to add. | |
< * @return this. | |
< * @deprecated Use {@link #addBlockingService(io.grpc.examples.helloworld.Greeter.BlockingGreeterService)}. | |
< */ | |
< @Deprecated | |
< public Builder addService(final BlockingGreeterService service) { | |
< return addBlockingService(service); | |
< } | |
< | |
443,458d265 | |
< } | |
< } | |
< | |
< /** | |
< * @deprecated This class will be removed in the future in favor of direct usage of {@link GrpcClientMetadata}. Deprecation of {@link GrpcClientMetadata#path()} renders this type unnecessary. | |
< */ | |
< @Deprecated | |
< public static final class SayHelloMetadata extends DefaultGrpcClientMetadata { | |
< /** | |
< * @deprecated Use {@link DefaultGrpcClientMetadata}. | |
< */ | |
< @Deprecated | |
< public static final SayHelloMetadata INSTANCE = new SayHelloMetadata(); | |
< | |
< private SayHelloMetadata(final GrpcClientMetadata metadata) { | |
< super(SayHelloRpc.PATH, metadata); | |
460,485d266 | |
< | |
< private SayHelloMetadata() { | |
< super(SayHelloRpc.PATH); | |
< } | |
< | |
< public SayHelloMetadata(final GrpcExecutionStrategy strategy) { | |
< super(SayHelloRpc.PATH, strategy); | |
< } | |
< | |
< public SayHelloMetadata(final Duration timeout) { | |
< super(SayHelloRpc.PATH, timeout); | |
< } | |
< | |
< public SayHelloMetadata(final ContentCodec requestEncoding) { | |
< super(SayHelloRpc.PATH, requestEncoding); | |
< } | |
< | |
< public SayHelloMetadata(final GrpcExecutionStrategy strategy, | |
< final ContentCodec requestEncoding) { | |
< super(SayHelloRpc.PATH, strategy, requestEncoding); | |
< } | |
< | |
< public SayHelloMetadata(final GrpcExecutionStrategy strategy, | |
< final ContentCodec requestEncoding, final Duration timeout) { | |
< super(SayHelloRpc.PATH, strategy, requestEncoding, timeout); | |
< } | |
489,526d269 | |
< /** | |
< * <pre> | |
< * Sends a greeting | |
< * </pre> | |
< * | |
< * @param request the request to send to the server. | |
< * @return a {@link Single} which completes when the response is received from the server. | |
< */ | |
< Single<HelloReply> sayHello(HelloRequest request); | |
< | |
< /** | |
< * <pre> | |
< * Sends a greeting | |
< * </pre> | |
< * | |
< * @deprecated Use {@link #sayHello(GrpcClientMetadata,HelloRequest)}. | |
< * @param metadata the metadata associated with this client call. | |
< * @param request the request to send to the server. | |
< * @return a {@link Single} which completes when the response is received from the server. | |
< */ | |
< @Deprecated | |
< default Single<HelloReply> sayHello(SayHelloMetadata metadata, HelloRequest request) { | |
< return Single.failed(new UnsupportedOperationException("This method is not implemented by " + getClass() + ". Consider migrating to an alternative method or implement this method if it's required temporarily.")); | |
< } | |
< | |
< /** | |
< * <pre> | |
< * Sends a greeting | |
< * </pre> | |
< * | |
< * @param metadata the metadata associated with this client call. | |
< * @param request the request to send to the server. | |
< * @return a {@link Single} which completes when the response is received from the server. | |
< */ | |
< default Single<HelloReply> sayHello(GrpcClientMetadata metadata, HelloRequest request) { | |
< return sayHello(new SayHelloMetadata(metadata), request); | |
< } | |
< | |
534,578d276 | |
< /** | |
< * <pre> | |
< * Sends a greeting | |
< * </pre> | |
< * | |
< * @param request the request from the client. | |
< * @return the response from the server. | |
< * @throws Exception if an unexpected application error occurs. | |
< * @throws io.servicetalk.grpc.api.GrpcStatusException if an expected application exception occurs. Its contents will be serialized and propagated to the peer. | |
< */ | |
< HelloReply sayHello(HelloRequest request) throws Exception; | |
< | |
< /** | |
< * <pre> | |
< * Sends a greeting | |
< * </pre> | |
< * | |
< * @deprecated Use {@link #sayHello(GrpcClientMetadata,HelloRequest)}. | |
< * @param metadata the metadata associated with this client call. | |
< * @param request the request from the client. | |
< * @return the response from the server. | |
< * @throws Exception if an unexpected application error occurs. | |
< * @throws io.servicetalk.grpc.api.GrpcStatusException if an expected application exception occurs. Its contents will be serialized and propagated to the peer. | |
< */ | |
< @Deprecated | |
< default HelloReply sayHello(SayHelloMetadata metadata, HelloRequest request) throws | |
< Exception { | |
< throw new UnsupportedOperationException("This method is not implemented by " + getClass() + ". Consider migrating to an alternative method or implement this method if it's required temporarily."); | |
< } | |
< | |
< /** | |
< * <pre> | |
< * Sends a greeting | |
< * </pre> | |
< * | |
< * @param metadata the metadata associated with this client call. | |
< * @param request the request from the client. | |
< * @return the response from the server. | |
< * @throws Exception if an unexpected application error occurs. | |
< * @throws io.servicetalk.grpc.api.GrpcStatusException if an expected application exception occurs. Its contents will be serialized and propagated to the peer. | |
< */ | |
< default HelloReply sayHello(GrpcClientMetadata metadata, HelloRequest request) throws | |
< Exception { | |
< return sayHello(new SayHelloMetadata(metadata), request); | |
< } | |
602,619d299 | |
< | |
< @Override | |
< public HelloReply sayHello(final HelloRequest request) throws Exception { | |
< return client.sayHello(request).toFuture().get(); | |
< } | |
< | |
< @Deprecated | |
< @Override | |
< public HelloReply sayHello(final SayHelloMetadata metadata, final HelloRequest request) | |
< throws Exception { | |
< return client.sayHello(metadata, request).toFuture().get(); | |
< } | |
< | |
< @Override | |
< public HelloReply sayHello(final GrpcClientMetadata metadata, final HelloRequest request) | |
< throws Exception { | |
< return client.sayHello(metadata, request).toFuture().get(); | |
< } | |
640,641d319 | |
< private final GrpcClientCallFactory.ClientCall<HelloRequest, HelloReply> sayHelloCall; | |
< | |
648,652d325 | |
< if (supportedMessageCodings.isEmpty()) { | |
< sayHelloCall = factory.newCall(SayHelloRpc.methodDescriptor(), bufferDecoderGroup); | |
< } else { | |
< sayHelloCall = factory.newCall(initSerializationProvider(supportedMessageCodings), HelloRequest.class, HelloReply.class); | |
< } | |
694,715d366 | |
< | |
< @Override | |
< public Single<HelloReply> sayHello(final HelloRequest request) { | |
< return sayHello(supportedMessageCodings.isEmpty() ? new DefaultGrpcClientMetadata() : new SayHelloMetadata(), request); | |
< } | |
< | |
< @Deprecated | |
< @Override | |
< public Single<HelloReply> sayHello(final SayHelloMetadata metadata, | |
< final HelloRequest request) { | |
< Objects.requireNonNull(metadata); | |
< Objects.requireNonNull(request); | |
< return sayHelloCall.request(metadata, request); | |
< } | |
< | |
< @Override | |
< public Single<HelloReply> sayHello(final GrpcClientMetadata metadata, | |
< final HelloRequest request) { | |
< Objects.requireNonNull(metadata); | |
< Objects.requireNonNull(request); | |
< return sayHelloCall.request(metadata, request); | |
< } | |
725,726d375 | |
< private final GrpcClientCallFactory.BlockingClientCall<HelloRequest, HelloReply> sayHelloCall; | |
< | |
733,737d381 | |
< if (supportedMessageCodings.isEmpty()) { | |
< sayHelloCall = factory.newBlockingCall(BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup); | |
< } else { | |
< sayHelloCall = factory.newBlockingCall(initSerializationProvider(supportedMessageCodings), HelloRequest.class, HelloReply.class); | |
< } | |
759,780d402 | |
< | |
< @Override | |
< public HelloReply sayHello(final HelloRequest request) throws Exception { | |
< return sayHello(supportedMessageCodings.isEmpty() ? new DefaultGrpcClientMetadata() : new SayHelloMetadata(), request); | |
< } | |
< | |
< @Deprecated | |
< @Override | |
< public HelloReply sayHello(final SayHelloMetadata metadata, final HelloRequest request) | |
< throws Exception { | |
< Objects.requireNonNull(metadata); | |
< Objects.requireNonNull(request); | |
< return sayHelloCall.request(metadata, request); | |
< } | |
< | |
< @Override | |
< public HelloReply sayHello(final GrpcClientMetadata metadata, | |
< final HelloRequest request) throws Exception { | |
< Objects.requireNonNull(metadata); | |
< Objects.requireNonNull(request); | |
< return sayHelloCall.request(metadata, request); | |
< } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment