private static int identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException e) { return 0; } }
private static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
protected static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
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); }
/** * Ensures that the other process identifies itself by the same pid used by * this stopper to connect to that process. NOT USED EXCEPT IN TEST. * * @return true if the pid matches * * @throws IllegalStateException if the other process identifies itself by a different pid * @throws IOException if a communication problem occurred when accessing the MBeanServerConnection * @throws PidUnavailableException if parsing the pid from the RuntimeMXBean name fails */ boolean checkPidMatches() throws IllegalStateException, IOException, PidUnavailableException { final RuntimeMXBean proxy = ManagementFactory.newPlatformMXBeanProxy( this.server, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); final int remotePid = ProcessUtils.identifyPid(proxy.getName()); if (remotePid != this.pid) { throw new IllegalStateException("Process has different pid '" + remotePid + "' than expected pid '" + this.pid + "'"); } else { return true; } }
/** * Ensures that the other process identifies itself by the same pid used by * this stopper to connect to that process. NOT USED EXCEPT IN TEST. * * @return true if the pid matches * * @throws IllegalStateException if the other process identifies itself by a different pid * @throws IOException if a communication problem occurred when accessing the MBeanServerConnection * @throws PidUnavailableException if parsing the pid from the RuntimeMXBean name fails */ boolean checkPidMatches() throws IllegalStateException, IOException, PidUnavailableException { final RuntimeMXBean proxy = ManagementFactory.newPlatformMXBeanProxy( this.server, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); final int remotePid = ProcessUtils.identifyPid(proxy.getName()); if (remotePid != this.pid) { throw new IllegalStateException("Process has different pid '" + remotePid + "' than expected pid '" + this.pid + "'"); } else { return true; } }
public void testExistingPidFileThrows() throws Exception { final File pidFile = new File(getClass().getSimpleName() + File.separator + "testExistingPidFileThrows.pid"); assertTrue(pidFile.createNewFile()); assertTrue(pidFile.exists()); final FileWriter writer = new FileWriter(pidFile); // use a read pid that exists writer.write(String.valueOf(ProcessUtils.identifyPid())); writer.close(); try { new LocalProcessLauncher(pidFile, false); fail("LocalProcessLauncher should have thrown FileAlreadyExistsException"); } catch (FileAlreadyExistsException e) { // passed } }
protected static int identifyPid(final LogWriterI18n logger) { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException e) { if (logger.fineEnabled()) { logger.fine(e); } return 0; } }
public void testPidFileContainsPid() throws Exception { final File pidFile = new File(getClass().getSimpleName() + File.separator + "testPidFileContainsPid.pid"); final LocalProcessLauncher launcher = new LocalProcessLauncher(pidFile, false); assertNotNull(launcher); assertTrue(pidFile.exists()); final FileReader fr = new FileReader(pidFile); final BufferedReader br = new BufferedReader(fr); final int pid = Integer.parseInt(br.readLine()); br.close(); assertTrue(pid > 0); assertEquals(launcher.getPid(), pid); assertEquals(ProcessUtils.identifyPid(), pid); }
public void testPidAccuracy() throws PidUnavailableException { int pid = ProcessUtils.identifyPid(); assertTrue(pid > 0); int osProcessPid = OSProcess.getId(); if (osProcessPid > 0) { assertEquals(OSProcess.getId(), pid); } else { // not much to test if OSProcess native code is unusable } }
private void validateProcessControllerFactory(boolean isAttachAPIFound) throws Exception { final ProcessControllerFactory factory = new ProcessControllerFactory(); assertEquals(isAttachAPIFound, factory.isAttachAPIFound()); if (isAttachAPIFound) { final ProcessControllerParameters parms = new NullMBeanControllerParameters(); final ProcessController controller = factory.createProcessController(parms, ProcessUtils.identifyPid()); assertTrue(controller instanceof MBeanProcessController); } else { final ProcessControllerParameters parms = new NullFileControllerParameters(); final ProcessController controller = factory.createProcessController(parms, ProcessUtils.identifyPid()); assertTrue(controller instanceof FileProcessController); } }