This commit is contained in:
Francesco Nigro 2019-04-12 11:25:08 +02:00
commit 4b2993666a
4 changed files with 67 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}
}

View File

@ -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 {

View File

@ -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