Skip to content

Instantly share code, notes, and snippets.

@mgodave
Created November 13, 2024 18:35
Show Gist options
  • Save mgodave/98be3da5cd3062a1d597332f81567a88 to your computer and use it in GitHub Desktop.
Save mgodave/98be3da5cd3062a1d597332f81567a88 to your computer and use it in GitHub Desktop.
4d3
< import io.servicetalk.concurrent.api.AsyncCloseable;
12d10
< import io.servicetalk.encoding.api.Identity;
24d21
< import io.servicetalk.grpc.api.GrpcSerializationProvider;
30d26
< import io.servicetalk.grpc.protobuf.ProtoBufSerializationProviderBuilder;
32d27
< import java.lang.Deprecated;
36,37d30
< import java.lang.String;
< import java.time.Duration;
47c40
< public final class Greeter {
---
> public final class GreeterSt {
56c49
< private Greeter() {
---
> private GreeterSt() {
60,73d52
< 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)));
< }
<
76,81d54
< /**
< * @deprecated Use {@link #methodDescriptor}.
< */
< @Deprecated
< String PATH = "/helloworld.Greeter/SayHello";
<
100,105d72
< /**
< * @deprecated Use {@link #methodDescriptor}.
< */
< @Deprecated
< String PATH = "/helloworld.Greeter/SayHello";
<
177,258d143
< /**
< * 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,310d148
< 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;
< }
<
332,338d169
< @Override
< @Deprecated
< protected GreeterServiceFromRoutes newServiceFromRoutes(
< final GrpcRoutes.AllGrpcRoutes routes) {
< return new GreeterServiceFromRoutes(routes);
< }
<
342,346c173
< 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,358c181
< 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,369c188
< 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,382c197
< 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,403d206
< /**
< * 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);
< }
<
409,442d211
<
< @Override
< @Deprecated
< protected void registerRoutes(final GreeterService service) {
< sayHello(service);
< }
<
< @Deprecated
< private static final class GreeterServiceFromRoutes implements GreeterService {
< private final AsyncCloseable closeable;
<
< private final GrpcRoutes.Route<HelloRequest, HelloReply> sayHello;
<
< private GreeterServiceFromRoutes(final GrpcRoutes.AllGrpcRoutes routes) {
< closeable = routes;
< sayHello = routes.routeFor(SayHelloRpc.methodDescriptor().httpPath());
< }
<
< @Override
< public Single<HelloReply> sayHello(final GrpcServiceContext ctx,
< final HelloRequest request) {
< return sayHello.handle(ctx, request);
< }
<
< @Override
< public Completable closeAsync() {
< return closeable.closeAsync();
< }
<
< @Override
< public Completable closeAsyncGracefully() {
< return closeable.closeAsyncGracefully();
< }
< }
446,487d214
< /**
< * @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);
< }
<
< 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);
< }
< }
<
509c236
< return sayHello(new SayHelloMetadata(metadata), 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."));
512,526d238
< /**
< * <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 Consider migrating to an alternative method or implement this method if it's required temporarily."));
< }
<
545,562d256
<
< /**
< * <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.");
< }
577c271
< return sayHello(new SayHelloMetadata(metadata), request);
---
> 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.");
613,619d306
<
< @Deprecated
< @Override
< public HelloReply sayHello(final SayHelloMetadata metadata, final HelloRequest request)
< throws Exception {
< return client.sayHello(metadata, request).toFuture().get();
< }
648,652c335
< if (supportedMessageCodings.isEmpty()) {
< sayHelloCall = factory.newCall(SayHelloRpc.methodDescriptor(), bufferDecoderGroup);
< } else {
< sayHelloCall = factory.newCall(initSerializationProvider(supportedMessageCodings), HelloRequest.class, HelloReply.class);
< }
---
> sayHelloCall = factory.newCall(SayHelloRpc.methodDescriptor(), bufferDecoderGroup);
703d385
< @Deprecated
705,712d386
< public Single<HelloReply> sayHello(final SayHelloMetadata metadata,
< final HelloRequest request) {
< Objects.requireNonNull(metadata);
< Objects.requireNonNull(request);
< return sayHelloCall.request(metadata, request);
< }
<
< @Override
714c388
< return sayHello(supportedMessageCodings.isEmpty() ? new DefaultGrpcClientMetadata() : new SayHelloMetadata(), request);
---
> return sayHello(new DefaultGrpcClientMetadata(), request);
733,737c407
< if (supportedMessageCodings.isEmpty()) {
< sayHelloCall = factory.newBlockingCall(BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup);
< } else {
< sayHelloCall = factory.newBlockingCall(initSerializationProvider(supportedMessageCodings), HelloRequest.class, HelloReply.class);
< }
---
> sayHelloCall = factory.newBlockingCall(BlockingSayHelloRpc.methodDescriptor(), bufferDecoderGroup);
768d437
< @Deprecated
770,777d438
< public HelloReply sayHello(final SayHelloMetadata metadata, final HelloRequest request)
< throws Exception {
< Objects.requireNonNull(metadata);
< Objects.requireNonNull(request);
< return sayHelloCall.request(metadata, request);
< }
<
< @Override
779c440
< return sayHello(supportedMessageCodings.isEmpty() ? new DefaultGrpcClientMetadata() : new SayHelloMetadata(), request);
---
> return sayHello(new DefaultGrpcClientMetadata(), request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment