Search in sources :

Example 1 with Proc

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();
            }
        }
    };
}
Also used : Proc(hudson.Proc) StreamCopyThread(hudson.util.StreamCopyThread) JIException(org.jinterop.dcom.common.JIException) IOException2(hudson.util.IOException2) StreamCopyThread(hudson.util.StreamCopyThread)

Example 2 with Proc

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);
}
Also used : Proc(hudson.Proc) LocalLauncher(hudson.Launcher.LocalLauncher) SocketOutputStream(hudson.remoting.SocketOutputStream) BufferedInputStream(java.io.BufferedInputStream) InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) SocketInputStream(hudson.remoting.SocketInputStream) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Aggregations

Proc (hudson.Proc)2 LocalLauncher (hudson.Launcher.LocalLauncher)1 SocketInputStream (hudson.remoting.SocketInputStream)1 SocketOutputStream (hudson.remoting.SocketOutputStream)1 IOException2 (hudson.util.IOException2)1 StreamCopyThread (hudson.util.StreamCopyThread)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 JIException (org.jinterop.dcom.common.JIException)1