Skip to content

Commit d59973c

Browse files
authored
core,services: separately index mutable and immutable services
Updates the proto reflection service to process immutable services once and mutable services as-needed.
1 parent c436d93 commit d59973c

29 files changed

+2778
-248
lines changed

core/src/main/java/io/grpc/Server.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,33 @@ public int getPort() {
6666
}
6767

6868
/**
69-
* Returns the services registered with the server, or an empty list if not supported by the
69+
* Returns all services registered with the server, or an empty list if not supported by the
7070
* implementation.
7171
*/
7272
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222")
7373
public List<ServerServiceDefinition> getServices() {
7474
return Collections.emptyList();
7575
}
7676

77+
/**
78+
* Returns immutable services registered with the server, or an empty list if not supported by the
79+
* implementation.
80+
*/
81+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222")
82+
public List<ServerServiceDefinition> getImmutableServices() {
83+
return Collections.emptyList();
84+
}
85+
86+
87+
/**
88+
* Returns mutable services registered with the server, or an empty list if not supported by the
89+
* implementation.
90+
*/
91+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222")
92+
public List<ServerServiceDefinition> getMutableServices() {
93+
return Collections.emptyList();
94+
}
95+
7796
/**
7897
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected.
7998
*/

core/src/main/java/io/grpc/internal/ServerImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ public List<ServerServiceDefinition> getServices() {
193193
}
194194
}
195195

