Allow to disable native transport and native ssl support via system property. (#7903)
Motivation: Sometimes it's useful to disable native transports / native ssl to debug a problem. We should allow to do so with a system property so people not need to adjust code for this. Modifications: Add system properties which allow to disable native transport and native ssl. Result: Easier to disable native code usage without code changes.
This commit is contained in:
parent
b83328606f
commit
358249e5c9
|
@ -72,45 +72,54 @@ public final class OpenSsl {
|
|||
static {
|
||||
Throwable cause = null;
|
||||
|
||||
// Test if netty-tcnative is in the classpath first.
|
||||
try {
|
||||
Class.forName("io.netty.internal.tcnative.SSL", false, OpenSsl.class.getClassLoader());
|
||||
} catch (ClassNotFoundException t) {
|
||||
cause = t;
|
||||
logger.debug(
|
||||
"netty-tcnative not in the classpath; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable.");
|
||||
}
|
||||
if (SystemPropertyUtil.getBoolean("io.netty.handler.ssl.noOpenSsl", false)) {
|
||||
cause = new UnsupportedOperationException(
|
||||
"OpenSSL was explicit disabled with -Dio.netty.handler.ssl.noOpenSsl=true");
|
||||
|
||||
// If in the classpath, try to load the native library and initialize netty-tcnative.
|
||||
if (cause == null) {
|
||||
logger.debug(
|
||||
"netty-tcnative explicit disabled; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable.", cause);
|
||||
} else {
|
||||
// Test if netty-tcnative is in the classpath first.
|
||||
try {
|
||||
// The JNI library was not already loaded. Load it now.
|
||||
loadTcNative();
|
||||
} catch (Throwable t) {
|
||||
Class.forName("io.netty.internal.tcnative.SSL", false, OpenSsl.class.getClassLoader());
|
||||
} catch (ClassNotFoundException t) {
|
||||
cause = t;
|
||||
logger.debug(
|
||||
"Failed to load netty-tcnative; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable, unless the " +
|
||||
"application has already loaded the symbols by some other means. " +
|
||||
"See http://netty.io/wiki/forked-tomcat-native.html for more information.", t);
|
||||
"netty-tcnative not in the classpath; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable.");
|
||||
}
|
||||
|
||||
try {
|
||||
initializeTcNative();
|
||||
|
||||
// The library was initialized successfully. If loading the library failed above,
|
||||
// reset the cause now since it appears that the library was loaded by some other
|
||||
// means.
|
||||
cause = null;
|
||||
} catch (Throwable t) {
|
||||
if (cause == null) {
|
||||
// If in the classpath, try to load the native library and initialize netty-tcnative.
|
||||
if (cause == null) {
|
||||
try {
|
||||
// The JNI library was not already loaded. Load it now.
|
||||
loadTcNative();
|
||||
} catch (Throwable t) {
|
||||
cause = t;
|
||||
logger.debug(
|
||||
"Failed to load netty-tcnative; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable, unless the " +
|
||||
"application has already loaded the symbols by some other means. " +
|
||||
"See http://netty.io/wiki/forked-tomcat-native.html for more information.", t);
|
||||
}
|
||||
|
||||
try {
|
||||
initializeTcNative();
|
||||
|
||||
// The library was initialized successfully. If loading the library failed above,
|
||||
// reset the cause now since it appears that the library was loaded by some other
|
||||
// means.
|
||||
cause = null;
|
||||
} catch (Throwable t) {
|
||||
if (cause == null) {
|
||||
cause = t;
|
||||
}
|
||||
logger.debug(
|
||||
"Failed to initialize netty-tcnative; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable. " +
|
||||
"See http://netty.io/wiki/forked-tomcat-native.html for more information.", t);
|
||||
}
|
||||
logger.debug(
|
||||
"Failed to initialize netty-tcnative; " +
|
||||
OpenSslEngine.class.getSimpleName() + " will be unavailable. " +
|
||||
"See http://netty.io/wiki/forked-tomcat-native.html for more information.", t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package io.netty.channel.epoll;
|
|||
|
||||
import io.netty.channel.unix.FileDescriptor;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
|
||||
/**
|
||||
* Tells if <a href="http://netty.io/wiki/native-transports.html">{@code netty-transport-native-epoll}</a> is supported.
|
||||
|
@ -27,26 +28,32 @@ public final class Epoll {
|
|||
|
||||
static {
|
||||
Throwable cause = null;
|
||||
FileDescriptor epollFd = null;
|
||||
FileDescriptor eventFd = null;
|
||||
try {
|
||||
epollFd = Native.newEpollCreate();
|
||||
eventFd = Native.newEventFd();
|
||||
} catch (Throwable t) {
|
||||
cause = t;
|
||||
} finally {
|
||||
if (epollFd != null) {
|
||||
try {
|
||||
epollFd.close();
|
||||
} catch (Exception ignore) {
|
||||
// ignore
|
||||
|
||||
if (SystemPropertyUtil.getBoolean("io.netty.transport.noNative", false)) {
|
||||
cause = new UnsupportedOperationException(
|
||||
"Native transport was explicit disabled with -Dio.netty.transport.noNative=true");
|
||||
} else {
|
||||
FileDescriptor epollFd = null;
|
||||
FileDescriptor eventFd = null;
|
||||
try {
|
||||
epollFd = Native.newEpollCreate();
|
||||
eventFd = Native.newEventFd();
|
||||
} catch (Throwable t) {
|
||||
cause = t;
|
||||
} finally {
|
||||
if (epollFd != null) {
|
||||
try {
|
||||
epollFd.close();
|
||||
} catch (Exception ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
if (eventFd != null) {
|
||||
try {
|
||||
eventFd.close();
|
||||
} catch (Exception ignore) {
|
||||
// ignore
|
||||
if (eventFd != null) {
|
||||
try {
|
||||
eventFd.close();
|
||||
} catch (Exception ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +64,8 @@ public final class Epoll {
|
|||
UNAVAILABILITY_CAUSE = PlatformDependent.hasUnsafe()
|
||||
? null
|
||||
: new IllegalStateException(
|
||||
"sun.misc.Unsafe not available",
|
||||
PlatformDependent.getUnsafeUnavailabilityCause());
|
||||
"sun.misc.Unsafe not available",
|
||||
PlatformDependent.getUnsafeUnavailabilityCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package io.netty.channel.kqueue;
|
|||
|
||||
import io.netty.channel.unix.FileDescriptor;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import io.netty.util.internal.UnstableApi;
|
||||
|
||||
/**
|
||||
|
@ -25,20 +26,24 @@ import io.netty.util.internal.UnstableApi;
|
|||
@UnstableApi
|
||||
public final class KQueue {
|
||||
private static final Throwable UNAVAILABILITY_CAUSE;
|
||||
|
||||
static {
|
||||
Throwable cause = null;
|
||||
FileDescriptor kqueueFd = null;
|
||||
try {
|
||||
kqueueFd = Native.newKQueue();
|
||||
} catch (Throwable t) {
|
||||
cause = t;
|
||||
} finally {
|
||||
if (kqueueFd != null) {
|
||||
try {
|
||||
kqueueFd.close();
|
||||
} catch (Exception ignore) {
|
||||
// ignore
|
||||
if (SystemPropertyUtil.getBoolean("io.netty.transport.noNative", false)) {
|
||||
cause = new UnsupportedOperationException(
|
||||
"Native transport was explicit disabled with -Dio.netty.transport.noNative=true");
|
||||
} else {
|
||||
FileDescriptor kqueueFd = null;
|
||||
try {
|
||||
kqueueFd = Native.newKQueue();
|
||||
} catch (Throwable t) {
|
||||
cause = t;
|
||||
} finally {
|
||||
if (kqueueFd != null) {
|
||||
try {
|
||||
kqueueFd.close();
|
||||
} catch (Exception ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue