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

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 10807b6d674 (chores) camel-mina: cleaned up duplicated code
10807b6d674 is described below

commit 10807b6d674f17f8362dfe65b377f921c48485db
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Jul 28 09:12:52 2022 +0200

    (chores) camel-mina: cleaned up duplicated code
---
 .../apache/camel/component/mina/MinaConsumer.java  | 50 ++++++++++------------
 1 file changed, 22 insertions(+), 28 deletions(-)

diff --git 
a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
 
b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
index 0aa63db53b8..578029e66cc 100644
--- 
a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
+++ 
b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
@@ -22,6 +22,7 @@ import java.net.SocketAddress;
 import java.nio.charset.Charset;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
 
 import org.apache.camel.CamelException;
 import org.apache.camel.Exchange;
@@ -182,24 +183,32 @@ public class MinaConsumer extends DefaultConsumer {
         // acceptor connectorConfig
         configureCodecFactory("MinaConsumer", acceptor, configuration);
         ((NioSocketAcceptor) acceptor).setReuseAddress(true);
+        setupNioSocketAcceptor(configuration, minaLogger, filters);
+        if (configuration.getSslContextParameters() != null) {
+            SslFilter filter = new SslFilter(
+                    
configuration.getSslContextParameters().createSSLContext(getEndpoint().getCamelContext()),
+                    configuration.isAutoStartTls());
+            filter.setUseClientMode(false);
+            acceptor.getFilterChain().addFirst("sslFilter", filter);
+        }
+    }
+
+    private void setupNioSocketAcceptor(MinaConfiguration configuration, 
boolean minaLogger, List<IoFilter> filters) {
         acceptor.setCloseOnDeactivation(true);
 
-        if (configuration.isOrderedThreadPoolExecutor()) {
-            workerPool = new 
OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
-        } else {
-            workerPool = new 
UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
-        }
+        workerPool = createThreadPool(configuration);
         acceptor.getFilterChain().addLast("threadPool", new 
ExecutorFilter(workerPool));
         if (minaLogger) {
             acceptor.getFilterChain().addLast("logger", new LoggingFilter());
         }
         appendIoFiltersToChain(filters, acceptor.getFilterChain());
-        if (configuration.getSslContextParameters() != null) {
-            SslFilter filter = new SslFilter(
-                    
configuration.getSslContextParameters().createSSLContext(getEndpoint().getCamelContext()),
-                    configuration.isAutoStartTls());
-            filter.setUseClientMode(false);
-            acceptor.getFilterChain().addFirst("sslFilter", filter);
+    }
+
+    private ThreadPoolExecutor createThreadPool(MinaConfiguration 
configuration) {
+        if (configuration.isOrderedThreadPoolExecutor()) {
+            return new 
OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
+        } else {
+            return new 
UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
         }
     }
 
@@ -213,11 +222,7 @@ public class MinaConsumer extends DefaultConsumer {
         final int processorCount = Runtime.getRuntime().availableProcessors() 
+ 1;
         connector = new NioSocketConnector(processorCount);
 
-        if (configuration.isOrderedThreadPoolExecutor()) {
-            workerPool = new 
OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
-        } else {
-            workerPool = new 
UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
-        }
+        workerPool = createThreadPool(configuration);
         connector.getFilterChain().addLast("threadPool", new 
ExecutorFilter(workerPool));
         if (minaLogger) {
             connector.getFilterChain().addLast("logger", new LoggingFilter());
@@ -276,18 +281,7 @@ public class MinaConsumer extends DefaultConsumer {
 
         // acceptor connectorConfig
         configureDataGramCodecFactory("MinaConsumer", acceptor, configuration);
-        acceptor.setCloseOnDeactivation(true);
-        // reuse address is default true for datagram
-        if (configuration.isOrderedThreadPoolExecutor()) {
-            workerPool = new 
OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
-        } else {
-            workerPool = new 
UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
-        }
-        acceptor.getFilterChain().addLast("threadPool", new 
ExecutorFilter(workerPool));
-        if (minaLogger) {
-            acceptor.getFilterChain().addLast("logger", new LoggingFilter());
-        }
-        appendIoFiltersToChain(filters, acceptor.getFilterChain());
+        setupNioSocketAcceptor(configuration, minaLogger, filters);
         if (configuration.getSslContextParameters() != null) {
             LOG.warn("Using datagram protocol, {}, but an SSLContextParameters 
instance was provided. "
                      + "SSLContextParameters is only supported on the TCP 
protocol.",

Reply via email to