Example usage for java.lang Process isAlive

List of usage examples for java.lang Process isAlive

Introduction

In this page you can find the example usage for java.lang Process isAlive.

Prototype

public boolean isAlive() 

Source Link

Document

Tests whether the process represented by this Process is alive.

Usage

From source file:com.samczsun.helios.Helios.java

public static Process launchProcess(ProcessBuilder launch) throws IOException {
    Process process = launch.start();
    processes.add(process);//from   www .j  a v  a 2  s.  com
    submitBackgroundTask(() -> {
        try {
            process.waitFor();
            if (!process.isAlive()) {
                processes.remove(process);
            }
        } catch (InterruptedException e) {
            ExceptionHandler.handle(e);
        }
    });
    return process;
}

From source file:de.jcup.egradle.core.process.SimpleProcessExecutor.java

boolean isAlive(Process p) {
    return p.isAlive();
}

From source file:org.graylog.plugins.backup.strategy.AbstractMongoBackupStrategy.java

protected synchronized void processCommand(List<String> command) throws Exception {
    //need to find a a smart way to manage processBuilder

    ProcessBuilder pb = new ProcessBuilder(command);
    pb.redirectErrorStream(true);/*w  ww.j a  v a 2  s . c  o m*/
    Process p = pb.start();

    Timer timeOut = new Timer();
    timeOut.schedule(new TimerTask() {
        @Override
        public void run() {
            if (p.isAlive()) {
                LOG.warn("restore process take more than 15 sec I'll destroy it");
                p.destroy();
            }
        }

        //this parameter need to be configurable

    }, 15000);

    p.waitFor();
    timeOut.cancel();

}

From source file:urls.CurlStore.java

public Pair<String, InputStream> get() {
    final Triple<String, Process, Long> triple = QUEUE.poll();
    if (triple == null)
        return null;

    final Process process = triple.getMiddle();
    final Long startTime = triple.getRight();
    final String url = triple.getLeft();

    if (process.isAlive()) {
        if (System.currentTimeMillis() - startTime < timeout)
            QUEUE.offer(triple);/*  w w  w. j av a 2  s.  co m*/
        else {
            process.destroy();
            EXIT_VALUES.append(". ");
        }
        return null;
    }

    if (process.exitValue() != 0) {
        EXIT_VALUES.append(process.exitValue() + " ");
        return null;
    }

    return Pair.of(url, process.getInputStream());
}

From source file:org.eclipse.swt.snippets.SnippetExplorer.java

/**
 * Test if the given command can be executed.
 *
 * @param command command to test/*from www  . j a  v a  2s  . c om*/
 * @return <code>false</code> if executing the command failed for any reason
 */
private static boolean canRunCommand(String command) {
    try {
        final Process p = Runtime.getRuntime().exec(command);
        p.waitFor(150, TimeUnit.MILLISECONDS);
        if (p.isAlive()) {
            p.destroy();
            p.waitFor(100, TimeUnit.MILLISECONDS);
            if (p.isAlive()) {
                p.destroyForcibly();
            }
        }
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.antonjohansson.svncommit.core.utils.Bash.java

private boolean isAvailable(Process process, InputStream logStream, InputStream errorStream)
        throws IOException {
    return logStream.available() > 0 || errorStream.available() > 0 || process.isAlive();
}

From source file:org.apache.geode.internal.process.AbstractProcessStreamReaderIntegrationTest.java

protected void assertThatProcessIsAlive(final Process process) {
    assertThat(process.isAlive()).isTrue();
}

From source file:com.orange.clara.cloud.servicedbdumper.dbdumper.core.CoreDumper.java

private void runDump(DatabaseDriver databaseDriver, String fileName)
        throws IOException, InterruptedException, RunProcessException {
    String[] commandLine = databaseDriver.getDumpCommandLine();
    int i = 1;/*from  w ww.  j  a v a  2  s.  c  o  m*/
    while (true) {
        Process p = this.runCommandLine(commandLine);
        try {
            this.filer.store(p.getInputStream(), fileName);
        } catch (IOException e) {
        } catch (Exception e) {
            if (p.isAlive()) {
                p.destroy();
            }
            throw e;
        }
        p.waitFor();
        if (p.exitValue() == 0) {
            break;
        }
        if (i >= this.dbCommandRetry) {
            this.filer.delete(fileName);
            throw new RunProcessException("\nError during process (exit code is " + p.exitValue() + "): ");
        }
        logger.warn("Retry {}/{}: fail to dump data for file {}.", i, dbCommandRetry, fileName);
        Thread.sleep(10000);
        i++;
    }
}

From source file:org.apache.metron.rest.service.impl.PcapToPdmlScriptWrapper.java

public InputStream execute(String scriptPath, FileSystem fileSystem, Path pcapPath) throws IOException {
    ProcessBuilder processBuilder = getProcessBuilder(scriptPath, pcapPath.toUri().getPath());
    Process process = processBuilder.start();
    InputStream rawInputStream = getRawInputStream(fileSystem, pcapPath);
    OutputStream processOutputStream = process.getOutputStream();
    IOUtils.copy(rawInputStream, processOutputStream);
    rawInputStream.close();//from   w  ww .  ja va 2  s  . c  o m
    if (process.isAlive()) {
        // need to close processOutputStream if script doesn't exit with an error
        processOutputStream.close();
        return process.getInputStream();
    } else {
        String errorMessage = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8);
        throw new IOException(errorMessage);
    }
}

From source file:org.eclipse.flux.client.java.AbstractFluxClientTest.java

@Override
protected void tearDown() throws Exception {
    try {//from  w  w w.j a v a 2 s  . c o m
        super.tearDown();

        //ensure all processes are terminated.
        synchronized (processes) {
            for (Process<?> process : processes) {
                assertTrue("Process not started", process.hasRun);
                assertFalse("Poorly behaved tests, left a processes running", process.isAlive());
            }
        }
    } finally {
        //Make sure this gets executed no matter what or there will be Thread leakage!
        if (timer != null) {
            timer.cancel();
        }
    }
}