This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new e8ee154a5c refactor: inspect code of remoting classes. (#10305)
e8ee154a5c is described below

commit e8ee154a5c1192ba8c5aa915c8380f43a1e844fd
Author: stone lion <[email protected]>
AuthorDate: Tue Jul 12 11:17:43 2022 +0800

    refactor: inspect code of remoting classes. (#10305)
---
 .../buffer/ByteBufferBackedChannelBuffer.java      |  8 ++-----
 .../remoting/buffer/DynamicChannelBuffer.java      |  9 ++------
 .../dubbo/remoting/transport/AbstractClient.java   | 14 +++++++----
 .../transport/ChannelHandlerDispatcher.java        |  2 +-
 .../dubbo/remoting/transport/DecodeHandler.java    | 27 +++++++++++-----------
 .../ConnectionOrderedChannelHandler.java           |  2 +-
 6 files changed, 29 insertions(+), 33 deletions(-)

diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ByteBufferBackedChannelBuffer.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ByteBufferBackedChannelBuffer.java
index b35889b0c7..6bcfa16acf 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ByteBufferBackedChannelBuffer.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ByteBufferBackedChannelBuffer.java
@@ -132,10 +132,7 @@ public class ByteBufferBackedChannelBuffer extends 
AbstractChannelBuffer {
         }
 
         if (buffer.hasArray()) {
-            out.write(
-                    buffer.array(),
-                    index + buffer.arrayOffset(),
-                    length);
+            out.write(buffer.array(), index + buffer.arrayOffset(), length);
         } else {
             byte[] tmp = new byte[length];
             ((ByteBuffer) buffer.duplicate().position(index)).get(tmp);
@@ -193,8 +190,7 @@ public class ByteBufferBackedChannelBuffer extends 
AbstractChannelBuffer {
         if (index == 0 && length == capacity()) {
             return buffer.duplicate();
         } else {
-            return ((ByteBuffer) buffer.duplicate().position(
-                    index).limit(index + length)).slice();
+            return ((ByteBuffer) 
buffer.duplicate().position(index).limit(index + length)).slice();
         }
     }
 
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
index 55f7b91ddd..dbd9677a76 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
@@ -40,7 +40,7 @@ public class DynamicChannelBuffer extends 
AbstractChannelBuffer {
             throw new NullPointerException("factory");
         }
         this.factory = factory;
-        buffer = factory.getBuffer(estimatedLength);
+        this.buffer = factory.getBuffer(estimatedLength);
     }
 
     @Override
@@ -49,12 +49,7 @@ public class DynamicChannelBuffer extends 
AbstractChannelBuffer {
             return;
         }
 
-        int newCapacity;
-        if (capacity() == 0) {
-            newCapacity = 1;
-        } else {
-            newCapacity = capacity();
-        }
+        int newCapacity = capacity() == 0 ? 1 : capacity();
         int minNewCapacity = writerIndex() + minWritableBytes;
         while (newCapacity < minNewCapacity) {
             newCapacity <<= 1;
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
index 815777528a..40185dcb68 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
@@ -45,16 +45,17 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.LAZY_CONNECT_KEY
 public abstract class AbstractClient extends AbstractEndpoint implements 
Client {
 
     protected static final String CLIENT_THREAD_POOL_NAME = 
"DubboClientHandler";
+
     private static final Logger logger = 
LoggerFactory.getLogger(AbstractClient.class);
+
     private final Lock connectLock = new ReentrantLock();
+
     private final boolean needReconnect;
-    protected volatile ExecutorService executor;
-    private final ExecutorRepository executorRepository;
 
+    protected volatile ExecutorService executor;
 
     public AbstractClient(URL url, ChannelHandler handler) throws 
RemotingException {
         super(url, handler);
-        executorRepository = 
url.getOrDefaultApplicationModel().getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
         // set default needReconnect true when channel is not connected
         needReconnect = url.getParameter(Constants.SEND_RECONNECT_KEY, true);
 
@@ -102,14 +103,17 @@ public abstract class AbstractClient extends 
AbstractEndpoint implements Client
     }
 
     private void initExecutor(URL url) {
+        ExecutorRepository executorRepository = 
url.getOrDefaultApplicationModel()
+            
.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
+
         /**
          * Consumer's executor is shared globally, provider ip doesn't need to 
be part of the thread name.
          *
          * Instance of url is InstanceAddressURL, so addParameter actually 
adds parameters into ServiceInstance,
          * which means params are shared among different services. Since 
client is shared among services this is currently not a problem.
          */
-        url = url.addParameter(THREAD_NAME_KEY, CLIENT_THREAD_POOL_NAME);
-        url = url.addParameterIfAbsent(THREADPOOL_KEY, 
DEFAULT_CLIENT_THREADPOOL);
+        url = url.addParameter(THREAD_NAME_KEY, CLIENT_THREAD_POOL_NAME)
+            .addParameterIfAbsent(THREADPOOL_KEY, DEFAULT_CLIENT_THREADPOOL);
         executor = executorRepository.createExecutorIfAbsent(url);
     }
 
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java
index 3ef2415783..f8b04eeba6 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java
@@ -33,7 +33,7 @@ public class ChannelHandlerDispatcher implements 
ChannelHandler {
 
     private static final Logger logger = 
LoggerFactory.getLogger(ChannelHandlerDispatcher.class);
 
-    private final Collection<ChannelHandler> channelHandlers = new 
CopyOnWriteArraySet<ChannelHandler>();
+    private final Collection<ChannelHandler> channelHandlers = new 
CopyOnWriteArraySet<>();
 
     public ChannelHandlerDispatcher() {
     }
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/DecodeHandler.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/DecodeHandler.java
index a342c4b757..c34c02341c 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/DecodeHandler.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/DecodeHandler.java
@@ -52,18 +52,19 @@ public class DecodeHandler extends 
AbstractChannelHandlerDelegate {
     }
 
     private void decode(Object message) {
-        if (message instanceof Decodeable) {
-            try {
-                ((Decodeable) message).decode();
-                if (log.isDebugEnabled()) {
-                    log.debug("Decode decodeable message " + 
message.getClass().getName());
-                }
-            } catch (Throwable e) {
-                if (log.isWarnEnabled()) {
-                    log.warn("Call Decodeable.decode failed: " + 
e.getMessage(), e);
-                }
-            } // ~ end of catch
-        } // ~ end of if
-    } // ~ end of method decode
+        if (!(message instanceof Decodeable)) {
+            return;
+        }
 
+        try {
+            ((Decodeable) message).decode();
+            if (log.isDebugEnabled()) {
+                log.debug("Decode decodeable message " + 
message.getClass().getName());
+            }
+        } catch (Throwable e) {
+            if (log.isWarnEnabled()) {
+                log.warn("Call Decodeable.decode failed: " + e.getMessage(), 
e);
+            }
+        }
+    }
 }
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java
index be8dc2dfc3..cca7a93cbb 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java
@@ -50,7 +50,7 @@ public class ConnectionOrderedChannelHandler extends 
WrappedChannelHandler {
         String threadName = url.getParameter(THREAD_NAME_KEY, 
DEFAULT_THREAD_NAME);
         connectionExecutor = new ThreadPoolExecutor(1, 1,
                 0L, TimeUnit.MILLISECONDS,
-                new 
LinkedBlockingQueue<Runnable>(url.getPositiveParameter(CONNECT_QUEUE_CAPACITY, 
Integer.MAX_VALUE)),
+            new 
LinkedBlockingQueue<>(url.getPositiveParameter(CONNECT_QUEUE_CAPACITY, 
Integer.MAX_VALUE)),
                 new NamedThreadFactory(threadName, true),
                 new AbortPolicyWithReport(threadName, url)
         );  // FIXME There's no place to release connectionExecutor!

Reply via email to