This is an automated email from the ASF dual-hosted git repository. nigrofranz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/master by this push: new cf2540e ARTEMIS-2301 Minor change on Epoll and kQueue.isAvailable new 4b29936 This closes #2616 cf2540e is described below commit cf2540ebb197ba5802ffafa1d32ab0216e1090a3 Author: Clebert Suconic <clebertsuco...@apache.org> AuthorDate: Thu Apr 11 10:22:39 2019 -0400 ARTEMIS-2301 Minor change on Epoll and kQueue.isAvailable just checking for NoClassDefFound and return false --- .../org/apache/activemq/artemis/utils/Env.java | 12 +++++ .../remoting/impl/netty/CheckDependencies.java | 51 ++++++++++++++++++++++ .../core/remoting/impl/netty/NettyConnector.java | 6 +-- .../core/remoting/impl/netty/NettyAcceptor.java | 6 +-- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Env.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Env.java index ed403f8..a10424b 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Env.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Env.java @@ -59,6 +59,10 @@ public final class Env { */ private static boolean testEnv = false; + private static final String OS = System.getProperty("os.name").toLowerCase(); + private static final boolean IS_LINUX = OS.startsWith("linux"); + private static final boolean IS_MAC = OS.startsWith("mac"); + private Env() { } @@ -79,4 +83,12 @@ public final class Env { Env.testEnv = testEnv; } + public static boolean isLinuxOs() { + return IS_LINUX == true; + } + + public static boolean isMacOs() { + return IS_MAC == true; + } + } diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/CheckDependencies.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/CheckDependencies.java new file mode 100644 index 0000000..987cac9 --- /dev/null +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/CheckDependencies.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.activemq.artemis.core.remoting.impl.netty; + +import io.netty.channel.epoll.Epoll; +import io.netty.channel.kqueue.KQueue; +import org.apache.activemq.artemis.core.client.ActiveMQClientLogger; +import org.apache.activemq.artemis.utils.Env; +import org.jboss.logging.Logger; + +/** + * This class will check for Epoll or KQueue is available, and return false in case of NoClassDefFoundError + * it could be improved to check for other cases eventually. + */ +public class CheckDependencies { + + private static final Logger logger = Logger.getLogger(CheckDependencies.class); + + public static final boolean isEpollAvailable() { + try { + return Env.isLinuxOs() && Epoll.isAvailable(); + } catch (Throwable e) { + ActiveMQClientLogger.LOGGER.unableToCheckKQueueAvailability(e); + return false; + } + } + + public static final boolean isKQueueAvailable() { + try { + return Env.isMacOs() && KQueue.isAvailable(); + } catch (Throwable e) { + ActiveMQClientLogger.LOGGER.unableToCheckKQueueAvailability(e); + return false; + } + } +} diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java index fa0682e..29cc9cd 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java @@ -65,12 +65,10 @@ import io.netty.channel.ChannelPromise; import io.netty.channel.EventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.WriteBufferWaterMark; -import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.kqueue.KQueue; import io.netty.channel.kqueue.KQueueEventLoopGroup; import io.netty.channel.kqueue.KQueueSocketChannel; import io.netty.channel.nio.NioEventLoopGroup; @@ -444,7 +442,7 @@ public class NettyConnector extends AbstractConnector { String connectorType; - if (useEpoll && Epoll.isAvailable()) { + if (useEpoll && CheckDependencies.isEpollAvailable()) { if (useGlobalWorkerPool) { group = SharedEventLoopGroup.getInstance((threadFactory -> new EpollEventLoopGroup(remotingThreads, threadFactory))); } else { @@ -453,7 +451,7 @@ public class NettyConnector extends AbstractConnector { connectorType = EPOLL_CONNECTOR_TYPE; channelClazz = EpollSocketChannel.class; logger.debug("Connector " + this + " using native epoll"); - } else if (useKQueue && KQueue.isAvailable()) { + } else if (useKQueue && CheckDependencies.isKQueueAvailable()) { if (useGlobalWorkerPool) { group = SharedEventLoopGroup.getInstance((threadFactory -> new KQueueEventLoopGroup(remotingThreads, threadFactory))); } else { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java index 47a66f5..5fccc25 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java @@ -54,13 +54,11 @@ import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.WriteBufferWaterMark; -import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.epoll.EpollServerSocketChannel; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.ChannelGroupFuture; import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.kqueue.KQueue; import io.netty.channel.kqueue.KQueueEventLoopGroup; import io.netty.channel.kqueue.KQueueServerSocketChannel; import io.netty.channel.local.LocalAddress; @@ -345,7 +343,7 @@ public class NettyAcceptor extends AbstractAcceptor { remotingThreads = Runtime.getRuntime().availableProcessors() * 3; } - if (useEpoll && Epoll.isAvailable()) { + if (useEpoll && CheckDependencies.isEpollAvailable()) { channelClazz = EpollServerSocketChannel.class; eventLoopGroup = new EpollEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() { @Override @@ -356,7 +354,7 @@ public class NettyAcceptor extends AbstractAcceptor { acceptorType = EPOLL_ACCEPTOR_TYPE; logger.debug("Acceptor using native epoll"); - } else if (useKQueue && KQueue.isAvailable()) { + } else if (useKQueue && CheckDependencies.isKQueueAvailable()) { channelClazz = KQueueServerSocketChannel.class; eventLoopGroup = new KQueueEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() { @Override