summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/io/NativeIO.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/NativeIO.java20
1 files changed, 6 insertions, 14 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
index 28c3f21b24c..af101211b4a 100644
--- a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
+++ b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
@@ -1,6 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.io;
+import com.yahoo.nativec.PosixFAdvise;
+
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
@@ -10,17 +12,12 @@ import java.io.SyncFailedException;
import java.lang.reflect.Field;
import java.util.logging.Logger;
-import com.sun.jna.LastErrorException;
-import com.sun.jna.Native;
-import com.sun.jna.Platform;
-
/**
* Provides functionality only possible through native C library.
*/
public class NativeIO {
private static final Logger logger = Logger.getLogger(NativeIO.class.getName());
private static final String DISABLE_NATIVE_IO = "DISABLE_NATIVE_IO";
- private static final int POSIX_FADV_DONTNEED = 4; // See /usr/include/linux/fadvise.h
private static final InitResult fdField = new InitResult();
private static class InitResult {
private final boolean initialized;
@@ -31,17 +28,14 @@ public class NativeIO {
boolean initComplete = false;
boolean disabled = true;
Field field = null;
- Throwable exception = null;
+ Throwable exception = PosixFAdvise.init();
try {
- if (Platform.isLinux()) {
+ if (exception == null) {
disabled = System.getenv().containsKey(DISABLE_NATIVE_IO);
if (!disabled) {
- Native.register(Platform.C_LIBRARY_NAME);
field = getField(FileDescriptor.class, "fd");
initComplete = true;
}
- } else {
- exception = new RuntimeException("Platform is unsúpported. Only supported on linux.");
}
} catch (Throwable throwable) {
exception = throwable;
@@ -68,14 +62,12 @@ public class NativeIO {
}
}
- private static native int posix_fadvise(int fd, long offset, long len, int flag) throws LastErrorException;
-
public NativeIO() {
if ( ! fdField.isInitialized()) {
if (fdField.isEnabled()) {
logger.warning("Native IO not possible due to " + getError().getMessage());
} else {
- logger.info("Native IO has been disable explicit via system property " + DISABLE_NATIVE_IO);
+ logger.info("Native IO has been disabled explicit via system property " + DISABLE_NATIVE_IO);
}
}
}
@@ -96,7 +88,7 @@ public class NativeIO {
}
}
if (valid()) {
- posix_fadvise(fdField.getNativeFD(fd), offset, len, POSIX_FADV_DONTNEED);
+ PosixFAdvise.posix_fadvise(fdField.getNativeFD(fd), offset, len, PosixFAdvise.POSIX_FADV_DONTNEED);
}
}
/**