2 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
22 class CephNativeLoader {
23 private static final CephNativeLoader instance = new CephNativeLoader();
24 private static boolean initialized = false;
26 private static final String JNI_PATH_ENV_VAR = "CEPH_JNI_PATH";
27 private static final String LIBRARY_NAME = "cephfs_jni";
28 private static final String LIBRARY_FILE = "libcephfs_jni.so";
30 private CephNativeLoader() {}
32 public static CephNativeLoader getInstance() {
36 public synchronized void loadLibrary() {
40 boolean success = false;
43 * Allow a Ceph specific environment variable to force
46 String path = System.getenv(JNI_PATH_ENV_VAR);
49 System.out.println("Loading libcephfs-jni: " + path);
55 * Try default Java loading path(s)
57 System.out.println("Loading libcephfs-jni from default path: " +
58 System.getProperty("java.library.path"));
59 System.loadLibrary(LIBRARY_NAME);
61 } catch (final UnsatisfiedLinkError ule1) {
64 * Try RHEL/CentOS default path
66 path = "/usr/lib64/" + LIBRARY_FILE;
67 System.out.println("Loading libcephfs-jni: " + path);
70 } catch (final UnsatisfiedLinkError ule2) {
72 * Try Ubuntu default path
74 path = "/usr/lib/jni/" + LIBRARY_FILE;
75 System.out.println("Loading libcephfs-jni: " + path);
82 System.out.println("Loading libcephfs-jni: " +
83 (success ? "Success!" : "Failure!"));
87 * Finish initialization
89 CephMount.native_initialize();