initialize local snappy loader

This commit is contained in:
Taro L. Saito 2011-08-01 16:56:40 +09:00
parent 94d5356ba9
commit 9c86835cc3

View File

@ -190,13 +190,14 @@ public class SnappyLoader
boolean useNativeCodeInjection = !Boolean.parseBoolean(System.getProperty(KEY_SNAPPY_DISABLE_NATIVE_INJECTION, boolean useNativeCodeInjection = !Boolean.parseBoolean(System.getProperty(KEY_SNAPPY_DISABLE_NATIVE_INJECTION,
"false")); "false"));
try {
if (!useNativeCodeInjection) { if (!useNativeCodeInjection) {
// Use the local loader // Use the local loader
return LocalSnappyNativeLoader.class; return SnappyLoader.class.getClassLoader().loadClass(LocalSnappyNativeLoader.class.getName());
} }
else { else {
// Use parent class loader to load SnappyNative, since Tomcat, which uses different class loaders for each webapps, cannot load JNI interface twice // Use parent class loader to load SnappyNative, since Tomcat, which uses different class loaders for each webapps, cannot load JNI interface twice
try {
final String nativeLoaderClassName = "org.xerial.snappy.SnappyNativeLoader"; final String nativeLoaderClassName = "org.xerial.snappy.SnappyNativeLoader";
ClassLoader rootClassLoader = getRootClassLoader(); ClassLoader rootClassLoader = getRootClassLoader();
// Load a byte code // Load a byte code
@ -235,11 +236,11 @@ public class SnappyLoader
// Load the SnappyNativeLoader class // Load the SnappyNativeLoader class
return rootClassLoader.loadClass(nativeLoaderClassName); return rootClassLoader.loadClass(nativeLoaderClassName);
} }
}
catch (Exception e) { catch (Exception e) {
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage()); throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
} }
}
} }