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


Java ExecuteWatchdog類代碼示例

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


ExecuteWatchdog類屬於org.apache.commons.exec包,在下文中一共展示了ExecuteWatchdog類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: testExecutable

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
private static boolean testExecutable() {
    CommandLine commandLine = CommandLine.parse(RCLIProcessor.rExecutable + " " + VERSION_CALL);

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    Executor executor = new DefaultExecutor();

    // put a watchdog with a timeout
    ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(TIMEOUT_SECONDS) * 1000);
    executor.setWatchdog(watchdog);

    try {
        executor.execute(commandLine, resultHandler);
        resultHandler.waitFor();
        int exitVal = resultHandler.getExitValue();
        if (exitVal != 0) {
            return false;
        }
            return true;
    }
    catch (Exception e) {
        return false;
    }
}
 
開發者ID:52North,項目名稱:movingcode,代碼行數:24,代碼來源:RCLIProbe.java

示例3: run

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
public void run() {
	try {
	executor = new DaemonExecutor();
	resultHandler = new DefaultExecuteResultHandler();
	String javaHome = System.getProperty("java.home");
	String userDir = System.getProperty("user.dir");
	
	executor.setStreamHandler(new PumpStreamHandler(System.out));
	watchdog = new ExecuteWatchdog(15000);
	executor.setWatchdog(watchdog);
	executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR 
			+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe").addArgument("-version"));
	executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR 
			+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe")
		.addArgument("-jar")
		.addArgument(userDir + "/../moneta-springboot/target/moneta-springboot-" + ContractTestSuite.getProjectVersion() + ".jar"));
	
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	
}
 
開發者ID:Derek-Ashmore,項目名稱:moneta,代碼行數:24,代碼來源:SpringBootContractTest.java

示例4: testExecutable

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
public static boolean testExecutable() {
	CommandLine commandLine = CommandLine.parse(PythonCLIProcessor.pythonExecutable + " --version");

	DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
	Executor executor = new DefaultExecutor();

	// put a watchdog with a timeout
	ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(timeout_seconds) * 1000);
	executor.setWatchdog(watchdog);

	try {
		executor.execute(commandLine, resultHandler);
		resultHandler.waitFor();
		int exitVal = resultHandler.getExitValue();
		if (exitVal != 0) {
			return false;
		}
		return true;
	}
	catch (Exception e) {
		return false;
	}
}
 
開發者ID:52North,項目名稱:movingcode,代碼行數:24,代碼來源:PythonCLIProbe.java

示例5: triggerThreadDump

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
private void triggerThreadDump() {
    String kill = findBinary("kill");
    
    if (kill != null) {
        for (final Integer pid : getOpenNMSProcesses()) {
            LogUtils.debugf(this, "pid = " + pid);
            CommandLine command = CommandLine.parse(kill + " -3 " + pid.toString());
            try {
                LogUtils.tracef(this, "running '%s'", command.toString());
                DefaultExecutor executor = new DefaultExecutor();
                executor.setWatchdog(new ExecuteWatchdog(5000));
                int exitValue = executor.execute(command);
                LogUtils.tracef(this, "finished '%s'", command.toString());
                if (exitValue != 0) {
                    LogUtils.warnf(this, "'%s' exited non-zero: %d", command.toString(), exitValue);
                }
            } catch (final Exception e) {
                LogUtils.warnf(this, e, "Unable to run kill -3 on '%s': you might need to run system-report as root.", pid.toString());
            }
        }
    }
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:23,代碼來源:ThreadReportPlugin.java

示例6: main

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    String cmd = "/tmp/test.sh";
    CommandLine cmdLine = CommandLine.parse("/bin/bash " + cmd);

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    PumpStreamHandler psh = new PumpStreamHandler(stdout, stderr);

    psh.setStopTimeout(TIMEOUT_FIVE_MINUTES);

    ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT_TEN_MINUTES); // timeout in milliseconds

    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);
    executor.setStreamHandler(psh);
    executor.setWatchdog(watchdog);

    int exitValue = executor.execute(cmdLine, Collections.emptyMap());
    System.out.println(exitValue);
}
 
