From b2b8fcdb48dfab319b50484d84b3e640551cb053 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 28 Sep 2021 10:56:11 +0800 Subject: [PATCH 1/2] Revert LinkedHashMap in Invocation to HashMap --- .../org/apache/dubbo/rpc/RpcInvocation.java | 22 +++++++++---------- .../dubbo/rpc/filter/ContextFilter.java | 3 ++- .../dubbo/DecodeableRpcInvocation.java | 4 ++-- .../rpc/protocol/tri/AbstractStream.java | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index 86345f6be92..1b7b412c309 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -30,7 +30,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Arrays; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -76,7 +76,7 @@ public class RpcInvocation implements Invocation, Serializable { /** * Only used on the caller side, will not appear on the wire. */ - private transient Map attributes = new LinkedHashMap(); + private transient Map attributes = new HashMap(); private transient Invoker invoker; @@ -91,7 +91,7 @@ public RpcInvocation() { public RpcInvocation(Invocation invocation, Invoker invoker) { this(invocation.getServiceModel(), invocation.getMethodName(), invocation.getServiceName(), invocation.getProtocolServiceKey(), - invocation.getParameterTypes(), invocation.getArguments(), new LinkedHashMap<>(invocation.getObjectAttachments()), + invocation.getParameterTypes(), invocation.getArguments(), new HashMap<>(invocation.getObjectAttachments()), invocation.getInvoker(), invocation.getAttributes()); if (invoker != null) { URL url = invoker.getUrl(); @@ -175,8 +175,8 @@ public RpcInvocation(ServiceModel serviceModel, String methodName, String servic this.protocolServiceKey = protocolServiceKey; this.parameterTypes = parameterTypes == null ? new Class[0] : parameterTypes; this.arguments = arguments == null ? new Object[0] : arguments; - this.attachments = attachments == null ? new LinkedHashMap<>() : attachments; - this.attributes = attributes == null ? new LinkedHashMap<>() : attributes; + this.attachments = attachments == null ? new HashMap<>() : attachments; + this.attributes = attributes == null ? new HashMap<>() : attributes; this.invoker = invoker; initParameterDesc(); } @@ -315,7 +315,7 @@ public Map getObjectAttachments() { } public void setObjectAttachments(Map attachments) { - this.attachments = attachments == null ? new LinkedHashMap<>() : attachments; + this.attachments = attachments == null ? new HashMap<>() : attachments; } @Override @@ -331,7 +331,7 @@ public Map getAttachments() { @Deprecated public void setAttachments(Map attachments) { - this.attachments = attachments == null ? new LinkedHashMap<>() : new LinkedHashMap<>(attachments); + this.attachments = attachments == null ? new HashMap<>() : new HashMap<>(attachments); } @Override @@ -342,7 +342,7 @@ public void setAttachment(String key, Object value) { @Override public void setObjectAttachment(String key, Object value) { if (attachments == null) { - attachments = new LinkedHashMap<>(); + attachments = new HashMap<>(); } attachments.put(key, value); } @@ -360,7 +360,7 @@ public void setAttachmentIfAbsent(String key, Object value) { @Override public void setObjectAttachmentIfAbsent(String key, Object value) { if (attachments == null) { - attachments = new LinkedHashMap<>(); + attachments = new HashMap<>(); } if (!attachments.containsKey(key)) { attachments.put(key, value); @@ -373,7 +373,7 @@ public void addAttachments(Map attachments) { return; } if (this.attachments == null) { - this.attachments = new LinkedHashMap<>(); + this.attachments = new HashMap<>(); } this.attachments.putAll(attachments); } @@ -383,7 +383,7 @@ public void addObjectAttachments(Map attachments) { return; } if (this.attachments == null) { - this.attachments = new LinkedHashMap<>(); + this.attachments = new HashMap<>(); } this.attachments.putAll(attachments); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java index fd39c221e3e..722aa1a4a07 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -63,7 +64,7 @@ public class ContextFilter implements Filter, Filter.Listener { private static final Set UNLOADING_KEYS; static { - UNLOADING_KEYS = new HashSet<>(128); + UNLOADING_KEYS = new LinkedHashSet<>(16); UNLOADING_KEYS.add(PATH_KEY); UNLOADING_KEYS.add(INTERFACE_KEY); UNLOADING_KEYS.add(GROUP_KEY); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index 0ed252f543d..3f7c90a9a48 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -43,7 +43,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -225,7 +225,7 @@ public Object decode(Channel channel, InputStream input) throws IOException { if (map != null && map.size() > 0) { Map attachment = getObjectAttachments(); if (attachment == null) { - attachment = new LinkedHashMap<>(); + attachment = new HashMap<>(); } attachment.putAll(map); setObjectAttachments(attachment); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java index 3b8f7fec5ab..404be5c6987 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java @@ -34,7 +34,7 @@ import org.apache.dubbo.rpc.protocol.tri.GrpcStatus.Code; import java.util.ArrayList; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -252,7 +252,7 @@ private Metadata getTrailers(GrpcStatus grpcStatus) { } protected Map parseMetadataToAttachmentMap(Metadata metadata) { - Map attachments = new LinkedHashMap<>(); + Map attachments = new HashMap<>(); for (Map.Entry header : metadata) { String key = header.getKey().toString(); if (Http2Headers.PseudoHeaderName.isPseudoHeader(key)) { From 2f85f48622ea47d12904c0593dc674f02feb4f6f Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 28 Sep 2021 11:01:40 +0800 Subject: [PATCH 2/2] fix import --- .../main/java/org/apache/dubbo/rpc/filter/ContextFilter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java index 722aa1a4a07..c813384b1bb 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -64,7 +63,7 @@ public class ContextFilter implements Filter, Filter.Listener { private static final Set UNLOADING_KEYS; static { - UNLOADING_KEYS = new LinkedHashSet<>(16); + UNLOADING_KEYS = new HashSet<>(16); UNLOADING_KEYS.add(PATH_KEY); UNLOADING_KEYS.add(INTERFACE_KEY); UNLOADING_KEYS.add(GROUP_KEY);