use of hudson.Proc in project hudson-2.x by hudson.
the class WindowsRemoteLauncher method launch.
public Proc launch(ProcStarter ps) throws IOException {
maskedPrintCommandLine(ps.cmds(), ps.masks(), ps.pwd());
// TODO: environment variable handling
String name = ps.cmds().toString();
final Process proc;
try {
proc = launcher.launch(buildCommandLine(ps), ps.pwd().getRemote());
} catch (JIException e) {
throw new IOException2(e);
} catch (InterruptedException e) {
throw new IOException2(e);
}
final Thread t1 = new StreamCopyThread("stdout copier: " + name, proc.getInputStream(), ps.stdout(), false);
t1.start();
final Thread t2 = new StreamCopyThread("stdin copier: " + name, ps.stdin(), proc.getOutputStream(), true);
t2.start();
return new Proc() {
public boolean isAlive() throws IOException, InterruptedException {
try {
proc.exitValue();
return false;
} catch (IllegalThreadStateException e) {
return true;
}
}
public void kill() throws IOException, InterruptedException {
t1.interrupt();
t2.interrupt();
proc.destroy();
}
public int join() throws IOException, InterruptedException {
try {
t1.join();
t2.join();
return proc.waitFor();
} finally {
proc.destroy();
}
}
};
}
use of hudson.Proc in project hudson-2.x by hudson.
the class Channels method newJVM.
/**
* Launches a new JVM with the given classpath, establish a communication channel,
* and return a {@link Channel} to it.
*
* @param displayName
* Human readable name of what this JVM represents. For example "Selenium grid" or "Hadoop".
* This token is used for messages to {@code listener}.
* @param listener
* The progress of the launcher and the failure information will be sent here. Must not be null.
* @param workDir
* If non-null, the new JVM will have this directory as the working directory. This must be a local path.
* @param classpath
* The classpath of the new JVM. Can be null if you just need {@code slave.jar} (and everything else
* can be sent over the channel.) But if you have jars that are known to be necessary by the new JVM,
* setting it here will improve the classloading performance (by avoiding remote class file transfer.)
* Classes in this classpath will also take precedence over any other classes that's sent via the channel
* later, so it's also useful for making sure you get the version of the classes you want.
* @param vmb
* A partially configured {@link JVMBuilder} that allows the caller to fine-tune the launch parameter.
*
* @return
* never null
* @since 1.361
*/
public static Channel newJVM(String displayName, TaskListener listener, JVMBuilder vmb, FilePath workDir, ClasspathBuilder classpath) throws IOException {
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress("localhost", 0));
serverSocket.setSoTimeout(10 * 1000);
// use -cp + FQCN instead of -jar since remoting.jar can be rebundled (like in the case of the swarm plugin.)
vmb.classpath().addJarOf(Channel.class);
vmb.mainClass(Launcher.class);
if (classpath != null)
vmb.args().add("-cp").add(classpath);
vmb.args().add("-connectTo", "localhost:" + serverSocket.getLocalPort());
listener.getLogger().println("Starting " + displayName);
Proc p = vmb.launch(new LocalLauncher(listener)).stdout(listener).pwd(workDir).start();
Socket s = serverSocket.accept();
serverSocket.close();
return forProcess("Channel to " + displayName, Computer.threadPoolForRemoting, new BufferedInputStream(new SocketInputStream(s)), new BufferedOutputStream(new SocketOutputStream(s)), null, p);
}
Aggregations