開發者ID:kinow,項目名稱:commons-sandbox,代碼行數:21,代碼來源:Tests.java

示例7: 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

示例8: execute

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
public int execute(String[] args, @Nullable Path workingDir, Map<String, String> addEnv) throws IOException {
  if (!Files.isExecutable(file)) {
    Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_EXECUTE);
    Files.setPosixFilePermissions(file, perms);
  }

  ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
  CommandLine cmd = new CommandLine(file.toFile());
  cmd.addArguments(args);
  DefaultExecutor exec = new DefaultExecutor();
  exec.setWatchdog(watchdog);
  exec.setStreamHandler(createStreamHandler());
  exec.setExitValues(null);
  if (workingDir != null) {
    exec.setWorkingDirectory(workingDir.toFile());
  }
  in.close();
  LOG.info("Executing: {}", cmd.toString());
  Map<String, String> env = new HashMap<>(System.getenv());
  env.putAll(addEnv);
  return exec.execute(cmd, env);
}
 
開發者ID:SonarSource,項目名稱:sonarlint-cli,代碼行數:25,代碼來源:CommandExecutor.java

示例9: dockerAsync

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
/**
 * Runs docker command asynchronously.
 *
 * @param arguments command line arguments
 * @param out       stdout will be written in to this file
 *
 * @return a handle used to stop the command process
 *
 * @throws IOException when command has error
 */
public ExecuteWatchdog dockerAsync(final List<Object> arguments, OutputStream out) throws IOException {
    CommandLine cmdLine = new CommandLine(DOCKER);
    arguments.forEach((arg) -> {
        cmdLine.addArgument(arg + "");
    });
    LOG.debug("[{} {}]", cmdLine.getExecutable(), StringUtils.join(cmdLine.getArguments(), " "));
    List<String> output = new ArrayList<>();
    ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
    Executor executor = new DefaultExecutor();
    executor.setWatchdog(watchdog);
    PrintWriter writer = new PrintWriter(out);
    ESH esh = new ESH(writer);
    executor.setStreamHandler(esh);
    executor.execute(cmdLine, new DefaultExecuteResultHandler());
    return watchdog;
}
 
開發者ID:tascape,項目名稱:reactor,代碼行數:27,代碼來源:DockerClient.java

示例10: runJar

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
private ExecuteWatchdog runJar(InvocationOutputHandler buildLogHandler, InvocationOutputHandler consoleLogHandler, Map<String, String> envVarsForApp, Waiter startupWaiter) {
    Path libsPath = Paths.get(projectRoot.getPath(), "build", "libs");
    File libsFolder = libsPath.toFile();

    // To simplify implementation, now I assume only 1 uberjar named "artifact-version-all.jar" under libs folder
    // As we clean the project every time, I can't foresee any possibility that will mix up other uberjars.
    File[] files = libsFolder.listFiles();

    if(files == null) {
        throw new ProjectCannotStartException(libsFolder.getPath() + " doesn't exist");
    }

    Optional<File> jar = Stream.of(files).filter((f) -> f.getName().contains("all")).findFirst();

    if (!jar.isPresent() || !jar.get().isFile()) {
        throw new ProjectCannotStartException("Could not find the jar file at " + jar.get().getPath());
    }

    CommandLine command = javaHomeProvider.commandLine(envVarsForApp)
        .addArgument("-Djava.io.tmpdir=" + envVarsForApp.get("TEMP"))
        .addArgument("-jar")
        .addArgument(fullPath(jar.get()));

    return ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
}
 
開發者ID:danielflower,項目名稱:app-runner,代碼行數:26,代碼來源:GradleRunner.java

