ARTEMIS-2301 Minor change on Epoll and kQueue.isAvailable
just checking for NoClassDefFound and return false
This commit is contained in:
parent
6713a393ac
commit
cf2540ebb1
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue