All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.danielflower.apprunner.runners.Killer Maven / Gradle / Ivy

Go to download

A self-hosted platform-as-a-service that hosts web apps written in Java, Clojure, NodeJS, Python, golang and Scala.

There is a newer version: 2.4.6
Show newest version
package com.danielflower.apprunner.runners;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.ExecuteWatchdog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class Killer extends ExecuteWatchdog {
    private static final Logger log = LoggerFactory.getLogger(Killer.class);
    private final CommandLine command;
    private Process process;

    public Killer(long timeout, CommandLine command) {
        super(timeout);
        this.command = command;
    }

    @Override
    public synchronized void start(Process processToMonitor) {
        this.process = processToMonitor;
        super.start(processToMonitor);
    }

    @Override
    public synchronized void destroyProcess() {
        long start = System.currentTimeMillis();
        log.info("Killing " + command);
        process.destroyForcibly();
        super.destroyProcess();
        try {
            boolean stopped = process.waitFor(5, TimeUnit.SECONDS);
            if (stopped) {
                log.info("Killed in " + ((System.currentTimeMillis() - start) + "ms"));
            } else {
                log.warn("Could not kill " + command);
            }
        } catch (InterruptedException e) {
            log.info("Interrupted while waiting to kill " + command);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy