1 17 18 package org.apache.tomcat.jni; 19 20 25 26 public final class Library { 27 28 29 private static String [] NAMES = {"tcnative-1", "libtcnative-1"}; 30 33 static private Library _instance = null; 34 35 private Library() 36 { 37 boolean loaded = false; 38 String err = ""; 39 for (int i = 0; i < NAMES.length; i++) { 40 try { 41 System.loadLibrary(NAMES[i]); 42 loaded = true; 43 } 44 catch (Throwable e) { 45 if ( i > 0) 46 err += ", "; 47 err += e.getMessage(); 48 } 49 if (loaded) 50 break; 51 } 52 if (!loaded) { 53 err += "("; 54 err += System.getProperty("java.library.path"); 55 err += ")"; 56 throw new UnsatisfiedLinkError (err); 57 } 58 } 59 60 private Library(String libraryName) 61 { 62 System.loadLibrary(libraryName); 63 } 64 65 68 private static native boolean initialize(); 69 72 public static native void terminate(); 73 74 private static native boolean has(int what); 75 76 private static native int version(int what); 77 78 private static native int size(int what); 79 80 81 public static int TCN_MAJOR_VERSION = 0; 82 83 public static int TCN_MINOR_VERSION = 0; 84 85 public static int TCN_PATCH_VERSION = 0; 86 87 public static int TCN_IS_DEV_VERSION = 0; 88 89 public static int APR_MAJOR_VERSION = 0; 90 91 public static int APR_MINOR_VERSION = 0; 92 93 public static int APR_PATCH_VERSION = 0; 94 95 public static int APR_IS_DEV_VERSION = 0; 96 97 98 public static native String versionString(); 99 100 public static native String aprVersionString(); 101 102 103 public static boolean APR_HAVE_IPV6 = false; 104 public static boolean APR_HAS_SHARED_MEMORY = false; 105 public static boolean APR_HAS_THREADS = false; 106 public static boolean APR_HAS_SENDFILE = false; 107 public static boolean APR_HAS_MMAP = false; 108 public static boolean APR_HAS_FORK = false; 109 public static boolean APR_HAS_RANDOM = false; 110 public static boolean APR_HAS_OTHER_CHILD = false; 111 public static boolean APR_HAS_DSO = false; 112 public static boolean APR_HAS_SO_ACCEPTFILTER = false; 113 public static boolean APR_HAS_UNICODE_FS = false; 114 public static boolean APR_HAS_PROC_INVOKED = false; 115 public static boolean APR_HAS_USER = false; 116 public static boolean APR_HAS_LARGE_FILES = false; 117 public static boolean APR_HAS_XTHREAD_FILES = false; 118 public static boolean APR_HAS_OS_UUID = false; 119 120 public static boolean APR_IS_BIGENDIAN = false; 121 124 public static boolean APR_FILES_AS_SOCKETS = false; 125 127 public static boolean APR_CHARSET_EBCDIC = false; 128 130 public static boolean APR_TCP_NODELAY_INHERITED = false; 131 133 public static boolean APR_O_NONBLOCK_INHERITED = false; 134 135 136 public static int APR_SIZEOF_VOIDP; 137 public static int APR_PATH_MAX; 138 public static int APRMAXHOSTLEN; 139 public static int APR_MAX_IOVEC_SIZE; 140 public static int APR_MAX_SECS_TO_LINGER; 141 public static int APR_MMAP_THRESHOLD; 142 public static int APR_MMAP_LIMIT; 143 144 145 public static native long globalPool(); 146 147 152 static public boolean initialize(String libraryName) 153 throws Exception 154 { 155 if (_instance == null) { 156 if (libraryName == null) 157 _instance = new Library(); 158 else 159 _instance = new Library(libraryName); 160 TCN_MAJOR_VERSION = version(0x01); 161 TCN_MINOR_VERSION = version(0x02); 162 TCN_PATCH_VERSION = version(0x03); 163 TCN_IS_DEV_VERSION = version(0x04); 164 APR_MAJOR_VERSION = version(0x11); 165 APR_MINOR_VERSION = version(0x12); 166 APR_PATCH_VERSION = version(0x13); 167 APR_IS_DEV_VERSION = version(0x14); 168 169 APR_SIZEOF_VOIDP = size(1); 170 APR_PATH_MAX = size(2); 171 APRMAXHOSTLEN = size(3); 172 APR_MAX_IOVEC_SIZE = size(4); 173 APR_MAX_SECS_TO_LINGER = size(5); 174 APR_MMAP_THRESHOLD = size(6); 175 APR_MMAP_LIMIT = size(7); 176 177 APR_HAVE_IPV6 = has(0); 178 APR_HAS_SHARED_MEMORY = has(1); 179 APR_HAS_THREADS = has(2); 180 APR_HAS_SENDFILE = has(3); 181 APR_HAS_MMAP = has(4); 182 APR_HAS_FORK = has(5); 183 APR_HAS_RANDOM = has(6); 184 APR_HAS_OTHER_CHILD = has(7); 185 APR_HAS_DSO = has(8); 186 APR_HAS_SO_ACCEPTFILTER = has(9); 187 APR_HAS_UNICODE_FS = has(10); 188 APR_HAS_PROC_INVOKED = has(11); 189 APR_HAS_USER = has(12); 190 APR_HAS_LARGE_FILES = has(13); 191 APR_HAS_XTHREAD_FILES = has(14); 192 APR_HAS_OS_UUID = has(15); 193 APR_IS_BIGENDIAN = has(16); 194 APR_FILES_AS_SOCKETS = has(17); 195 APR_CHARSET_EBCDIC = has(18); 196 APR_TCP_NODELAY_INHERITED = has(19); 197 APR_O_NONBLOCK_INHERITED = has(20); 198 if (APR_MAJOR_VERSION < 1) { 199 throw new UnsatisfiedLinkError ("Unsupported APR Version (" + 200 aprVersionString() + ")"); 201 } 202 if (!APR_HAS_THREADS) { 203 throw new UnsatisfiedLinkError ("Missing APR_HAS_THREADS"); 204 } 205 } 206 return initialize(); 207 } 208 } 209 | Popular Tags |