當前位置: 首頁>>代碼示例>>Java>>正文


Java ExecuteWatchdog.killedProcess方法代碼示例

本文整理匯總了Java中org.apache.commons.exec.ExecuteWatchdog.killedProcess方法的典型用法代碼示例。如果您正苦於以下問題:Java ExecuteWatchdog.killedProcess方法的具體用法?Java ExecuteWatchdog.killedProcess怎麽用?Java ExecuteWatchdog.killedProcess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.exec.ExecuteWatchdog的用法示例。


在下文中一共展示了ExecuteWatchdog.killedProcess方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: call

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
@Override
public Long call() throws Exception {
    Executor executor = new DefaultExecutor();
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    ExecuteWatchdog watchDog = new ExecuteWatchdog(watchdogTimeout);
    executor.setWatchdog(watchDog);
    executor.setStreamHandler(new PumpStreamHandler(new MyLogOutputStream(handler, true), new MyLogOutputStream(handler, false)));
    Long exitValue;
    try {
        exitValue = new Long(executor.execute(commandline));
    } catch (ExecuteException e) {
        exitValue = new Long(e.getExitValue());
    }
    if (watchDog.killedProcess()) {
        exitValue = WATCHDOG_EXIST_VALUE;
    }
    return exitValue;
}
 
開發者ID:polygOnetic,項目名稱:guetzliconverter,代碼行數:19,代碼來源:ProcessExecutor.java

示例2: compile

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
public void compile(String cwd, Submission submission) throws RuntimeException {
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    ExecuteWatchdog watchdog = new ExecuteWatchdog(watchdogTimeout);

    DefaultExecutor executor = new DefaultExecutor();
    executor.setWorkingDirectory(new File(cwd));
    executor.setStreamHandler(new PumpStreamHandler(null, stderr, null));
    executor.setWatchdog(watchdog);

    CommandLine cmd = new CommandLine(javac);
    cmd.addArgument("-J-Duser.language=en");  // force using English
    cmd.addArgument("-classpath");
    cmd.addArgument(cwd);
    cmd.addArgument(fileName + ".java");
    logger.info("Compiler cmd:\t" + cmd.toString());

    try {
        executor.execute(cmd);
        logger.info("Compile OK");
    } catch (IOException e) {
        if (watchdog.killedProcess()) {
            submission.setStatus(Submission.STATUS_CE);
            submission.setError("Compile Time Exceeded");
            logger.warn("Compile Time Exceeded:\t" + e.getMessage());
        } else {
            submission.setStatus(Submission.STATUS_CE);
            submission.setError("Compile error");
            logger.warn("Compile error:\t" + e.getMessage());
        }
        logger.warn(stderr.toString());
        throw new RuntimeException("Compile Aborted.");
    }
}
 
開發者ID:justice-oj,項目名稱:dispatcher,代碼行數:34,代碼來源:JavaWorker.java

示例3: execute

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
/**
 * Executes the given command synchronously.
 *
 * @param command The command to execute.
 * @param processInput Input provided to the process.
 * @return The result of the execution, or empty if the process does not terminate within the timeout set for this executor.
 * @throws IOException if the process execution failed.
 */
public Optional<ProcessResult> execute(String command, String processInput) throws IOException {
    ByteArrayOutputStream processErr = new ByteArrayOutputStream();
    ByteArrayOutputStream processOut = new ByteArrayOutputStream();

    DefaultExecutor executor = new DefaultExecutor();
    executor.setStreamHandler(createStreamHandler(processOut, processErr, processInput));
    ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.SECONDS.toMillis(timeoutSeconds));
    executor.setWatchdog(watchDog);
    executor.setExitValues(successExitCodes);

    int exitCode;
    try {
        exitCode = executor.execute(CommandLine.parse(command));
    } catch (ExecuteException e) {
        exitCode = e.getExitValue();
    }
    return (watchDog.killedProcess()) ?
            Optional.empty() : Optional.of(new ProcessResult(exitCode, processOut.toString(), processErr.toString()));
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:28,代碼來源:ProcessExecutor.java

