Loads the necessary library files. Calling this method twice will have no effect. By default the method extracts the shared library for loading at java.io.tmpdir, however, you can override this temporary location by setting the environment variable ROCKSDB_SHAREDLIB_DIR.
()
| 43 | * setting the environment variable ROCKSDB_SHAREDLIB_DIR. |
| 44 | */ |
| 45 | public static void loadLibrary() { |
| 46 | if (libraryLoaded.get() == LibraryState.LOADED) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | if (libraryLoaded.compareAndSet(LibraryState.NOT_LOADED, |
| 51 | LibraryState.LOADING)) { |
| 52 | final String tmpDir = System.getenv("ROCKSDB_SHAREDLIB_DIR"); |
| 53 | // loading possibly necessary libraries. |
| 54 | for (final CompressionType compressionType : CompressionType.values()) { |
| 55 | try { |
| 56 | if (compressionType.getLibraryName() != null) { |
| 57 | System.loadLibrary(compressionType.getLibraryName()); |
| 58 | } |
| 59 | } catch (UnsatisfiedLinkError e) { |
| 60 | // since it may be optional, we ignore its loading failure here. |
| 61 | } |
| 62 | } |
| 63 | try { |
| 64 | NativeLibraryLoader.getInstance().loadLibrary(tmpDir); |
| 65 | } catch (IOException e) { |
| 66 | libraryLoaded.set(LibraryState.NOT_LOADED); |
| 67 | throw new RuntimeException("Unable to load the RocksDB shared library" |
| 68 | + e); |
| 69 | } |
| 70 | |
| 71 | libraryLoaded.set(LibraryState.LOADED); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | while (libraryLoaded.get() == LibraryState.LOADING) { |
| 76 | try { |
| 77 | Thread.sleep(10); |
| 78 | } catch(final InterruptedException e) { |
| 79 | //ignore |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Tries to load the necessary library files from the given list of |