AlbumenJ commented on code in PR #10798: URL: https://github.com/apache/dubbo/pull/10798#discussion_r1006372540
########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); Review Comment: Create a new map, add all attachments from `clientResponse` and `serverResponse`. `serverResponse` should override `clientResponse`. ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); Review Comment: Get from `serverResponse` first and then fall back to `clientResponse` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); Review Comment: Remove in both `serverResponse` and `clientResponse` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); Review Comment: Create a new map, add all attachments from `clientResponse` and `serverResponse`. `serverResponse` should override `clientResponse`. ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); Review Comment: Get from `serverResponse` first and then fall back to `clientResponse` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); + } + + @Override + public Map<String, Object> get() { + return RpcContext.getServerResponseContext().get(); + } + + @Override + public RpcContextAttachment set(String key, Object value) { + return RpcContext.getServerResponseContext().set(key, value); Review Comment: Deprecated method. Proxy it to `setAttachment` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); + } + + @Override + public Map<String, Object> get() { + return RpcContext.getServerResponseContext().get(); + } + + @Override + public RpcContextAttachment set(String key, Object value) { + return RpcContext.getServerResponseContext().set(key, value); + } + + @Override + public RpcContextAttachment remove(String key) { + return RpcContext.getServerResponseContext().remove(key); + } + + @Override + public Object get(String key) { + return RpcContext.getServerResponseContext().get(key); Review Comment: Deprecated method. Proxy it to `getAttachment` ########## dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/PenetrateAttachmentSelectorMock.java: ########## @@ -16,17 +16,24 @@ */ package org.apache.dubbo.rpc.support; +import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.PenetrateAttachmentSelector; import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcContextAttachment; import java.util.Map; public class PenetrateAttachmentSelectorMock implements PenetrateAttachmentSelector { @Override - public Map<String, Object> select() { + public Map<String, Object> select(Invocation invocation, RpcContextAttachment clientAttachment, RpcContextAttachment serverAttachment) { Map<String, Object> objectAttachments = RpcContext.getServerAttachment().getObjectAttachments(); objectAttachments.put("testKey", "testVal"); return objectAttachments; } + + @Override + public Map<String, Object> selectReverse(Invocation invocation, RpcContextAttachment clientResponseContext, RpcContextAttachment serverResponseContext) { + return null; + } Review Comment: Add some test cases for this ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); + } + + @Override + public Map<String, Object> get() { + return RpcContext.getServerResponseContext().get(); + } + + @Override + public RpcContextAttachment set(String key, Object value) { + return RpcContext.getServerResponseContext().set(key, value); + } + + @Override + public RpcContextAttachment remove(String key) { + return RpcContext.getServerResponseContext().remove(key); + } + + @Override + public Object get(String key) { + return RpcContext.getServerResponseContext().get(key); + } + + @Override + public RpcContextAttachment copyOf(boolean needCopy) { + return RpcContext.getServerResponseContext().copyOf(needCopy); + } + + @Override + protected boolean isValid() { + return RpcContext.getServerResponseContext().isValid(); Review Comment: Internal method, should not be called. Throw exception directly. BTW, check the usage. ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); + } + + @Override + public Map<String, Object> get() { + return RpcContext.getServerResponseContext().get(); + } + + @Override + public RpcContextAttachment set(String key, Object value) { + return RpcContext.getServerResponseContext().set(key, value); + } + + @Override + public RpcContextAttachment remove(String key) { + return RpcContext.getServerResponseContext().remove(key); Review Comment: Deprecated method. Proxy it to `removeAttachment` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); + } + + @Override + public Map<String, Object> get() { + return RpcContext.getServerResponseContext().get(); Review Comment: Deprecated method. Proxy it to getAttachements() ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); Review Comment: Clear both `serverResponse` and `clientResponse` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java: ########## @@ -58,6 +62,13 @@ */ @Activate(group = PROVIDER, order = Integer.MIN_VALUE) public class ContextFilter implements Filter, Filter.Listener { + private Set<PenetrateAttachmentSelector> supportedSelectors; + + public ContextFilter() { + ApplicationModel applicationModel = ApplicationModel.defaultModel(); + ExtensionLoader<PenetrateAttachmentSelector> selectorExtensionLoader = applicationModel.getExtensionLoader(PenetrateAttachmentSelector.class); Review Comment: ```suggestion public ContextFilter(ApplicationModel applicationModel) { ExtensionLoader<PenetrateAttachmentSelector> selectorExtensionLoader = applicationModel.getExtensionLoader(PenetrateAttachmentSelector.class); ``` ########## dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcServerContextAttachment.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.Map; + +public class RpcServerContextAttachment extends RpcContextAttachment{ + private static final RpcContextAttachment AGENT_SERVER_CONTEXT = new RpcContextAttachment() { + @Override + public RpcContextAttachment setObjectAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setObjectAttachment(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 RpcContext.getClientResponseContext().getAttachment(key); + } + + @Override + public Object getObjectAttachment(String key) { + return RpcContext.getClientResponseContext().getObjectAttachment(key); + } + + @Override + public RpcContextAttachment setAttachment(String key, String value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment setAttachment(String key, Object value) { + return RpcContext.getServerResponseContext().setAttachment(key, value); + } + + @Override + public RpcContextAttachment removeAttachment(String key) { + return RpcContext.getServerResponseContext().removeAttachment(key); + } + + @Override + public Map<String, String> getAttachments() { + return RpcContext.getServerResponseContext().getAttachments(); + } + + @Override + public Map<String, Object> getObjectAttachments() { + return RpcContext.getServerResponseContext().getObjectAttachments(); + } + + @Override + public RpcContextAttachment setAttachments(Map<String, String> attachment) { + return RpcContext.getServerResponseContext().setAttachments(attachment); + } + + @Override + public RpcContextAttachment setObjectAttachments(Map<String, Object> attachment) { + return RpcContext.getServerResponseContext().setObjectAttachments(attachment); + } + + @Override + public void clearAttachments() { + RpcContext.getServerResponseContext().clearAttachments(); + } + + @Override + public Map<String, Object> get() { + return RpcContext.getServerResponseContext().get(); + } + + @Override + public RpcContextAttachment set(String key, Object value) { + return RpcContext.getServerResponseContext().set(key, value); + } + + @Override + public RpcContextAttachment remove(String key) { + return RpcContext.getServerResponseContext().remove(key); + } + + @Override + public Object get(String key) { + return RpcContext.getServerResponseContext().get(key); + } + + @Override + public RpcContextAttachment copyOf(boolean needCopy) { + return RpcContext.getServerResponseContext().copyOf(needCopy); Review Comment: Internal method, should not be called. Throw exception directly. BTW, check the usage. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