196+
@Override
197+
public List<ServerServiceDefinition> getImmutableServices() {
198+
return registry.getServices();
199+
}
200+
201+
@Override
202+
public List<ServerServiceDefinition> getMutableServices() {
203+
return Collections.unmodifiableList(fallbackRegistry.getServices());
204+
}
205+
196206
/**
197207
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected.
198208
*/
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
package io.grpc.reflection.testing;
2+
3+
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
4+
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
5+
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
6+
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
7+
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
8+
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
9+
import static io.grpc.stub.ClientCalls.futureUnaryCall;
10+
import static io.grpc.MethodDescriptor.generateFullMethodName;
11+
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
12+
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
13+
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
14+
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
15+
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
16+
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
17+
18+
/**
19+
*/
20+
@javax.annotation.Generated(
21+
value = "by gRPC proto compiler (version 1.1.0-SNAPSHOT)",
22+
comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto")
23+
public class AnotherDynamicServiceGrpc {
24+
25+
private AnotherDynamicServiceGrpc() {}
26+
27+
public static final String SERVICE_NAME = "grpc.reflection.testing.AnotherDynamicService";
28+
29+
// Static method descriptors that strictly reflect the proto.
30+
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
31+
public static final io.grpc.MethodDescriptor<io.grpc.reflection.testing.DynamicRequest,
32+
io.grpc.reflection.testing.DynamicReply> METHOD_METHOD =
33+
io.grpc.MethodDescriptor.create(
34+
io.grpc.MethodDescriptor.MethodType.UNARY,
35+
generateFullMethodName(
36+
"grpc.reflection.testing.AnotherDynamicService", "Method"),
37+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.DynamicRequest.getDefaultInstance()),
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.DynamicReply.getDefaultInstance()));
39+
40+
/**
41+
* Creates a new async stub that supports all call types for the service
42+
*/
43+
public static AnotherDynamicServiceStub newStub(io.grpc.Channel channel) {
44+
return new AnotherDynamicServiceStub(channel);
45+
}
46+
47+
/**
48+
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
49+
*/
50+
public static AnotherDynamicServiceBlockingStub newBlockingStub(
51+
io.grpc.Channel channel) {
52+
return new AnotherDynamicServiceBlockingStub(channel);
53+
}
54+
55+
/**
56+
* Creates a new ListenableFuture-style stub that supports unary and streaming output calls on the service
57+
*/
58+
public static AnotherDynamicServiceFutureStub newFutureStub(
59+
io.grpc.Channel channel) {
60+
return new AnotherDynamicServiceFutureStub(channel);
61+
}
62+
63+
/**
64+
*/
65+
public static abstract class AnotherDynamicServiceImplBase implements io.grpc.BindableService {
66+
67+
/**
68+
*/
69+
public void method(io.grpc.reflection.testing.DynamicRequest request,
70+
io.grpc.stub.StreamObserver<io.grpc.reflection.testing.DynamicReply> responseObserver) {
71+
asyncUnimplementedUnaryCall(METHOD_METHOD, responseObserver);
72+
}
73+
74+
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
75+
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
76+
.addMethod(
77+
METHOD_METHOD,
78+
asyncUnaryCall(
79+
new MethodHandlers<
80+
io.grpc.reflection.testing.DynamicRequest,
81+
io.grpc.reflection.testing.DynamicReply>(
82+
this, METHODID_METHOD)))
83+
.build();
84+
}
85+
}
86+
87+
/**
88+
*/
89+
public static final class AnotherDynamicServiceStub extends io.grpc.stub.AbstractStub<AnotherDynamicServiceStub> {
90+
private AnotherDynamicServiceStub(io.grpc.Channel channel) {
91+
super(channel);
92+
}
93+
94+
private AnotherDynamicServiceStub(io.grpc.Channel channel,
95+
io.grpc.CallOptions callOptions) {
96+
super(channel, callOptions);
97+
}
98+
99+
@java.lang.Override
100+
protected AnotherDynamicServiceStub build(io.grpc.Channel channel,
101+
io.grpc.CallOptions callOptions) {
102+
return new AnotherDynamicServiceStub(channel, callOptions);
103+
}
104+
105+
/**
106+
*/
107+
public void method(io.grpc.reflection.testing.DynamicRequest request,
108+
io.grpc.stub.StreamObserver<io.grpc.reflection.testing.DynamicReply> responseObserver) {
109+
asyncUnaryCall(
110+
getChannel().newCall(METHOD_METHOD, getCallOptions()), request, responseObserver);
111+
}
112+
}
113+
114+
/**
115+
*/
116+
public static final class AnotherDynamicServiceBlockingStub extends io.grpc.stub.AbstractStub<AnotherDynamicServiceBlockingStub> {
117+
private AnotherDynamicServiceBlockingStub(io.grpc.Channel channel) {
118+
super(channel);
119+
}
120+
121+
private AnotherDynamicServiceBlockingStub(io.grpc.Channel channel,
122+
io.grpc.CallOptions callOptions) {
123+
super(channel, callOptions);
124+
}
125+
126+
@java.lang.Override
127+
protected AnotherDynamicServiceBlockingStub build(io.grpc.Channel channel,
128+
io.grpc.CallOptions callOptions) {
129+
return new AnotherDynamicServiceBlockingStub(channel, callOptions);
130+
}
131+
132+
/**
133+
*/
134+
public io.grpc.reflection.testing.DynamicReply method(io.grpc.reflection.testing.DynamicRequest request) {
135+
return blockingUnaryCall(
136+
getChannel(), METHOD_METHOD, getCallOptions(), request);
137+
}
138+
}
139+
140+
/**
141+
*/
142+
public static final class AnotherDynamicServiceFutureStub extends io.grpc.stub.AbstractStub<AnotherDynamicServiceFutureStub> {
143+
private AnotherDynamicServiceFutureStub(io.grpc.Channel channel) {
144+
super(channel);
145+
}
146+
147+
private AnotherDynamicServiceFutureStub(io.grpc.Channel channel,
148+
io.grpc.CallOptions callOptions) {
149+
super(channel, callOptions);
150+
}
151+
152+
@java.lang.Override
153+
protected AnotherDynamicServiceFutureStub build(io.grpc.Channel channel,
154+
io.grpc.CallOptions callOptions) {
155+
return new AnotherDynamicServiceFutureStub(channel, callOptions);
156+
}
157+
158+
/**
159+
*/
160+
public com.google.common.util.concurrent.ListenableFuture<io.grpc.reflection.testing.DynamicReply> method(
161+
io.grpc.reflection.testing.DynamicRequest request) {
162+
return futureUnaryCall(
163+
getChannel().newCall(METHOD_METHOD, getCallOptions()), request);
164+
}
165+
}
166+
167+
private static final int METHODID_METHOD = 0;
168+
169+
private static class MethodHandlers<Req, Resp> implements
170+
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
171+
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
172+
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
173+
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
174+
private final AnotherDynamicServiceImplBase serviceImpl;
175+
private final int methodId;
176+
177+
public MethodHandlers(AnotherDynamicServiceImplBase serviceImpl, int methodId) {
178+
this.serviceImpl = serviceImpl;
179+
this.methodId = methodId;
180+
}
181+
182+
@java.lang.Override
183+
@java.lang.SuppressWarnings("unchecked")
184+
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
185+
switch (methodId) {
186+
case METHODID_METHOD:
187+
serviceImpl.method((io.grpc.reflection.testing.DynamicRequest) request,
188+
(io.grpc.stub.StreamObserver<io.grpc.reflection.testing.DynamicReply>) responseObserver);
189+
break;
190+
default:
191+
throw new AssertionError();
192+
}
193+
}
194+
195+
@java.lang.Override
196+
@java.lang.SuppressWarnings("unchecked")
197+
public io.grpc.stub.StreamObserver<Req> invoke(
198+
io.grpc.stub.StreamObserver<Resp> responseObserver) {
199+
switch (methodId) {
200+
default:
201+
throw new AssertionError();
202+
}
203+
}
204+
}
205+
206+
private static final class AnotherDynamicServiceDescriptorSupplier implements io.grpc.protobuf.ProtoFileDescriptorSupplier {
207+
@java.lang.Override
208+
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
209+
return io.grpc.reflection.testing.DynamicReflectionTestProto.getDescriptor();
210+
}
211+
}
212+
213+
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
214+
215+
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
216+
io.grpc.ServiceDescriptor result = serviceDescriptor;
217+
if (result == null) {
218+
synchronized (AnotherDynamicServiceGrpc.class) {
219+
result = serviceDescriptor;
220+
if (result == null) {
221+
serviceDescriptor = result = new io.grpc.ServiceDescriptor(
222+
SERVICE_NAME,
223+
new AnotherDynamicServiceDescriptorSupplier(),
224+
METHOD_METHOD);
225+
}
226+
}
227+
}
228+
return result;
229+
}
230+
}

