You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2019/06/17 17:27:28 UTC

[qpid-jms] branch master updated: QPIDJMS-462: isolate use of native transport classes, facilitate their runtime exclusion

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

robbie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-jms.git


The following commit(s) were added to refs/heads/master by this push:
     new a0793f2  QPIDJMS-462: isolate use of native transport classes, facilitate their runtime exclusion
a0793f2 is described below

commit a0793f2568663cb3f4be3610d5efeb048cbcdeb9
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Mon Jun 17 18:26:31 2019 +0100

    QPIDJMS-462: isolate use of native transport classes, facilitate their runtime exclusion
---
 .../qpid/jms/transports/netty/EpollSupport.java    | 51 ++++++++++++++++++++++
 .../qpid/jms/transports/netty/KQueueSupport.java   | 51 ++++++++++++++++++++++
 .../jms/transports/netty/NettyTcpTransport.java    | 23 ++++------
 qpid-jms-examples/pom.xml                          | 21 +++++++++
 4 files changed, 132 insertions(+), 14 deletions(-)

diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/EpollSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/EpollSupport.java
new file mode 100644
index 0000000..413d702
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/EpollSupport.java
@@ -0,0 +1,51 @@
+/*
+ * 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.qpid.jms.transports.netty;
+
+import java.util.concurrent.ThreadFactory;
+
+import org.apache.qpid.jms.transports.TransportOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollSocketChannel;
+
+public class EpollSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EpollSupport.class);
+
+    public static boolean isAvailable(TransportOptions transportOptions) {
+        try {
+            return transportOptions.isUseEpoll() && Epoll.isAvailable();
+        } catch (NoClassDefFoundError ncdfe) {
+            LOG.debug("Unable to check for Epoll support due to missing class definition", ncdfe);
+            return false;
+        }
+    }
+
+    public static EventLoopGroup createGroup(int nThreads, ThreadFactory ioThreadfactory) {
+        return new EpollEventLoopGroup(nThreads, ioThreadfactory);
+    }
+
+    public static void createChannel(Bootstrap bootstrap) {
+        bootstrap.channel(EpollSocketChannel.class);
+    }
+}
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/KQueueSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/KQueueSupport.java
new file mode 100644
index 0000000..dbfc6c9
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/KQueueSupport.java
@@ -0,0 +1,51 @@
+/*
+ * 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.qpid.jms.transports.netty;
+
+import java.util.concurrent.ThreadFactory;
+
+import org.apache.qpid.jms.transports.TransportOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.kqueue.KQueue;
+import io.netty.channel.kqueue.KQueueEventLoopGroup;
+import io.netty.channel.kqueue.KQueueSocketChannel;
+
+public class KQueueSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(KQueueSupport.class);
+
+    public static boolean isAvailable(TransportOptions transportOptions) {
+        try {
+            return transportOptions.isUseKQueue() && KQueue.isAvailable();
+        } catch (NoClassDefFoundError ncdfe) {
+            LOG.debug("Unable to check for KQueue support due to missing class definition", ncdfe);
+            return false;
+        }
+    }
+
+    public static EventLoopGroup createGroup(int nThreads, ThreadFactory ioThreadfactory) {
+        return new KQueueEventLoopGroup(nThreads, ioThreadfactory);
+    }
+
+    public static void createChannel(Bootstrap bootstrap) {
+        bootstrap.channel(KQueueSocketChannel.class);
+    }
+}
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
index ce19cc0..5ddeea4 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
@@ -48,12 +48,6 @@ import io.netty.channel.ChannelPipeline;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.FixedRecvByteBufAllocator;
 import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.channel.epoll.Epoll;
-import io.netty.channel.epoll.EpollEventLoopGroup;
-import io.netty.channel.epoll.EpollSocketChannel;
-import io.netty.channel.kqueue.KQueue;
-import io.netty.channel.kqueue.KQueueEventLoopGroup;
-import io.netty.channel.kqueue.KQueueSocketChannel;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.handler.logging.LoggingHandler;
@@ -138,15 +132,16 @@ public class NettyTcpTransport implements Transport {
             throw new IllegalStateException("A transport listener must be set before connection attempts.");
         }
 
-        boolean useKQueue = getTransportOptions().isUseKQueue() && KQueue.isAvailable();
-        boolean useEpoll = getTransportOptions().isUseEpoll() && Epoll.isAvailable();
+        TransportOptions transportOptions = getTransportOptions();
+        boolean useKQueue = KQueueSupport.isAvailable(transportOptions);
+        boolean useEpoll = EpollSupport.isAvailable(transportOptions);
 
         if (useKQueue) {
             LOG.trace("Netty Transport using KQueue mode");
-            group = new KQueueEventLoopGroup(1, ioThreadfactory);
+            group = KQueueSupport.createGroup(1, ioThreadfactory);
         } else if (useEpoll) {
             LOG.trace("Netty Transport using Epoll mode");
-            group = new EpollEventLoopGroup(1, ioThreadfactory);
+            group = EpollSupport.createGroup(1, ioThreadfactory);
         } else {
             LOG.trace("Netty Transport using NIO mode");
             group = new NioEventLoopGroup(1, ioThreadfactory);
@@ -155,9 +150,9 @@ public class NettyTcpTransport implements Transport {
         bootstrap = new Bootstrap();
         bootstrap.group(group);
         if (useKQueue) {
-            bootstrap.channel(KQueueSocketChannel.class);
+            KQueueSupport.createChannel(bootstrap);
         } else if (useEpoll) {
-            bootstrap.channel(EpollSocketChannel.class);
+            EpollSupport.createChannel(bootstrap);
         } else {
             bootstrap.channel(NioSocketChannel.class);
         }
@@ -177,8 +172,8 @@ public class NettyTcpTransport implements Transport {
             }
         });
 
-        configureNetty(bootstrap, getTransportOptions());
-        getTransportOptions().setSslContextOverride(sslContextOverride);
+        configureNetty(bootstrap, transportOptions);
+        transportOptions.setSslContextOverride(sslContextOverride);
 
         ChannelFuture future = bootstrap.connect(getRemoteHost(), getRemotePort());
         future.addListener(new ChannelFutureListener() {
diff --git a/qpid-jms-examples/pom.xml b/qpid-jms-examples/pom.xml
index 4d6e407..0792132 100644
--- a/qpid-jms-examples/pom.xml
+++ b/qpid-jms-examples/pom.xml
@@ -60,4 +60,25 @@
     </plugins>
   </build>
 
+  <profiles>
+    <profile>
+      <id>exclude-native-transport-deps</id>
+      <dependencies>
+        <dependency>
+          <groupId>org.apache.qpid</groupId>
+          <artifactId>qpid-jms-client</artifactId>
+          <exclusions>
+            <exclusion>
+              <groupId>io.netty</groupId>
+              <artifactId>netty-transport-native-epoll</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>io.netty</groupId>
+              <artifactId>netty-transport-native-kqueue</artifactId>
+            </exclusion>
+          </exclusions>
+        </dependency>
+      </dependencies>
+    </profile>
+  </profiles>
 </project>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org