Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api, core, services: make ProtoReflectionService interceptor compatible #6967

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,23 +14,18 @@
* limitations under the License.
*/

package io.grpc.internal;

import io.grpc.Context;
import io.grpc.Internal;
import io.grpc.Server;
package io.grpc;

/**
* Internal accessor for getting the {@link Server} instance inside server RPC {@link Context}.
* This is intended for usage internal to the gRPC team, as it's unclear to us what users would
* need. If you *really* think you need to use this, please file an issue for us to discuss a
* public API.
* This is intended for usage internal to the gRPC team. If you think you need to use
* this, contact the gRPC team first.
*/
@Internal
public class InternalServerAccessor {
public static final Context.Key<Server> SERVER_KEY = ServerImpl.SERVER_CONTEXT_KEY;
public class InternalServer {
public static final Context.Key<Server> SERVER_CONTEXT_KEY = Server.SERVER_CONTEXT_KEY;

// Prevent instantiation.
private InternalServerAccessor() {
private InternalServer() {
}
}
8 changes: 8 additions & 0 deletions api/src/main/java/io/grpc/Server.java
Expand Up @@ -30,6 +30,14 @@
@ThreadSafe
public abstract class Server {

/**
* Key for accessing the {@link Server} instance inside server RPC {@link Context}. It's
* unclear to us what users would need. If you think you need to use this, please file an
* issue for us to discuss a public API.
*/
protected static final Context.Key<Server> SERVER_CONTEXT_KEY =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected leaks it. Using package-private is probably better.

Context.key("io.grpc.Server");

/**
* Bind and start the server. After this call returns, clients may begin connecting to the
* listening socket(s).
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/io/grpc/internal/ServerImpl.java
Expand Up @@ -45,7 +45,6 @@
import io.grpc.InternalLogId;
import io.grpc.InternalServerInterceptors;
import io.grpc.Metadata;
import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
Expand Down Expand Up @@ -92,7 +91,6 @@ public final class ServerImpl extends io.grpc.Server implements InternalInstrume
private static final Logger log = Logger.getLogger(ServerImpl.class.getName());
private static final ServerStreamListener NOOP_LISTENER = new NoopListener();

static final Context.Key<Server> SERVER_CONTEXT_KEY = Context.key("io.grpc.ServerImpl");
private final InternalLogId logId;
private final ObjectPool<? extends Executor> executorPool;
/** Executor for application processing. Safe to read after {@link #start()}. */
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/grpc/internal/ServerImplTest.java
Expand Up @@ -561,7 +561,7 @@ public ServerCall.Listener<String> startCall(
Context callContext = callContextReference.get();
assertNotNull(callContext);
assertEquals("context added by tracer", SERVER_TRACER_ADDED_KEY.get(callContext));
assertEquals(server, ServerImpl.SERVER_CONTEXT_KEY.get(callContext));
assertEquals(server, io.grpc.InternalServer.SERVER_CONTEXT_KEY.get(callContext));

streamListener.messagesAvailable(new SingleMessageProducer(STRING_MARSHALLER.stream(request)));
assertEquals(1, executor.runDueTasks());
Expand Down
Expand Up @@ -26,10 +26,10 @@
import com.google.protobuf.Descriptors.ServiceDescriptor;
import io.grpc.BindableService;
import io.grpc.ExperimentalApi;
import io.grpc.InternalServer;
import io.grpc.Server;
import io.grpc.ServerServiceDefinition;
import io.grpc.Status;
import io.grpc.internal.InternalServerAccessor;
import io.grpc.protobuf.ProtoFileDescriptorSupplier;
import io.grpc.reflection.v1alpha.ErrorResponse;
import io.grpc.reflection.v1alpha.ExtensionNumberResponse;
Expand Down Expand Up @@ -86,7 +86,7 @@ public static BindableService newInstance() {
*/
private ServerReflectionIndex getRefreshedIndex() {
synchronized (lock) {
Server server = InternalServerAccessor.SERVER_KEY.get();
Server server = InternalServer.SERVER_CONTEXT_KEY.get();
ServerReflectionIndex index = serverReflectionIndexes.get(server);
if (index == null) {
index =
Expand Down