services/src/generated/test/grpc/io/grpc/reflection/testing/DynamicServiceGrpc.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
@javax.annotation.Generated(
2121
value = "by gRPC proto compiler (version 1.1.0-SNAPSHOT)",
22-
comments = "Source: io/grpc/reflection/testing/reflection_test.proto")
22+
comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto")
2323
public class DynamicServiceGrpc {
2424

2525
private DynamicServiceGrpc() {}
@@ -28,14 +28,14 @@ private DynamicServiceGrpc() {}
2828

2929
// Static method descriptors that strictly reflect the proto.
3030
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
31-
public static final io.grpc.MethodDescriptor<io.grpc.reflection.testing.Request,
32-
io.grpc.reflection.testing.Reply> METHOD_METHOD =
31+
public static final io.grpc.MethodDescriptor<io.grpc.reflection.testing.DynamicRequest,
32+
io.grpc.reflection.testing.DynamicReply> METHOD_METHOD =
3333
io.grpc.MethodDescriptor.create(
3434
io.grpc.MethodDescriptor.MethodType.UNARY,
3535
generateFullMethodName(
3636
"grpc.reflection.testing.DynamicService", "Method"),
37-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.Request.getDefaultInstance()),
38-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.Reply.getDefaultInstance()));
37+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.DynamicRequest.getDefaultInstance()),
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.reflection.testing.DynamicReply.getDefaultInstance()));
3939

