You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/11/08 00:00:34 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10798: feat: split rpcContext

AlbumenJ commented on code in PR #10798:
URL: https://github.com/apache/dubbo/pull/10798#discussion_r1016014141


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCallListener.java:
##########
@@ -50,12 +50,14 @@ public void invoke() {
         RpcContext.restoreCancellationContext(cancellationContext);
         InetSocketAddress remoteAddress = (InetSocketAddress) invocation.getAttributes()
             .remove(AbstractServerCall.REMOTE_ADDRESS_KEY);
+        RpcContext.getServerResponseContext().setRemoteAddress(remoteAddress);
         RpcContext.getServerContext().setRemoteAddress(remoteAddress);
         String remoteApp = (String) invocation.getAttributes()
             .remove(TripleHeaderEnum.CONSUMER_APP_NAME_KEY);
         if (null != remoteApp) {
+            RpcContext.getServerResponseContext().setRemoteApplicationName(remoteApp);
             RpcContext.getServerContext().setRemoteApplicationName(remoteApp);
-        }
+        };

Review Comment:
   ```suggestion
           }
   ```



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCallListener.java:
##########
@@ -50,12 +50,14 @@ public void invoke() {
         RpcContext.restoreCancellationContext(cancellationContext);
         InetSocketAddress remoteAddress = (InetSocketAddress) invocation.getAttributes()
             .remove(AbstractServerCall.REMOTE_ADDRESS_KEY);
+        RpcContext.getServerResponseContext().setRemoteAddress(remoteAddress);
         RpcContext.getServerContext().setRemoteAddress(remoteAddress);
         String remoteApp = (String) invocation.getAttributes()
             .remove(TripleHeaderEnum.CONSUMER_APP_NAME_KEY);
         if (null != remoteApp) {
+            RpcContext.getServerResponseContext().setRemoteApplicationName(remoteApp);
             RpcContext.getServerContext().setRemoteApplicationName(remoteApp);

Review Comment:
   ```suggestion
           RpcContext.getServiceContext().setRemoteApplicationName(remoteApp);
   ```



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCallListener.java:
##########
@@ -50,12 +50,14 @@ public void invoke() {
         RpcContext.restoreCancellationContext(cancellationContext);
         InetSocketAddress remoteAddress = (InetSocketAddress) invocation.getAttributes()
             .remove(AbstractServerCall.REMOTE_ADDRESS_KEY);
+        RpcContext.getServerResponseContext().setRemoteAddress(remoteAddress);
         RpcContext.getServerContext().setRemoteAddress(remoteAddress);

Review Comment:
   ```suggestion
           RpcContext.getServiceContext().setRemoteAddress(remoteAddress);
   ```



##########
dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.dubbo.rpc;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Objects;
+
+public class RpcServerContextAttachment extends RpcContextAttachment {
+    @Override
+    public RpcContextAttachment copyOf(boolean needCopy) {
+        throw new RuntimeException("copyOf internal method, should not be invoke");
+    }
+
+    @Override
+    protected boolean isValid() {
+        throw new RuntimeException("isValid of is internal method, should not be invoke");
+    }
+
+    @Override
+    public RpcContextAttachment setObjectAttachment(String key, Object value) {
+        return (RpcContextAttachment) getObjectAttachments().put(key, value);
+    }
+
+    @Override
+    protected void setAsyncContext(AsyncContext asyncContext) {
+        RpcContext.getServerResponseContext().setAsyncContext(asyncContext);
+    }
+
+    @Override
+    public boolean isAsyncStarted() {
+        return RpcContext.getServerResponseContext().isAsyncStarted();
+    }
+
+    @Override
+    public boolean stopAsync() {
+        return RpcContext.getServerResponseContext().stopAsync();
+    }
+
+    @Override
+    public AsyncContext getAsyncContext() {
+        return RpcContext.getClientResponseContext().getAsyncContext();
+    }
+
+    @Override
+    public String getAttachment(String key) {
+        return (String) getObjectAttachment(key);
+    }
+
+    @Override
+    public Object getObjectAttachment(String key) {
+        return getAttachmentObjectMap().get(key);
+    }
+
+    @Override
+    public RpcContextAttachment setAttachment(String key, String value) {
+        return (RpcContextAttachment) getAttachmentObjectMap().put(key, value);
+//        return RpcContext.getServerResponseContext().setAttachment(key, value);
+    }
+
+    @Override
+    public RpcContextAttachment setAttachment(String key, Object value) {
+        return (RpcContextAttachment) getObjectAttachments().put(key, value);
+    }
+
+    @Override
+    public RpcContextAttachment removeAttachment(String key) {
+        return (RpcContextAttachment) getAttachmentObjectMap().remove(key);
+    }
+
+    @Override
+    public Map<String, String> getAttachments() {
+        return getAttachmentMap();
+    }
+
+    @Override
+    public Map<String, Object> getObjectAttachments() {
+        return getAttachmentObjectMap();
+    }
+
+    @Override
+    public RpcContextAttachment setAttachments(Map<String, String> attachment) {
+        getAttachmentMap().putAll(attachment);
+        return (RpcContextAttachment) getAttachmentMap();
+    }
+
+    @Override
+    public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) {
+        getAttachmentObjectMap().putAll(attachment);
+        return (RpcContextAttachment) getAttachmentObjectMap();
+    }
+
+    @Override
+    public void clearAttachments() {
+        getAttachmentMap().clear();
+    }
+
+    public Map<String, String> getAttachmentMap() {
+        return new AttachmentMap(this);
+    }
+
+    public Map<String, Object> getAttachmentObjectMap() {
+        return new AttachmentMap(this);
+    }
+
+    @Override
+    public Map<String, Object> get() {
+        return getObjectAttachments();
+    }
+
+    @Override
+    public RpcContextAttachment set(String key, Object value) {
+        return setAttachment(key, value);
+    }
+
+    @Override
+    public RpcContextAttachment remove(String key) {
+        return removeAttachment(key);
+    }
+
+    @Override
+    public Object get(String key) {
+        return getAttachment(key);
+    }
+
+    static class AttachmentMap implements Map {
+        private RpcServerContextAttachment rpcServerContextAttachment;
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+            RpcServerContextAttachment.AttachmentMap that = (RpcServerContextAttachment.AttachmentMap) o;
+            return Objects.equals(rpcServerContextAttachment, that.rpcServerContextAttachment);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(rpcServerContextAttachment);
+        }
+
+        public AttachmentMap(RpcServerContextAttachment rpcServerContextAttachment) {
+            Map<String, String> attachmentMap = this;
+            attachmentMap.putAll(getAllAttachmentMap());

Review Comment:
   what is the purpose of these two lines



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org