jduo commented on a change in pull request #7994:
URL: https://github.com/apache/arrow/pull/7994#discussion_r513686533



##########
File path: 
java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ContextAdapter.java
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.flight.grpc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.arrow.flight.RequestContext;
+import org.apache.arrow.flight.auth2.Auth2Constants;
+
+import io.grpc.Context;
+
+/**
+ * Adapter class for gRPC contexts.
+ */
+public class ContextAdapter implements RequestContext {
+  // gRPC uses reference equality when looking up keys in a Context. Cache 
used keys in this static map
+  // so that look ups can succeed.
+  private static final Map<String, Context.Key<String>> usedKeys = new 
HashMap<>();
+  private static final Context.Key<String> authkey = 
Context.keyWithDefault(Auth2Constants.PEER_IDENTITY_KEY, "");
+  private Context context = Context.current();
+
+  /**
+   * Retrieves the gRPC context.
+   * @return the gRPC context.
+   */
+  public Context getContext() {
+    return context;
+  }
+
+  @Override
+  public void put(String key, String value) {
+    context = context.withValue(authkey, value);

Review comment:
       I've removed ContextAdapter, and implemented what you suggested earlier 
(store a map in the gRPC context and expose the map to the middleware methods).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to