Skip to content

Commit 19eab29

Browse files
authored
compiler: Generate interfaces for services to implement (#9688)
Introduce an AsyncService interface in the generated code and move the methods from <service>ImplBase to default implementation of the interface. * update pom files to allow java 1.8 * Add a bindService(<service>Async) method * Change TestServiceImpl to use the interface and include a bind method instead of extending TestServiceImplBase.
1 parent 67d6600 commit 19eab29

File tree

60 files changed

+2672
-1593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2672
-1593
lines changed

alts/src/generated/main/grpc/io/grpc/alts/internal/HandshakerServiceGrpc.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public HandshakerServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.Call
9292

9393
/**
9494
*/
95-
public static abstract class HandshakerServiceImplBase implements io.grpc.BindableService {
95+
public interface AsyncService {
9696

9797
/**
9898
* <pre>
@@ -104,27 +104,28 @@ public static abstract class HandshakerServiceImplBase implements io.grpc.Bindab
104104
* response before sending next request.
105105
* </pre>
106106
*/
107-
public io.grpc.stub.StreamObserver<io.grpc.alts.internal.HandshakerReq> doHandshake(
107+
default io.grpc.stub.StreamObserver<io.grpc.alts.internal.HandshakerReq> doHandshake(
108108
io.grpc.stub.StreamObserver<io.grpc.alts.internal.HandshakerResp> responseObserver) {
109109
return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(getDoHandshakeMethod(), responseObserver);
110110
}
111+
}
112+
113+
/**
114+
* Base class for the server implementation of the service HandshakerService.
115+
*/
116+
public static abstract class HandshakerServiceImplBase
117+
implements io.grpc.BindableService, AsyncService {
111118

112119
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
113-
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
114-
.addMethod(
115-
getDoHandshakeMethod(),
116-
io.grpc.stub.ServerCalls.asyncBidiStreamingCall(
117-
new MethodHandlers<
118-
io.grpc.alts.internal.HandshakerReq,
119-
io.grpc.alts.internal.HandshakerResp>(
120-
this, METHODID_DO_HANDSHAKE)))
121-
.build();
120+
return HandshakerServiceGrpc.bindService(this);
122121
}
123122
}
124123

125124
/**
125+
* A stub to allow clients to do asynchronous rpc calls to service HandshakerService.
126126
*/
127-
public static final class HandshakerServiceStub extends io.grpc.stub.AbstractAsyncStub<HandshakerServiceStub> {
127+
public static final class HandshakerServiceStub
128+
extends io.grpc.stub.AbstractAsyncStub<HandshakerServiceStub> {
128129
private HandshakerServiceStub(
129130
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
130131
super(channel, callOptions);
@@ -154,8 +155,10 @@ public io.grpc.stub.StreamObserver<io.grpc.alts.internal.HandshakerReq> doHandsh
154155
}
155156

156157
/**
158+
* A stub to allow clients to do synchronous rpc calls to service HandshakerService.
157159
*/
158-
public static final class HandshakerServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub<HandshakerServiceBlockingStub> {
160+
public static final class HandshakerServiceBlockingStub
161+
extends io.grpc.stub.AbstractBlockingStub<HandshakerServiceBlockingStub> {
159162
private HandshakerServiceBlockingStub(
160163
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
161164
super(channel, callOptions);
@@ -169,8 +172,10 @@ protected HandshakerServiceBlockingStub build(
169172
}
170173

171174
/**
175+
* A stub to allow clients to do ListenableFuture-style rpc calls to service HandshakerService.
172176
*/
173-
public static final class HandshakerServiceFutureStub extends io.grpc.stub.AbstractFutureStub<HandshakerServiceFutureStub> {
177+
public static final class HandshakerServiceFutureStub
178+
extends io.grpc.stub.AbstractFutureStub<HandshakerServiceFutureStub> {
174179
private HandshakerServiceFutureStub(
175180
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
176181
super(channel, callOptions);
@@ -190,10 +195,10 @@ private static final class MethodHandlers<Req, Resp> implements
190195
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
191196
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
192197
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
193-
private final HandshakerServiceImplBase serviceImpl;
198+
private final AsyncService serviceImpl;
194199
private final int methodId;
195200

196-
MethodHandlers(HandshakerServiceImplBase serviceImpl, int methodId) {
201+
MethodHandlers(AsyncService serviceImpl, int methodId) {
197202
this.serviceImpl = serviceImpl;
198203
this.methodId = methodId;
199204
}
@@ -221,6 +226,18 @@ public io.grpc.stub.StreamObserver<Req> invoke(
221226
}
222227
}
223228

229+
public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) {
230+
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
231+
.addMethod(
232+
getDoHandshakeMethod(),
233+
io.grpc.stub.ServerCalls.asyncBidiStreamingCall(
234+
new MethodHandlers<
235+
io.grpc.alts.internal.HandshakerReq,
236+
io.grpc.alts.internal.HandshakerResp>(
237+
service, METHODID_DO_HANDSHAKE)))
238+
.build();
239+
}
240+
224241
private static abstract class HandshakerServiceBaseDescriptorSupplier
225242
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
226243
HandshakerServiceBaseDescriptorSupplier() {}

alts/src/test/java/io/grpc/alts/HandshakerServiceChannelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> so) {
4646
so.onCompleted();
4747
}
4848
})
49-
.build());
49+
.build());
5050
private Resource<Channel> resource;
5151

5252
@Before

android-interop-testing/src/generated/debug/grpc/io/grpc/testing/integration/LoadBalancerStatsServiceGrpc.java

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ public LoadBalancerStatsServiceFutureStub newStub(io.grpc.Channel channel, io.gr
127127
* A service used to obtain stats for verifying LB behavior.
128128
* </pre>
129129
*/
130-
public static abstract class LoadBalancerStatsServiceImplBase implements io.grpc.BindableService {
130+
public interface AsyncService {
131131

132132
/**
133133
* <pre>
134134
* Gets the backend distribution for RPCs sent by a test client.
135135
* </pre>
136136
*/
137-
public void getClientStats(io.grpc.testing.integration.Messages.LoadBalancerStatsRequest request,
137+
default void getClientStats(io.grpc.testing.integration.Messages.LoadBalancerStatsRequest request,
138138
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.LoadBalancerStatsResponse> responseObserver) {
139139
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetClientStatsMethod(), responseObserver);
140140
}
@@ -144,37 +144,34 @@ public void getClientStats(io.grpc.testing.integration.Messages.LoadBalancerStat
144144
* Gets the accumulated stats for RPCs sent by a test client.
145145
* </pre>
146146
*/
147-
public void getClientAccumulatedStats(io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsRequest request,
147+
default void getClientAccumulatedStats(io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsRequest request,
148148
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsResponse> responseObserver) {
149149
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetClientAccumulatedStatsMethod(), responseObserver);
150150
}
151+
}
152+
153+
/**
154+
* Base class for the server implementation of the service LoadBalancerStatsService.
155+
* <pre>
156+
* A service used to obtain stats for verifying LB behavior.
157+
* </pre>
158+
*/
159+
public static abstract class LoadBalancerStatsServiceImplBase
160+
implements io.grpc.BindableService, AsyncService {
151161

152162
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
153-
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
154-
.addMethod(
155-
getGetClientStatsMethod(),
156-
io.grpc.stub.ServerCalls.asyncUnaryCall(
157-
new MethodHandlers<
158-
io.grpc.testing.integration.Messages.LoadBalancerStatsRequest,
159-
io.grpc.testing.integration.Messages.LoadBalancerStatsResponse>(
160-
this, METHODID_GET_CLIENT_STATS)))
161-
.addMethod(
162-
getGetClientAccumulatedStatsMethod(),
163-
io.grpc.stub.ServerCalls.asyncUnaryCall(
164-
new MethodHandlers<
165-
io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsRequest,
166-
io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsResponse>(
167-
this, METHODID_GET_CLIENT_ACCUMULATED_STATS)))
168-
.build();
163+
return LoadBalancerStatsServiceGrpc.bindService(this);
169164
}
170165
}
171166

172167
/**
168+
* A stub to allow clients to do asynchronous rpc calls to service LoadBalancerStatsService.
173169
* <pre>
174170
* A service used to obtain stats for verifying LB behavior.
175171
* </pre>
176172
*/
177-
public static final class LoadBalancerStatsServiceStub extends io.grpc.stub.AbstractAsyncStub<LoadBalancerStatsServiceStub> {
173+
public static final class LoadBalancerStatsServiceStub
174+
extends io.grpc.stub.AbstractAsyncStub<LoadBalancerStatsServiceStub> {
178175
private LoadBalancerStatsServiceStub(
179176
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
180177
super(channel, callOptions);
@@ -210,11 +207,13 @@ public void getClientAccumulatedStats(io.grpc.testing.integration.Messages.LoadB
210207
}
211208

212209
/**
210+
* A stub to allow clients to do synchronous rpc calls to service LoadBalancerStatsService.
213211
* <pre>
214212
* A service used to obtain stats for verifying LB behavior.
215213
* </pre>
216214
*/
217-
public static final class LoadBalancerStatsServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub<LoadBalancerStatsServiceBlockingStub> {
215+
public static final class LoadBalancerStatsServiceBlockingStub
216+
extends io.grpc.stub.AbstractBlockingStub<LoadBalancerStatsServiceBlockingStub> {
218217
private LoadBalancerStatsServiceBlockingStub(
219218
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
220219
super(channel, callOptions);
@@ -248,11 +247,13 @@ public io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsResponse
248247
}
249248

250249
/**
250+
* A stub to allow clients to do ListenableFuture-style rpc calls to service LoadBalancerStatsService.
251251
* <pre>
252252
* A service used to obtain stats for verifying LB behavior.
253253
* </pre>
254254
*/
255-
public static final class LoadBalancerStatsServiceFutureStub extends io.grpc.stub.AbstractFutureStub<LoadBalancerStatsServiceFutureStub> {
255+
public static final class LoadBalancerStatsServiceFutureStub
256+
extends io.grpc.stub.AbstractFutureStub<LoadBalancerStatsServiceFutureStub> {
256257
private LoadBalancerStatsServiceFutureStub(
257258
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
258259
super(channel, callOptions);
@@ -295,10 +296,10 @@ private static final class MethodHandlers<Req, Resp> implements
295296
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
296297
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
297298
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
298-
private final LoadBalancerStatsServiceImplBase serviceImpl;
299+
private final AsyncService serviceImpl;
299300
private final int methodId;
300301

301-
MethodHandlers(LoadBalancerStatsServiceImplBase serviceImpl, int methodId) {
302+
MethodHandlers(AsyncService serviceImpl, int methodId) {
302303
this.serviceImpl = serviceImpl;
303304
this.methodId = methodId;
304305
}
@@ -331,6 +332,25 @@ public io.grpc.stub.StreamObserver<Req> invoke(
331332
}
332333
}
333334

335+
public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) {
336+
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
337+
.addMethod(
338+
getGetClientStatsMethod(),
339+
io.grpc.stub.ServerCalls.asyncUnaryCall(
340+
new MethodHandlers<
341+
io.grpc.testing.integration.Messages.LoadBalancerStatsRequest,
342+
io.grpc.testing.integration.Messages.LoadBalancerStatsResponse>(
343+
service, METHODID_GET_CLIENT_STATS)))
344+
.addMethod(
345+
getGetClientAccumulatedStatsMethod(),
346+
io.grpc.stub.ServerCalls.asyncUnaryCall(
347+
new MethodHandlers<
348+
io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsRequest,
349+
io.grpc.testing.integration.Messages.LoadBalancerAccumulatedStatsResponse>(
350+
service, METHODID_GET_CLIENT_ACCUMULATED_STATS)))
351+
.build();
352+
}
353+
334354
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
335355

336356
public static io.grpc.ServiceDescriptor getServiceDescriptor() {

android-interop-testing/src/generated/debug/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ public MetricsServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOpt
121121

122122
/**
123123
*/
124-
public static abstract class MetricsServiceImplBase implements io.grpc.BindableService {
124+
public interface AsyncService {
125125

126126
/**
127127
* <pre>
128128
* Returns the values of all the gauges that are currently being maintained by
129129
* the service
130130
* </pre>
131131
*/
132-
public void getAllGauges(io.grpc.testing.integration.Metrics.EmptyMessage request,
132+
default void getAllGauges(io.grpc.testing.integration.Metrics.EmptyMessage request,
133133
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Metrics.GaugeResponse> responseObserver) {
134134
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetAllGaugesMethod(), responseObserver);
135135
}
@@ -139,34 +139,28 @@ public void getAllGauges(io.grpc.testing.integration.Metrics.EmptyMessage reques
139139
* Returns the value of one gauge
140140
* </pre>
141141
*/
142-
public void getGauge(io.grpc.testing.integration.Metrics.GaugeRequest request,
142+
default void getGauge(io.grpc.testing.integration.Metrics.GaugeRequest request,
143143
io.grpc.stub.StreamObserver<io.grpc.testing.integration.Metrics.GaugeResponse> responseObserver) {
144144
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetGaugeMethod(), responseObserver);
145145
}
146+
}
147+
148+
/**
149+
* Base class for the server implementation of the service MetricsService.
150+
*/
151+
public static abstract class MetricsServiceImplBase
152+
implements io.grpc.BindableService, AsyncService {
146153

147154
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
148-
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
149-
.addMethod(
150-
getGetAllGaugesMethod(),
151-
io.grpc.stub.ServerCalls.asyncServerStreamingCall(
152-
new MethodHandlers<
153-
io.grpc.testing.integration.Metrics.EmptyMessage,
154-
io.grpc.testing.integration.Metrics.GaugeResponse>(
155-
this, METHODID_GET_ALL_GAUGES)))
156-
.addMethod(
157-
getGetGaugeMethod(),
158-
io.grpc.stub.ServerCalls.asyncUnaryCall(
159-
new MethodHandlers<
160-
io.grpc.testing.integration.Metrics.GaugeRequest,
161-
io.grpc.testing.integration.Metrics.GaugeResponse>(
162-
this, METHODID_GET_GAUGE)))
163-
.build();
155+
return MetricsServiceGrpc.bindService(this);
164156
}
165157
}
166158

167159
/**
160+
* A stub to allow clients to do asynchronous rpc calls to service MetricsService.
168161
*/
169-
public static final class MetricsServiceStub extends io.grpc.stub.AbstractAsyncStub<MetricsServiceStub> {
162+
public static final class MetricsServiceStub
163+
extends io.grpc.stub.AbstractAsyncStub<MetricsServiceStub> {
170164
private MetricsServiceStub(
171165
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
172166
super(channel, callOptions);
@@ -203,8 +197,10 @@ public void getGauge(io.grpc.testing.integration.Metrics.GaugeRequest request,
203197
}
204198

205199
/**
200+
* A stub to allow clients to do synchronous rpc calls to service MetricsService.
206201
*/
207-
public static final class MetricsServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub<MetricsServiceBlockingStub> {
202+
public static final class MetricsServiceBlockingStub
203+
extends io.grpc.stub.AbstractBlockingStub<MetricsServiceBlockingStub> {
208204
private MetricsServiceBlockingStub(
209205
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
210206
super(channel, callOptions);
@@ -240,8 +236,10 @@ public io.grpc.testing.integration.Metrics.GaugeResponse getGauge(io.grpc.testin
240236
}
241237

242238
/**
239+
* A stub to allow clients to do ListenableFuture-style rpc calls to service MetricsService.
243240
*/
244-
public static final class MetricsServiceFutureStub extends io.grpc.stub.AbstractFutureStub<MetricsServiceFutureStub> {
241+
public static final class MetricsServiceFutureStub
242+
extends io.grpc.stub.AbstractFutureStub<MetricsServiceFutureStub> {
245243
private MetricsServiceFutureStub(
246244
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
247245
super(channel, callOptions);
@@ -273,10 +271,10 @@ private static final class MethodHandlers<Req, Resp> implements
273271
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
274272
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
275273
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
276-
private final MetricsServiceImplBase serviceImpl;
274+
private final AsyncService serviceImpl;
277275
private final int methodId;
278276

279-
MethodHandlers(MetricsServiceImplBase serviceImpl, int methodId) {
277+
MethodHandlers(AsyncService serviceImpl, int methodId) {
280278
this.serviceImpl = serviceImpl;
281279
this.methodId = methodId;
282280
}
@@ -309,6 +307,25 @@ public io.grpc.stub.StreamObserver<Req> invoke(
309307
}
310308
}
311309

310+
public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) {
311+
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
312+
.addMethod(
313+
getGetAllGaugesMethod(),
314+
io.grpc.stub.ServerCalls.asyncServerStreamingCall(
315+
new MethodHandlers<
316+
io.grpc.testing.integration.Metrics.EmptyMessage,
317+
io.grpc.testing.integration.Metrics.GaugeResponse>(
318+
service, METHODID_GET_ALL_GAUGES)))
319+
.addMethod(
320+
getGetGaugeMethod(),
321+
io.grpc.stub.ServerCalls.asyncUnaryCall(
322+
new MethodHandlers<
323+
io.grpc.testing.integration.Metrics.GaugeRequest,
324+
io.grpc.testing.integration.Metrics.GaugeResponse>(
325+
service, METHODID_GET_GAUGE)))
326+
.build();
327+
}
328+
312329
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
313330

314331
public static io.grpc.ServiceDescriptor getServiceDescriptor() {

0 commit comments

Comments
 (0)