4040
/**
4141
* Creates a new async stub that supports all call types for the service
@@ -66,8 +66,8 @@ public static abstract class DynamicServiceImplBase implements io.grpc.BindableS
6666

6767
/**
6868
*/
69-
public void method(io.grpc.reflection.testing.Request request,
70-
io.grpc.stub.StreamObserver<io.grpc.reflection.testing.Reply> responseObserver) {
69+
public void method(io.grpc.reflection.testing.DynamicRequest request,
70+
io.grpc.stub.StreamObserver<io.grpc.reflection.testing.DynamicReply> responseObserver) {
7171
asyncUnimplementedUnaryCall(METHOD_METHOD, responseObserver);
7272
}
7373

@@ -77,8 +77,8 @@ public void method(io.grpc.reflection.testing.Request request,
7777
METHOD_METHOD,
7878
asyncUnaryCall(
7979
new MethodHandlers<
80-
io.grpc.reflection.testing.Request,
81-
io.grpc.reflection.testing.Reply>(
80+
io.grpc.reflection.testing.DynamicRequest,
81+
io.grpc.reflection.testing.DynamicReply>(
8282
this, METHODID_METHOD)))
8383
.build();
8484
}
@@ -104,8 +104,8 @@ protected DynamicServiceStub build(io.grpc.Channel channel,
104104

105105
/**
106106
*/
107-
public void method(io.grpc.reflection.testing.Request request,
108-
io.grpc.stub.StreamObserver<io.grpc.reflection.testing.Reply> responseObserver) {
107+
public void method(io.grpc.reflection.testing.DynamicRequest request,
108+
io.grpc.stub.StreamObserver<io.grpc.reflection.testing.DynamicReply> responseObserver) {
109109
asyncUnaryCall(
110110
getChannel().newCall(METHOD_METHOD, getCallOptions()), request, responseObserver);
111111
}
@@ -131,7 +131,7 @@ protected DynamicServiceBlockingStub build(io.grpc.Channel channel,
131131

132132
/**
133133
*/
134-
public io.grpc.reflection.testing.Reply method(io.grpc.reflection.testing.Request request) {
134+
public io.grpc.reflection.testing.DynamicReply method(io.grpc.reflection.testing.DynamicRequest request) {
135135
return blockingUnaryCall(
136136
getChannel(), METHOD_METHOD, getCallOptions(), request);
137137
}
@@ -157,8 +157,8 @@ protected DynamicServiceFutureStub build(io.grpc.Channel channel,
157157

158158
/**
159159
*/
160-
public com.google.common.util.concurrent.ListenableFuture<io.grpc.reflection.testing.Reply> method(
161-
io.grpc.reflection.testing.Request request) {
160+
public com.google.common.util.concurrent.ListenableFuture<io.grpc.reflection.testing.DynamicReply> method(
161+
io.grpc.reflection.testing.DynamicRequest request) {
162162
return futureUnaryCall(
163163
getChannel().newCall(METHOD_METHOD, getCallOptions()), request);
164164
}
@@ -184,8 +184,8 @@ public MethodHandlers(DynamicServiceImplBase serviceImpl, int methodId) {
184184
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
185185
switch (methodId) {
186186
case METHODID_METHOD:
187-
serviceImpl.method((io.grpc.reflection.testing.Request) request,
188-
(io.grpc.stub.StreamObserver<io.grpc.reflection.testing.Reply>) responseObserver);
187+
serviceImpl.method((io.grpc.reflection.testing.DynamicRequest) request,
188+
(io.grpc.stub.StreamObserver<io.grpc.reflection.testing.DynamicReply>) responseObserver);
189189
break;
190190
default:
191191
throw new AssertionError();
@@ -206,7 +206,7 @@ public io.grpc.stub.StreamObserver<Req> invoke(
206206
private static final class DynamicServiceDescriptorSupplier implements io.grpc.protobuf.ProtoFileDescriptorSupplier {
207207
@java.lang.Override
208208
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
209-
return io.grpc.reflection.testing.ReflectionTestProto.getDescriptor();
209+
return io.grpc.reflection.testing.DynamicReflectionTestProto.getDescriptor();
210210
}
211211
}
212212

0 commit comments

Comments
 (0)