beiwei30 closed pull request #1776: Extracting public code to the parent class URL: https://github.com/apache/incubator-dubbo/pull/1776
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java index fea2d6a53c..d660b52d3f 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java @@ -109,4 +109,12 @@ public URL getUrl() { return url; } + public ExecutorService getExecutorService() { + ExecutorService cexecutor = executor; + if (cexecutor == null || cexecutor.isShutdown()) { + cexecutor = SHARED_EXECUTOR; + } + return cexecutor; + } + } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/all/AllChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/all/AllChannelHandler.java index 9e5b331cb2..d44f0655e8 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/all/AllChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/all/AllChannelHandler.java @@ -88,12 +88,4 @@ public void caught(Channel channel, Throwable exception) throws RemotingExceptio throw new ExecutionException("caught event", channel, getClass() + " error when process caught event .", t); } } - - private ExecutorService getExecutorService() { - ExecutorService cexecutor = executor; - if (cexecutor == null || cexecutor.isShutdown()) { - cexecutor = SHARED_EXECUTOR; - } - return cexecutor; - } } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java index 1b162d5b6e..fb432a8563 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java @@ -75,10 +75,7 @@ public void disconnected(Channel channel) throws RemotingException { @Override public void received(Channel channel, Object message) throws RemotingException { - ExecutorService cexecutor = executor; - if (cexecutor == null || cexecutor.isShutdown()) { - cexecutor = SHARED_EXECUTOR; - } + ExecutorService cexecutor = getExecutorService(); try { cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message)); } catch (Throwable t) { @@ -100,10 +97,7 @@ public void received(Channel channel, Object message) throws RemotingException { @Override public void caught(Channel channel, Throwable exception) throws RemotingException { - ExecutorService cexecutor = executor; - if (cexecutor == null || cexecutor.isShutdown()) { - cexecutor = SHARED_EXECUTOR; - } + ExecutorService cexecutor = getExecutorService(); try { cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CAUGHT, exception)); } catch (Throwable t) { diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/execution/ExecutionChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/execution/ExecutionChannelHandler.java index 8a19bdd5a3..d31840b688 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/execution/ExecutionChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/execution/ExecutionChannelHandler.java @@ -27,6 +27,7 @@ import com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.ChannelState; import com.alibaba.dubbo.remoting.transport.dispatcher.WrappedChannelHandler; +import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; /** @@ -41,9 +42,10 @@ public ExecutionChannelHandler(ChannelHandler handler, URL url) { @Override public void received(Channel channel, Object message) throws RemotingException { + ExecutorService cexecutor = getExecutorService(); if (message instanceof Request) { try { - executor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message)); + cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message)); } catch (Throwable t) { // FIXME: when the thread pool is full, SERVER_THREADPOOL_EXHAUSTED_ERROR cannot return properly, // therefore the consumer side has to wait until gets timeout. This is a temporary solution to prevent diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/message/MessageOnlyChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/message/MessageOnlyChannelHandler.java index 5abc04e606..cccd931398 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/message/MessageOnlyChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispatcher/message/MessageOnlyChannelHandler.java @@ -35,10 +35,7 @@ public MessageOnlyChannelHandler(ChannelHandler handler, URL url) { @Override public void received(Channel channel, Object message) throws RemotingException { - ExecutorService cexecutor = executor; - if (cexecutor == null || cexecutor.isShutdown()) { - cexecutor = SHARED_EXECUTOR; - } + ExecutorService cexecutor = getExecutorService(); try { cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message)); } catch (Throwable t) { diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java index b00f5679e3..f22ab11b1d 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java @@ -85,6 +85,7 @@ public void testReconnectWarnLog() throws RemotingException, InterruptedExceptio try { Exchangers.connect(url); } catch (Exception e) { + //do nothing } Thread.sleep(1500); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org