示例4: onTranscodeProcessFailed

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
@Override
public void onTranscodeProcessFailed(ExecuteException e, ExecuteWatchdog watchdog, long timestamp) {
	// TODO Auto-generated method stub
	String cause = null;
	
	if(watchdog != null && watchdog.killedProcess()) cause = FAILURE_BY_TIMEOUT;
	else cause = GENERIC_FAILURE;
	
	if(timestamp - this.resultHandler.getAbortRequestTimestamp()>ABORT_TIMEOUT)
	{
		logger.warn("onTranscodeProcessFailed cause: " + cause);
		notifyObservers(SessionEvent.FAILED, new TranscoderExecutionError(e, cause, timestamp));
	}
	else
	{
		logger.warn("Probable force abort");
		doCleanUp();
	}
}
 
開發者ID:rajdeeprath,項目名稱:poor-man-transcoder,代碼行數:20,代碼來源:Session.java

示例5: main

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    DockerClient dc = new DockerClient();
    String v = dc.getVersion();
    LOG.info(v);

    ExecuteWatchdog dog = dc.tailServiceLogs("msc_siteservice");
    dc.delay(3000);
    dog.killedProcess();
    System.exit(0);
}
 
開發者ID:tascape,項目名稱:reactor,代碼行數:11,代碼來源:DockerClient.java

示例6: run

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
public void run(String cwd, Problem problem, List<TestCase> testCases, Submission submission) throws RuntimeException {
    CommandLine cmd = new CommandLine(java);
    cmd.addArgument("-Djava.security.manager");
    cmd.addArgument("-Djava.security.policy==" + policyFile);
    cmd.addArgument("-Xmx" + problem.getMemoryLimit() + "m");
    cmd.addArgument("-classpath");
    cmd.addArgument(cwd);
    cmd.addArgument(fileName);
    logger.info("Sandbox cmd:\t" + cmd.toString());

    long cost = 0;
    for (TestCase testCase : testCases) {
        ByteArrayInputStream stdin = new ByteArrayInputStream(testCase.getInput().getBytes());
        ByteArrayOutputStream stdout = new ByteArrayOutputStream(), stderr = new ByteArrayOutputStream();
        ExecuteWatchdog watchdog = new ExecuteWatchdog(problem.getRuntimeLimit());

        DefaultExecutor executor = new DefaultExecutor();
        executor.setWorkingDirectory(new File(cwd));
        executor.setStreamHandler(new PumpStreamHandler(stdout, stderr, stdin));
        executor.setWatchdog(watchdog);

        long startTime = System.nanoTime();
        try {
            executor.execute(cmd);
        } catch (IOException e) {
            if (watchdog.killedProcess()) {
                submission.setStatus(Submission.STATUS_TLE);
                submission.setError("Time Limit Exceeded");
            } else {
                submission.setStatus(Submission.STATUS_RE);
                submission.setError(stderr.toString());
            }
            logger.warn("Runtime error:\t" + e.toString());
            throw new RuntimeException("Execution Aborted.");
        }
        cost += System.nanoTime() - startTime;

        String o = stdout.toString().trim();
        if (!o.equals(testCase.getOutput())) {
            submission.setStatus(Submission.STATUS_WA);
            submission.setInput(testCase.getInput());
            submission.setOutput(o.length() > outputMaxLength ? o.substring(0, outputMaxLength) + "..." : o);
            submission.setExpected(testCase.getOutput());
            logger.warn("Input: " + testCase.getInput());
            logger.warn("Output: " + o.substring(0, Math.min(outputMaxLength, o.length())));
            logger.warn("Expected: " + testCase.getOutput());
            throw new RuntimeException("Wrong Answer.");
        }
    }

    submission.setRuntime(cost / 1000000);
    submission.setMemory(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / (1024 * 1024));
    submission.setStatus(Submission.STATUS_AC);
}
 
