public FileSystemInfo(String mountPoint, boolean deferedFetchInfo) { this.mountPoint = mountPoint; this.fetchedInfo = false; if (!deferedFetchInfo) { refresh(); } else { SigarProxy sigar = SigarAccess.getSigar(); createFileSystemObject(sigar); } }
public void refresh() { SigarProxy sigar = SigarAccess.getSigar(); createFileSystemObject(sigar); try { // this is the usage data and therefore should be refreshed this.fsUsage = getMountedFileSystemUsage(sigar, this.mountPoint); this.fetchedInfo = true; } catch (SigarException e) { // this happens when the file system is not available (e.g. if it's a CD-ROM without a CD loaded in it) or // if we don't have permission to access the filesystem. we can ignore it and set the usage data to null. this.fsUsage = null; this.fetchedInfo = true; if (LOG.isTraceEnabled()) { LOG.trace("Cannot refresh the usage data for file system mounted at [" + this.mountPoint + "].", e); } else if (LOG.isDebugEnabled()) { LOG.debug("Cannot refresh the usage data for file system mounted at [" + this.mountPoint + "]: " + e); } } catch (RuntimeException e) { this.fsUsage = null; this.fetchedInfo = true; LOG.error("An error occurred while refreshing the usage data for file system mounted at [" + this.mountPoint + "].", e); } }
private List<FileSystemInfo> getFileSystems(boolean deferredUsageInfo) { List<String> mountPoints = new ArrayList<String>(); try { FileSystemMap map = sigar.getFileSystemMap(); mountPoints.addAll(map.keySet()); } catch (Exception e) { log.warn("Cannot obtain native file system information", e); // ignore native error otherwise } List<FileSystemInfo> infos = new ArrayList<FileSystemInfo>(); for (String mountPoint : mountPoints) { infos.add(new FileSystemInfo(mountPoint, deferredUsageInfo)); } return infos; }
/** * This returns the usage information on the file system. This may return <code>null</code> if the file system is * not available (e.g when a "device not ready" error for CD-ROM drives occurs) or not accessible due to lack of * permission. * * @return file system usage data */ public FileSystemUsage getFileSystemUsage() { if(!this.fetchedInfo){ refresh(); } return this.fsUsage; }
private FileSystemUsage getMountedFileSystemUsage(SigarProxy sigar, String name) throws SigarException, NfsUnreachableException { FileSystem fs = sigar.getFileSystemMap().getFileSystem(name); if (fs == null) { throw new SigarException(name + " is not a mounted filesystem"); } if (fs instanceof NfsFileSystem) { NfsFileSystem nfs = (NfsFileSystem)fs; if (!nfsPing(nfs.getHostname())) { throw nfs.getUnreachableException(); } } return sigar.getFileSystemUsage(name); }
public List<FileSystemInfo> getFileSystems() { List<String> mountPoints = new ArrayList<String>(); try { FileSystemMap map = sigar.getFileSystemMap(); mountPoints.addAll(map.keySet()); } catch (Exception e) { log.warn("Cannot obtain native file system information", e); // ignore native error otherwise } List<FileSystemInfo> infos = new ArrayList<FileSystemInfo>(); for (String mountPoint : mountPoints) { infos.add(new FileSystemInfo(mountPoint)); } return infos; }
public FileSystemInfo(String mountPoint) { this.mountPoint = mountPoint; this.fetchedInfo = false; refresh(); }
public FileSystemInfo getFileSystem(String path) { String mountPoint = null; try { FileSystem mountPointForPath = sigar.getFileSystemMap().getMountPoint(path); if (mountPointForPath != null) mountPoint = mountPointForPath.getDirName(); } catch (Throwable e) { log.warn("Cannot obtain native file system information for [" + path + "]", e); // ignore native error otherwise } FileSystemInfo fileSystem = new FileSystemInfo(mountPoint); return fileSystem; }
public FileSystemInfo(String mountPoint) { this.mountPoint = mountPoint; refresh(); }
public FileSystemInfo getFileSystem(String path) { String mountPoint = null; try { FileSystem mountPointForPath = sigar.getFileSystemMap().getMountPoint(path); if (mountPointForPath != null) mountPoint = mountPointForPath.getDirName(); } catch (Throwable e) { log.warn("Cannot obtain native file system information for [" + path + "]", e); // ignore native error otherwise } FileSystemInfo fileSystem = new FileSystemInfo(mountPoint); return fileSystem; }