Updates issue 20. Add org.xerial.snappy.use.systemlib property to lookup snappyjava dll under java.library.path

This commit is contained in:
Taro L. Saito 2011-08-16 13:04:57 +09:00
parent 006425b288
commit 3710c4e7dc
3 changed files with 43 additions and 33 deletions

View File

@ -56,9 +56,9 @@ $ make clean-native native
= Using system installed libsnappyjava (or snappyjava.dll)
Use org.xerial.snappy.enable.bundled.libs system property:
Set org.xerial.snappy.use.systemlib system property to true:
java -Djava.library.path=(path to the installed snappyjava lib) -Dorg.xerial.snappy.enable.bundled.libs=false ...
java -Djava.library.path=(path to the installed snappyjava lib) -Dorg.xerial.snappy.use.systemlib=true ...
With this setting snappy-java does not use bundled native libraries. Insted it tries to load native library installed at the path specified in java.library.path.

View File

@ -51,8 +51,8 @@ import java.util.Properties;
* In default, no configuration is required to use snappy-java, but you can load
* your own native library created by 'make native' command.
*
* This SnappyLoader searches for native libraries (snappyjava.dll, libsnappy.so, etc.)
* in the following order:
* This SnappyLoader searches for native libraries (snappyjava.dll,
* libsnappy.so, etc.) in the following order:
* <ol>
* <li>(System property: <i>org.xerial.snappy.lib.path</i>)/(System property:
* <i>org.xerial.lib.name</i>)
@ -85,7 +85,8 @@ public class SnappyLoader
public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path";
public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name";
public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir";
public static final String KEY_SNAPPY_ENABLE_BUNDLED_LIBS = "org.xerial.snappy.enable.bundled.libs";
public static final String KEY_SNAPPY_USE_SYSTEMLIB = "org.xerial.snappy.use.systemlib";
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs"; // Depreciated, but preserved for backward compatibility
private static boolean isLoaded = false;
private static SnappyNativeAPI api = null;
@ -132,8 +133,9 @@ public class SnappyLoader
/**
* Load SnappyNative and its JNI native implementation in the root class
* loader. This process is necessary to avoid the JNI multi-loading issue when the
* same JNI library is loaded by different class loaders in the same JVM.
* loader. This process is necessary to avoid the JNI multi-loading issue
* when the same JNI library is loaded by different class loaders in the
* same JVM.
*
* In order to load native code in the root class loader, this method first
* inject SnappyNativeLoader class into the root class loader, because
@ -361,11 +363,20 @@ public class SnappyLoader
}
static File findNativeLibrary() {
// Try to load the library from org.xerial.snappy.lib.path library path */
boolean useSystemLib = Boolean.parseBoolean(System.getProperty(KEY_SNAPPY_USE_SYSTEMLIB, "false"));
if (useSystemLib)
return null;
boolean disabledBundledLibs = Boolean
.parseBoolean(System.getProperty(KEY_SNAPPY_DISABLE_BUNDLED_LIBS, "false"));
if (disabledBundledLibs)
return null;
// Try to load the library in org.xerial.snappy.lib.path */
String snappyNativeLibraryPath = System.getProperty(KEY_SNAPPY_LIB_PATH);
String snappyNativeLibraryName = System.getProperty(KEY_SNAPPY_LIB_NAME);
if (System.getProperty(KEY_SNAPPY_ENABLE_BUNDLED_LIBS, "true").equals("true")) {
// Resolve the library file name with a suffix (e.g., dll, .so, etc.)
if (snappyNativeLibraryName == null)
snappyNativeLibraryName = System.mapLibraryName("snappyjava");
@ -389,7 +400,6 @@ public class SnappyLoader
return extractLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder);
}
}
}
return null; // Use a pre-installed snappyjava
}

View File

@ -117,7 +117,7 @@ public class SnappyLoaderTest
public static void main(String[] args) {
// Test for loading native library specified in -Djava.library.path
System.setProperty(SnappyLoader.KEY_SNAPPY_ENABLE_BUNDLED_LIBS, "false");
System.setProperty(SnappyLoader.KEY_SNAPPY_USE_SYSTEMLIB, "true");
_logger.debug(Snappy.getNativeLibraryVersion());
}
}