開發者ID:justice-oj,項目名稱:dispatcher,代碼行數:55,代碼來源:JavaWorker.java

示例7: launchNewProcess

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
public int launchNewProcess(File baseDir, String cmdString,
		int timeout) throws IOException, ProcessTimeoutException {

	DefaultExecutor executor = new DefaultExecutor();
	ExecuteWatchdog timeoutWatchdog = new ExecuteWatchdog(timeout);
	executor.setWatchdog(timeoutWatchdog);

	PumpStreamHandler streamHandler =new PumpStreamHandler(this.outAndErr, this.outAndErr, this.input);
	executor.setStreamHandler(streamHandler);
	if (baseDir!=null) {
		executor.setWorkingDirectory(baseDir);
	}

	int exitValue;
	try {
		logger.debug("About to execute command " + cmdString);
		exitValue = executor.execute(CommandLine.parse(cmdString));
		if (executor.isFailure(exitValue)
				&& timeoutWatchdog.killedProcess()) {
			// it was killed on purpose by the watchdog
			logger.debug("A timeout occured while executing a process");
			logger.debug("The command is " + cmdString);
			throw new ProcessTimeoutException(
					"A timeout occurred while executing command "
							+ cmdString);
		}

		return exitValue;
	} catch (ExecuteException e) {
		if (timeoutWatchdog.killedProcess()) {
			logger.debug("A timeout occured while executing a process");
			logger.debug("The command is " + cmdString);
			throw new ProcessTimeoutException(
					"A timeout occurred while executing command "
							+ cmdString);
		} else {
			throw e;
		}

	}

}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:43,代碼來源:ProcessLauncher.java

示例8: runPerformanceBenchmark

import org.apache.commons.exec.ExecuteWatchdog; //導入方法依賴的package包/類
public static int runPerformanceBenchmark(final BenchmarkConfig bc, final ExecutionConfig ec)
		throws IOException, InterruptedException {
	final Joiner joiner = Joiner.on(", ");
	System.out.println("Running benchmark.");
	System.out.println("Workload: " + bc.getConfigBase().getWorkload());
	System.out.println("Tool: " + bc.getToolName());
	System.out.println("Model: " + bc.getConfigBase().getModelPath());
	System.out.println("Description: " + bc.getDescription());
	System.out.println("Operations: [" + joiner.join(bc.getConfigBase().getOperations()) + "]");
	System.out.println("Execution configuration: " + ec);
	System.out.println("Runs: " + bc.getConfigBase().getRuns());

	final File configFile = File.createTempFile("trainbenchmark-benchmark-", ".conf");
	final String configPath = configFile.getAbsolutePath();
	bc.saveToFile(configPath);

	final String projectName = String.format("trainbenchmark-tool-%s", bc.getProjectName());
	final String jarPath = String.format("../%s/build/libs/%s-1.0.0-SNAPSHOT-fat.jar %s", projectName, projectName,
			configPath);

	final String javaCommand = String.format("java -Xms%s -Xmx%s -server -jar %s %s", ec.getXms(), ec.getXmx(),
			jarPath, configPath);
	final CommandLine cmdLine = CommandLine.parse(javaCommand);

	final long timeoutInSeconds = bc.getConfigBase().getTimeout();
	final long timeoutInMilliseconds = timeoutInSeconds * 1000;
	final ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutInMilliseconds);
	final Executor executor = new DefaultExecutor();
	executor.setWatchdog(watchdog);
	executor.setStreamHandler(new PumpStreamHandler());
	try {
		final int exitValue = executor.execute(cmdLine);
		System.out.println();
		return exitValue;
	} catch (final ExecuteException e) {
		if (watchdog.killedProcess()) {
			System.out.println("Process timed out.");
		} else {
			e.printStackTrace(System.out);
		}
		return e.getExitValue();
	}
}
 
開發者ID:FTSRG,項目名稱:trainbenchmark,代碼行數:44,代碼來源:BenchmarkRunner.java


注:本文中的org.apache.commons.exec.ExecuteWatchdog.killedProcess方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。