本文整理汇总了Java中org.zeroturnaround.process.PidProcess类的典型用法代码示例。如果您正苦于以下问题:Java PidProcess类的具体用法?Java PidProcess怎么用?Java PidProcess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PidProcess类属于org.zeroturnaround.process包,在下文中一共展示了PidProcess类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: controlAppiumServer
import org.zeroturnaround.process.PidProcess; //导入依赖的package包/类
@Override
public void controlAppiumServer() throws MojoExecutionException {
getLog().info(" ");
getLog().info("-------------------------------------------------------");
getLog().info(" S T O P P I N G A P P I U M S E R V E R");
getLog().info("-------------------------------------------------------");
getLog().info(" ");
try {
int appiumProcessPID = Integer.parseInt(readFileToString(new File(projectBuildDirectory, APPIUM_PID), UTF_8));
PidProcess appiumProcess = Processes.newPidProcess(appiumProcessPID);
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
WindowsProcess appiumWindowsProcess = (WindowsProcess) appiumProcess;
appiumWindowsProcess.setIncludeChildren(true);
appiumProcess = appiumWindowsProcess;
}
if (!appiumProcess.isAlive()) {
throw new MojoExecutionException("Could not find a process running on " + appiumProcessPID);
}
ProcessUtil.destroyGracefullyOrForcefullyAndWait(appiumProcess, shutdownTimeout, TimeUnit.SECONDS, forceShutdownTimeout, TimeUnit.SECONDS);
if (appiumProcess.isAlive()) {
throw new MojoExecutionException("Unable to stop Appium server...");
}
} catch (InterruptedException | TimeoutException | IOException ex) {
throw new MojoExecutionException("Unable to stop Appium server...", ex);
}
}
示例2: endProcess
import org.zeroturnaround.process.PidProcess; //导入依赖的package包/类
private void endProcess() {
if (processEnded.compareAndSet(false, true)) {
runningInstances.decrementAndGet();
lock.getExpired().set(true);
final Process proc = process.get();
if (proc != null) {
while (proc.isAlive()) {
try {
PidProcess pidProcess = Processes.newPidProcess(proc);
try {
if (!pidProcess.destroyGracefully().waitFor(10, TimeUnit.SECONDS)) {
throw new RuntimeException();
}
} catch (Throwable t1) {
if (!pidProcess.destroyForcefully().waitFor(10, TimeUnit.SECONDS)) {
throw new RuntimeException();
}
}
} catch (Throwable t2) {
try {
proc.destroyForcibly().waitFor(10, TimeUnit.SECONDS);
} catch (Throwable t3) {}
}
}
}
try {
heartbeatThread.interrupt();
heartbeatThread.join();
} catch (Exception e) {}
synchronized (locks) {
locks.remove(lock);
}
}
}
示例3: controlAppiumServer
import org.zeroturnaround.process.PidProcess; //导入依赖的package包/类
@Override
public void controlAppiumServer() throws MojoExecutionException {
getLog().info(" ");
getLog().info("-------------------------------------------------------");
getLog().info(" S T A R T I N G A P P I U M S E R V E R");
getLog().info("-------------------------------------------------------");
getLog().info(" ");
getLog().debug("Using Node location: " + nodeDefaultLocation);
getLog().debug("Using Appium location: " + appiumLocation);
String nodeBinaryName = Os.isFamily(Os.FAMILY_WINDOWS) ? NODE_EXECUTABLE_WINDOWS : NODE_EXECUTABLE_NIX;
File nodeExecutable = new File(nodeDefaultLocation, nodeBinaryName);
checkFileExists(nodeExecutable);
checkFileExists(appiumLocation);
ArrayList<String> appiumCommandLineArguments = new ArrayList<>();
appiumCommandLineArguments.add(nodeExecutable.getAbsolutePath());
appiumCommandLineArguments.add(appiumLocation.getAbsolutePath());
appiumCommandLineArguments.add(ADDRESS.getCommandLineArgument());
appiumCommandLineArguments.add(appiumIpAddress);
appiumCommandLineArguments.add(PORT.getCommandLineArgument());
appiumCommandLineArguments.add(appiumPort);
appiumCommandLineArguments.add(SHOW_LOG_TIMESTAMPS.getCommandLineArgument());
appiumCommandLineArguments.add(LOG_TO_FILE.getCommandLineArgument());
appiumCommandLineArguments.add(new File(projectBuildDirectory, "appium.log").getAbsolutePath());
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(appiumCommandLineArguments);
processBuilder.redirectError(new File(projectBuildDirectory, "appiumServerErrors.log"));
processBuilder.redirectOutput(new File(projectBuildDirectory, "appiumServerOutput.log"));
try {
PidProcess appiumProcess = Processes.newPidProcess(processBuilder.start());
if (!appiumProcess.isAlive()) {
throw new MojoExecutionException("Unable to start Appium server!");
}
String processPID = Integer.toString(appiumProcess.getPid());
FileUtils.writeStringToFile(new File(projectBuildDirectory, APPIUM_PID), processPID, UTF_8);
waitForAppiumToStart(appiumStartupTicks, appiumIpAddress, appiumPort);
} catch (IOException | InterruptedException ex) {
throw new MojoExecutionException("Unable to start Appium server!", ex);
}
}