/** * Extracts the native bindings for sigar and tells sigar where to find them. * * @param nativeLibDir the directory the native libs should be stored to * @return the folder that contains the extracted nativeLibs * @throws Exception */ private static void loadNativeSigarBindings(File nativeLibDir) throws Exception { extractFromJarToTemp(SIGAR_RESOURCE_DIR + new SigarLoader(Sigar.class).getLibraryName(), nativeLibDir); System.setProperty(SIGAR_PATH, nativeLibDir.getAbsolutePath()); nativeLibDir.getAbsolutePath(); }
System.arraycopy(args, 1, pargs, 0, args.length-1); String sigarLib = SigarLoader.getLocation();
", native=" + Sigar.NATIVE_SCM_REVISION; String archlib = SigarLoader.getNativeLibraryName();
final SigarLoader sigarLoader = new SigarLoader(Sigar.class); final String libraryName = sigarLoader.getLibraryName(); sigarLoader.load();
public void init(File nativeDirectory) throws ArchLoaderException, ArchNotSupportedException { final SigarLoader archLoader = new SigarLoader(getClass()); archLoader.setName("sigar"); final String name = archLoader.getLibraryName(); File fl = new File(nativeDirectory, name); addNativeDirectoryToLibPath(nativeDirectory);
private void loadFromPath(final SigarLoader loader) { try { final String systemProp = loader.getPackageName() + ".path"; final String path = System.getProperty(systemProp); if (path == null) { final String libraryName = loader.getLibraryName(); final File output = new File(tempDir, "sigar/" + libraryName); if (!output.exists()) { return; loader.load(output.getParentFile().getAbsolutePath()); afterLoad(systemProp); } catch (final ArchLoaderException | IOException ex) { loader.load(path); afterLoad(systemProp); } catch (final ArchLoaderException ex) {
public void ensureSigarIsSetup() { valid = true; final SigarLoader loader = new SigarLoader(Sigar.class); try { loadFromPath(loader); } catch (final UnsatisfiedLinkError e) { unavailable(e.getMessage()); } }
private static List<String> getSigarLibFiles() { try { String libName = new SigarLoader(SigarProxy.class).getLibraryName(); if (SIGAR_X86_WINNT_DLL.equals(libName)) { return Arrays.asList(SIGAR_X86_WINNT_DLL, SIGAR_X86_WINNT_LIB); } else { return Collections.singletonList(libName); } } catch (ArchNotSupportedException e) { throw new RuntimeException(e); } } }
public static void main(String[] args) { Shell shell = new Shell(); try { if (args.length == 0) { shell.isInteractive = true; } shell.init("sigar", System.out, System.err); shell.registerCommands(); shell.readCommandFile(System.getProperty("user.home")); shell.readCommandFile("."); shell.readCommandFile(SigarLoader.getLocation()); if (shell.isInteractive) { shell.initHistory(); Getline.setCompleter(shell); shell.run(); } else { shell.handleCommand(null, args); } } catch (Exception e) { System.err.println("Unexpected exception: " + e); } finally { shell.shutdown(); } } }
/** * Extracts the native bindings for sigar and tells sigar where to find them. * * @param nativeLibDir the directory the native libs should be stored to * @return the folder that contains the extracted nativeLibs * @throws Exception */ private static void loadNativeSigarBindings(File nativeLibDir) throws Exception { extractFromJarToTemp(SIGAR_RESOURCE_DIR + new SigarLoader(Sigar.class).getLibraryName(), nativeLibDir); System.setProperty(SIGAR_PATH, nativeLibDir.getAbsolutePath()); nativeLibDir.getAbsolutePath(); }
/** * Check silently if sigar was loaded in order to avoid the SigarException: no libsigar-*. * * @return true, if Sigar native library is present in the ClassLoader otherwise false. * @throws IllegalAccessException * @throws NoSuchFieldException */ private static boolean isSigarAlreadyLoaded() throws Exception { final String libraryName = new SigarLoader(Sigar.class).getLibraryName(); final Field loadedLibraryNames = ClassLoader.class.getDeclaredField("loadedLibraryNames"); loadedLibraryNames.setAccessible(true); final Vector<String> libraries = (Vector<String>) loadedLibraryNames.get(SigarProvisioner.class.getClassLoader()); for (String library: libraries) { if(library.contains(libraryName)) return true; } return false; }