CrazyHZM commented on code in PR #13607: URL: https://github.com/apache/dubbo/pull/13607#discussion_r1456767141
########## dubbo-common/src/main/java/org/apache/dubbo/common/logger/FluentLogger.java: ########## @@ -0,0 +1,122 @@ +/* + * 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.common.logger; + +import java.util.function.Supplier; + +public interface FluentLogger { Review Comment: This change should not be in this PR. ########## dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultHttpResult.java: ########## @@ -0,0 +1,56 @@ +/* + * 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.remoting.http12.message; + +import org.apache.dubbo.remoting.http12.HttpResult; + +import java.util.List; +import java.util.Map; + +public class DefaultHttpResult<T> implements HttpResult<T> { + + private int status; Review Comment: statusCode? ########## dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java: ########## @@ -420,4 +427,33 @@ public static <T> Set<T> toTreeSet(Set<T> set) { } return set; } + + public static <T> Set<T> newHashSet(int expectedSize) { + return new HashSet<>(capacity(expectedSize)); + } + + public static <T> Set<T> newLinkedHashSet(int expectedSize) { + return new LinkedHashSet<>(capacity(expectedSize)); + } + + public static <T, K> Map<K, T> newHashMap(int expectedSize) { + return new HashMap<>(capacity(expectedSize)); + } + + public static <T, K> Map<K, T> newLinkedHashMap(int expectedSize) { + return new LinkedHashMap<>(capacity(expectedSize)); + } + + public static int capacity(int expectedSize) { + if (expectedSize < 3) { + if (expectedSize < 0) { + throw new IllegalArgumentException("expectedSize cannot be negative but was: " + expectedSize); + } + return expectedSize + 1; + } + if (expectedSize < 1 << (Integer.SIZE - 2)) { + return (int) (expectedSize / 0.75F + 1.0F); + } + return Integer.MAX_VALUE; + } Review Comment: What are the benefits of this part of the code? If not, I think we can focus on the important content of the PR itself first, and this part can be deleted first. ########## dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java: ########## @@ -404,13 +405,19 @@ public static <T> T first(Collection<T> values) { return null; } if (values instanceof List) { - List<T> list = (List<T>) values; - return list.get(0); + return ((List<T>) values).get(0); } else { return values.iterator().next(); } } + public static <T> T first(List<T> values) { Review Comment: This can be replaced by` first(Collection<T> values)` ########## dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultHttpResult.java: ########## @@ -0,0 +1,56 @@ +/* + * 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.remoting.http12.message; + +import org.apache.dubbo.remoting.http12.HttpResult; + +import java.util.List; +import java.util.Map; + +public class DefaultHttpResult<T> implements HttpResult<T> { + + private int status; + private Map<String, List<String>> headers; Review Comment: Why is the value of the header an array? ########## dubbo-common/src/main/java/org/apache/dubbo/common/utils/LRU2Cache.java: ########## @@ -19,22 +19,23 @@ import java.util.LinkedHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Function; /** * LRU-2 - * </p> + * <p> * When the data accessed for the first time, add it to history list. If the size of history list reaches max capacity, eliminate the earliest data (first in first out). * When the data already exists in the history list, and be accessed for the second time, then it will be put into cache. - * + * </p> * TODO, consider replacing with ConcurrentHashMap to improve performance under concurrency */ public class LRU2Cache<K, V> extends LinkedHashMap<K, V> { Review Comment: 这个变动如果跟这个PR没有关联,可以单独提个PR。 ########## dubbo-common/src/main/java/org/apache/dubbo/common/utils/TimeUtils.java: ########## @@ -73,4 +73,29 @@ private static synchronized void startTicker() { isTickerAlive = true; } } + + public static Long parseTimeoutToMills(String timeoutVal) { Review Comment: This section is recommended to be put back into the corresponding module first, it does not seem to be general enough. -- 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-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org