示例11: runCancelJob

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
private void runCancelJob(Master.Job message) {
    if (getAbortStatus(message.abortUrl, message.trackingId)) {
        CommandLine cmdLine = new CommandLine("/bin/bash");
        cmdLine.addArgument(agentConfig.getJob().getJobArtifact("cancel"));
        cmdLine.addArgument(message.jobId);
        DefaultExecutor killExecutor = new DefaultExecutor();
        ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
        killExecutor.setWatchdog(watchdog);
        try {
            log.info("Cancel command: {}", cmdLine);
            killExecutor.execute(cmdLine);
            TaskEvent taskEvent = (TaskEvent) message.taskEvent;
            String outPath = agentConfig.getJob().getOutPath(taskEvent.getJobName(), message.jobId);
            String errPath = agentConfig.getJob().getErrorPath(taskEvent.getJobName(), message.jobId);
            Worker.Result result = new Worker.Result(-9, agentConfig.getUrl(errPath), agentConfig.getUrl(outPath), null, message);
            getSender().tell(new Worker.WorkFailed(result), getSelf());
        } catch (IOException e) {
            log.error(e, "Error cancelling job");
        }
    }
}
 
開發者ID:Abiy,項目名稱:distGatling,代碼行數:22,代碼來源:JarExecutor.java

示例12: runCancelJob

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
private void runCancelJob(Master.Job message) {
    if (getAbortStatus(message.abortUrl, message.trackingId)) {
        CommandLine cmdLine = new CommandLine("/bin/bash");
        cmdLine.addArgument(agentConfig.getJob().getJobArtifact("cancel"));
        cmdLine.addArgument(message.jobId);
        DefaultExecutor killExecutor = new DefaultExecutor();
        ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
        killExecutor.setWatchdog(watchdog);
        try {
            log.info("Cancel command: {}", cmdLine);
            killExecutor.execute(cmdLine);
        } catch (IOException e) {
            log.error(e, "Error cancelling job");
        }
    }
}
 
開發者ID:Abiy,項目名稱:distGatling,代碼行數:17,代碼來源:ScriptExecutor.java

示例13: 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

示例14: setUpBeforeClass

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	System.out.println("Java Temp Dir: " +System.getProperty("java.io.tmpdir"));
	
	executor = new DefaultExecutor();
	resultHandler = new DefaultExecuteResultHandler();
	String javaHome = System.getProperty("java.home");
	String userDir = System.getProperty("user.dir");
	
	executor.setStreamHandler(new PumpStreamHandler(System.out));
	watchdog = new ExecuteWatchdog(10000);
	executor.setWatchdog(watchdog);
	executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR 
			+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe").addArgument("-version"));
	executor.execute(new CommandLine(javaHome + SystemUtils.FILE_SEPARATOR 
			+ "bin"+ SystemUtils.FILE_SEPARATOR+"java.exe")
		.addArgument("-jar")
		.addArgument(userDir + "/../moneta-dropwizard/target/moneta-dropwizard-" + ContractTestSuite.getProjectVersion() + ".jar")
		.addArgument("server")
		.addArgument("src/main/resources/dropwizard/moneta-dropwizard.yaml"), resultHandler);
	Thread.sleep(3000);
	System.out.println("Test sequence starting....");
}
 
開發者ID:Derek-Ashmore,項目名稱:moneta,代碼行數:24,代碼來源:DropwizardContractTest.java

示例15: checkDot

import org.apache.commons.exec.ExecuteWatchdog; //導入依賴的package包/類
/**
 * Verify if dot can be started and print out the version to stdout.
 *
 * @return True if "dot -V" ran successfully, false otherwise
 *
 * @throws IOException If running dot fails.
 */
public static boolean checkDot() throws IOException {
	// call graphviz-dot via commons-exec
	CommandLine cmdLine = new CommandLine(DOT_EXE);
	cmdLine.addArgument("-V");
	DefaultExecutor executor = new DefaultExecutor();
	executor.setExitValue(0);
	ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
	executor.setWatchdog(watchdog);
	executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
	int exitValue = executor.execute(cmdLine);
	if(exitValue != 0) {
		System.err.println("Could not run '" + DOT_EXE + "', had exit value: " + exitValue + "!");
		return false;
	}

	return true;
}
 
開發者ID:centic9,項目名稱:commons-dost,代碼行數:25,代碼來源:DotUtils.java


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