Skip to content

Commit

Permalink
Add JNA minimum version check (OpenHFT#104)
Browse files Browse the repository at this point in the history
Co-authored-by: rogersimmons <[email protected]>
  • Loading branch information
rogersimmons and rogersimmons authored Jun 22, 2023
1 parent 75814b2 commit 44d1d3f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions affinity/src/main/java/net/openhft/affinity/Affinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.openhft.affinity;

import com.sun.jna.Native;
import net.openhft.affinity.impl.*;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand Down Expand Up @@ -187,13 +188,21 @@ public static void setThreadId() {
}

public static boolean isJNAAvailable() {
if (JNAAvailable == null)
try {
Class.forName("com.sun.jna.Platform");
JNAAvailable = true;
} catch (ClassNotFoundException ignored) {
if (JNAAvailable == null) {
int majorVersion = Integer.parseInt(Native.VERSION.split("\\.")[0]);
if(majorVersion < 5) {
LOGGER.warn("Affinity library requires JNA version >= 5");
JNAAvailable = false;
}
else {
try {
Class.forName("com.sun.jna.Platform");
JNAAvailable = true;
} catch (ClassNotFoundException ignored) {
JNAAvailable = false;
}
}
}
return JNAAvailable;
}

Expand Down

0 comments on commit 44d1d3f

Please sign in to comment.