/** * Takes a fresh snapshot of non static properties of the underlying process. This method internally serializes * calls so that it maintains a consistent view of the various Sigar call results. * * @throws SystemInfoException */ public void refresh() throws SystemInfoException { // Serializing is also important as in somes cases, the process could be reported up while being down. // See this thread on VMWare forum: http://communities.vmware.com/message/2187972#2187972 boolean acquiredLock = false; try { acquiredLock = refreshLock.tryLock(REFRESH_LOCK_ACQUIRE_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (InterruptedException e) { LOG.error("Thread interrupted while trying to acquire ProcessInfo[" + this.pid + "] refresh lock", e); } if (!acquiredLock) { throw new RuntimeException("Could not acquire ProcessInfo[" + this.pid + "] refresh lock"); } try { // No need to update if the process has already been reported down, Sigar will only throw exceptions... if (priorSnaphot().isRunning()) { update(this.pid); } } finally { refreshLock.unlock(); } }
protected File getBaseDir(ProcessInfo process, JavaCommandLine javaCommandLine, File homeDir) { String baseDirString = javaCommandLine.getSystemProperties().get(getBaseDirSystemPropertyName()); File baseDir; if (baseDirString != null) { baseDir = new File(baseDirString); if (!baseDir.isAbsolute()) { if (process.priorSnaphot().getExecutable() == null) { baseDir = new File(homeDir, baseDirString); if (!baseDir.exists()) { throw new RuntimeException(getBaseDirSystemPropertyName() + " for AS7 process " + process + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } } else { String cwd = process.priorSnaphot().getExecutable().getCwd(); baseDir = new File(cwd, baseDirString); if (!baseDir.exists()) { baseDir = new File(homeDir, baseDirString); } } } baseDir = new File(FileUtils.getCanonicalPath(baseDir.getPath())); } else { baseDir = new File(homeDir, getDefaultBaseDirName()); } return baseDir; }
/** * @deprecated as of 4.6. For similar purpose, call {@link #priorSnaphot()} and then corresponding method * from the returned {@link ProcessInfoSnapshot}. */ @Deprecated public ProcCpu getCpu() throws SystemInfoException { return priorSnaphot().getCpu(); }
procTimes.add(priorSnaphot.getTime()); } catch (Exception e) { procMems.add(priorSnaphot.getMemory()); } catch (Exception e) { procCpus.add(priorSnaphot.getCpu()); } catch (Exception e) { procFds.add(priorSnaphot.getFileDescriptor()); } catch (Exception e) {
procTimes.add(priorSnaphot.getTime()); } catch (Exception e) { procMems.add(priorSnaphot.getMemory()); } catch (Exception e) { procCpus.add(priorSnaphot.getCpu()); } catch (Exception e) { procFds.add(priorSnaphot.getFileDescriptor()); } catch (Exception e) {
if (!processInfo.priorSnaphot().isRunning()) {
} else { ProcessInfo processInfo = context.getNativeProcess(); if (processInfo != null && processInfo.priorSnaphot().isRunning()) { availabilityType = previousAvailabilityType; } else {
/** * Takes a fresh snapshot of non static properties of the underlying process. This method internally serializes * calls so that it maintains a consistent view of the various Sigar call results. * * @throws SystemInfoException */ public void refresh() throws SystemInfoException { // Serializing is also important as in somes cases, the process could be reported up while being down. // See this thread on VMWare forum: http://communities.vmware.com/message/2187972#2187972 boolean acquiredLock = false; try { acquiredLock = refreshLock.tryLock(REFRESH_LOCK_ACQUIRE_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (InterruptedException e) { LOG.error("Thread interrupted while trying to acquire ProcessInfo[" + this.pid + "] refresh lock", e); } if (!acquiredLock) { throw new RuntimeException("Could not acquire ProcessInfo[" + this.pid + "] refresh lock"); } try { // No need to update if the process has already been reported down, Sigar will only throw exceptions... if (priorSnaphot().isRunning()) { update(this.pid); } } finally { refreshLock.unlock(); } }
protected File getConfigDir(ProcessInfo process, JavaCommandLine javaCommandLine, File baseDir) { String configDirString = javaCommandLine.getSystemProperties().get(getConfigDirSystemPropertyName()); File configDir; if (configDirString != null) { configDir = new File(configDirString); if (!configDir.isAbsolute()) { if (process.priorSnaphot().getExecutable() == null) { throw new RuntimeException(getConfigDirSystemPropertyName() + " for AS7 process " + process + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } String cwd = process.priorSnaphot().getExecutable().getCwd(); configDir = new File(cwd, configDirString); } configDir = new File(FileUtils.getCanonicalPath(configDir.getPath())); } else { configDir = new File(baseDir, getDefaultConfigDirName()); } return configDir; }
/** * Returns a {@link ProcessInfo} instance for the parent of this process. * * This method uses the parent process id which is not static (it can change if the parent process dies before its * child). So in theory it should be moved to the {@link ProcessInfoSnapshot} type. * * In practice, it stays here because the parent {@link ProcessInfo} instance is cached after creation. * * @since 4.4 */ public ProcessInfo getParentProcess() throws SystemInfoException { if (this.parentProcess == null) { this.parentProcess = new ProcessInfo(priorSnaphot().getParentPid(), sigar); } else { this.parentProcess.refresh(); } return this.parentProcess; }
/** * Returns a {@link ProcessInfo} instance for the parent of this process. * * This method uses the parent process id which is not static (it can change if the parent process dies before its * child). So in theory it should be moved to the {@link ProcessInfoSnapshot} type. * * In practice, it stays here because the parent {@link ProcessInfo} instance is cached after creation. * * @since 4.4 */ public ProcessInfo getParentProcess() throws SystemInfoException { if (this.parentProcess == null) { this.parentProcess = new ProcessInfo(priorSnaphot().getParentPid(), sigar); } else { this.parentProcess.refresh(); } return this.parentProcess; }
protected File getLogDir(ProcessInfo process, AS7CommandLine commandLine, File baseDir) { String logDirString = commandLine.getSystemProperties().get(getLogDirSystemPropertyName()); File logDir; if (logDirString != null) { logDir = new File(logDirString); if (!logDir.isAbsolute()) { if (process.priorSnaphot().getExecutable() == null) { throw new RuntimeException(getLogDirSystemPropertyName() + " for AS7 process " + process + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } String cwd = process.priorSnaphot().getExecutable().getCwd(); logDir = new File(cwd, logDirString); } logDir = new File(FileUtils.getCanonicalPath(logDir.getPath())); } else { logDir = new File(baseDir, getDefaultLogDirName()); } return logDir; }
@Override public String toString() { StringBuilder s = new StringBuilder("process: "); s.append("pid=["); s.append(getPid()); s.append("], name=["); s.append((!getName().equals(UNKNOWN_PROCESS_NAME)) ? getName() : getBaseName()); s.append("], ppid=["); try { s.append(priorSnaphot().getParentPid()); } catch (Exception e) { s.append(e); } s.append("]"); return s.toString(); }
@Override public String toString() { StringBuilder s = new StringBuilder("process: "); s.append("pid=["); s.append(getPid()); s.append("], name=["); s.append((!getName().equals(UNKNOWN_PROCESS_NAME)) ? getName() : getBaseName()); s.append("], ppid=["); try { s.append(priorSnaphot().getParentPid()); } catch (Exception e) { s.append(e); } s.append("]"); return s.toString(); }
private boolean isRediscoveryRequired(ProcessInfo processInfo) { return processInfo == null || !processInfo.freshSnapshot().isRunning(); }
protected File getHomeDir(ProcessInfo processInfo, JavaCommandLine javaCommandLine) { String home = javaCommandLine.getSystemProperties().get(HOME_DIR_SYSPROP); File homeDir = new File(home); if (!homeDir.isAbsolute()) { if (processInfo.priorSnaphot().getExecutable() == null) { throw new RuntimeException(HOME_DIR_SYSPROP + " for AS7 process " + processInfo + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } String cwd = processInfo.priorSnaphot().getExecutable().getCwd(); homeDir = new File(cwd, home); } return new File(FileUtils.getCanonicalPath(homeDir.getPath())); }
/** * @deprecated as of 4.6. For similar purpose, call {@link #priorSnaphot()} and then corresponding method * from the returned {@link ProcessInfoSnapshot}. */ @Deprecated public ProcExe getExecutable() throws SystemInfoException { return priorSnaphot().getExecutable(); }
/** * @deprecated as of 4.6. For similar purpose, call {@link #priorSnaphot()} and then corresponding method * from the returned {@link ProcessInfoSnapshot}. */ @Deprecated public long getParentPid() throws SystemInfoException { return priorSnaphot().getParentPid(); }
/** * @deprecated as of 4.6. For similar purpose, call {@link #priorSnaphot()} and then corresponding method * from the returned {@link ProcessInfoSnapshot}. */ @Deprecated public String getCurrentWorkingDirectory() throws SystemInfoException { return priorSnaphot().getCurrentWorkingDirectory(); }
/** * @deprecated as of 4.6. For similar purpose, call {@link #priorSnaphot()} and then corresponding method * from the returned {@link ProcessInfoSnapshot}. */ @Deprecated public ProcCred getCredentials() throws SystemInfoException { return priorSnaphot().getCredentials(); }