private static int identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException e) { return 0; } }
int otherPid = 0; try { otherPid = ProcessUtils.readPid(this.pidFile); } catch(IOException e) { ignorePidFile = !ProcessUtils.isProcessAlive(otherPid);
protected boolean isVmWithProcessIdRunning(final Integer pid) { // note: this will use JNA if available or Attach if available or return false if neither is available return ProcessUtils.isProcessAlive(pid); }
locatorState = (ProcessUtils.isAvailable() ? locatorStatus(locatorPidFile, oldPid, memberName) : locatorStatus(workingDirectory, memberName));
if (!ProcessUtils.isProcessAlive(process)) { if (!continueReading.isRunning()) { continueReading.start();
private static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
int otherPid = 0; try { otherPid = ProcessUtils.readPid(this.pidFile); } catch(IOException e) { ignorePidFile = !ProcessUtils.isProcessAlive(otherPid);
public void testStatusWithStalePidFile() throws Exception { this.workingDirectory = new File(getUniqueName()); this.workingDirectory.mkdir(); assertTrue(this.workingDirectory.isDirectory() && this.workingDirectory.canWrite()); this.pidFile = new File(this.workingDirectory, ProcessType.SERVER.getPidFileName()); final int pid = 0; assertFalse(ProcessUtils.isProcessAlive(pid)); writePid(this.pidFile, pid); final ServerLauncher dirLauncher = new ServerLauncher.Builder() .setWorkingDirectory(workingDirectory.getCanonicalPath()) .build(); try { dirLauncher.status(); fail("Status should have thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { String expected = "Invalid pid '" + pid + "' found in " + this.pidFile.getCanonicalPath(); assertEquals("Message was " + e.getMessage() + " instead of " + expected, expected, e.getMessage()); } } // testStatusWithStalePidFile
protected static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
public void testStatusWithStalePidFile() throws Exception { this.workingDirectory = new File(getUniqueName()); this.workingDirectory.mkdir(); assertTrue(this.workingDirectory.isDirectory() && this.workingDirectory.canWrite()); this.pidFile = new File(this.workingDirectory, ProcessType.LOCATOR.getPidFileName()); final int pid = 0; assertFalse(ProcessUtils.isProcessAlive(pid)); writePid(this.pidFile, pid); final LocatorLauncher dirLauncher = new LocatorLauncher.Builder() .setWorkingDirectory(workingDirectory.getCanonicalPath()) .build(); try { dirLauncher.status(); fail("Status should have thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { String expected = "Invalid pid '" + pid + "' found in " + this.pidFile.getCanonicalPath(); assertEquals("Message was " + e.getMessage() + " instead of " + expected, expected, e.getMessage()); } } // testStatusWithStalePidFile
protected static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
private static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
protected static int getPid() throws PidUnavailableException { return ProcessUtils.identifyPid(); }
int identifyPid() throws PidUnavailableException { return ProcessUtils.identifyPid(); }
int identifyPid() throws PidUnavailableException { return ProcessUtils.identifyPid(); }
/** * Returns the pid for this process. * * @throws PidUnavailableException if parsing the pid from the name of the * RuntimeMXBean fails * * @see java.lang.management.RuntimeMXBean#getName() */ public static int identifyPid() throws PidUnavailableException { return identifyPid(ManagementFactory.getRuntimeMXBean().getName()); }
/** * Returns the pid for this process. * * @throws PidUnavailableException if parsing the pid from the name of the * RuntimeMXBean fails * * @see java.lang.management.RuntimeMXBean#getName() */ public static int identifyPid() throws PidUnavailableException { return identifyPid(ManagementFactory.getRuntimeMXBean().getName()); }
public void testPidUnavailableThrows() { final String name = "Name without PID"; try { ProcessUtils.identifyPid(name); fail("PidUnavailableException should have been thrown for " + name); } catch (PidUnavailableException e) { // passed } } }
protected static int identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } return 0; } }
/** * Constructs a new ProcessLauncher. Parses this process's RuntimeMXBean name * for the pid (process id). * * @param pidFile the file to create and write pid into * @param force if true then the pid file will be replaced if it already exists * * @throws FileAlreadyExistsException if the pid file already exists and force is false * @throws IOException if unable to write pid (process id) to pid file * @throws PidUnavailableException if the pid cannot be parsed from the RuntimeMXBean name * * @see java.lang.management.RuntimeMXBean */ public LocalProcessLauncher(final File pidFile, final boolean force) throws FileAlreadyExistsException, IOException, PidUnavailableException { this.pid = ProcessUtils.identifyPid(); this.pidFile = pidFile; writePid(force); }