public void stop(BundleContext context) throws Exception { SnappyLoader.setSnappyApi(null); SnappyLoader.cleanUpExtractedNativeLib(); } }
static synchronized SnappyNative loadSnappyApi() { if (snappyApi != null) { return snappyApi; } loadNativeLibrary(); setSnappyApi(new SnappyNative()); return snappyApi; }
String extractedLibFileName = String.format("snappy-%s-%s-%s", getVersion(), uuid, libraryFileName); File extractedLibFile = new File(targetFolder, extractedLibFileName); extractedLibIn = new FileInputStream(extractedLibFile); if (!contentsEquals(nativeIn, extractedLibIn)) { throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, String.format("Failed to write a native library file at %s", extractedLibFile));
/** * Load a native library of snappy-java */ private synchronized static void loadNativeLibrary() { if (!isLoaded) { try { nativeLibFile = findNativeLibrary(); if (nativeLibFile != null) { // Load extracted or specified snappyjava native library. System.load(nativeLibFile.getAbsolutePath()); } else { // Load preinstalled snappyjava (in the path -Djava.library.path) System.loadLibrary("snappyjava"); } } catch (Exception e) { e.printStackTrace(); throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage()); } isLoaded = true; } }
private static boolean isFixed(boolean skipOnUnknown) { String versionString = SnappyLoader.getVersion(); Matcher matcher = PATTERN_VERSION.matcher(versionString); if (matcher.matches() == false) { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "unrecognized snappy-java version: {0}", //$NON-NLS-1$ versionString)); } return skipOnUnknown; } int[] version = { Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)), }; int[] required = FIXED_VERSION; assert required.length == version.length; for (int i = 0; i < version.length; i++) { int v = version[i]; int r = required[i]; if (v > r) { return true; } else if (v < r) { return false; } } return true; } }
boolean hasNativeLib = hasResource(snappyNativeLibraryPath + "/" + snappyNativeLibraryName); if (!hasNativeLib) { if (OSInfo.getOSName().equals("Mac")) { if (hasResource(snappyNativeLibraryPath + "/" + altName)) { snappyNativeLibraryName = altName; hasNativeLib = true; return extractLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder.getAbsolutePath());
static synchronized BitShuffleNative loadBitShuffleApi() { if (bitshuffleApi != null) { return bitshuffleApi; } loadNativeLibrary(); bitshuffleApi = new BitShuffleNative(); return bitshuffleApi; }
/** * Make a call to {@link System#loadLibrary(String)} to load the native library which assumes * that the library is available on the path based on this {@link Bundle}'s {@link Manifest}. */ public void start(BundleContext context) throws Exception { String library = System.mapLibraryName(LIBRARY_NAME); if (library.toLowerCase().endsWith(".dylib")) { // some MacOS JDK7+ vendors map to dylib instead of jnilib library = library.replace(".dylib", ".jnilib"); } System.loadLibrary(library); SnappyLoader.setSnappyApi(new SnappyNative()); }
public static File findNativeLibrary() { return SnappyLoader.findNativeLibrary(); } }
LOG.debug(MessageFormat.format( "not a snappy-java workaround target: version={0}", //$NON-NLS-1$ SnappyLoader.getVersion())); SnappyLoader.getVersion())); System.setProperty(SnappyLoader.KEY_SNAPPY_LIB_NAME, "libsnappyjava.jnilib"); //$NON-NLS-1$
/** * Clean up a temporary file (native lib) generated by snappy-java. * General users do not need to call this method, since the native library extracted in snappy-java * is deleted upon JVM termination (vie deleteOnExit()). * This method is useful when using a J2EE container, which will restart servlet containers multiple times without * restarting JVM. */ public static void cleanUp() { SnappyLoader.cleanUpExtractedNativeLib(); SnappyLoader.setSnappyApi(null); }