Package hudson.remoting

Examples of hudson.remoting.Channel


            if(computer==null) {
                error(out, "No such slave: "+nodeName);
                return;
            }

            Channel ch = computer.getChannel();
            if(ch !=null) {
                String c = request.getProperty("Cookie");
                if (c!=null && c.equals(ch.getProperty(COOKIE_NAME))) {
                    // we think we are currently connected, but this request proves that it's from the party
                    // we are supposed to be communicating to. so let the current one get disconnected
                    LOGGER.info("Disconnecting "+nodeName+" as we are reconnected from the current peer");
                    try {
                        computer.disconnect(new ConnectionFromCurrentPeer()).get(15, TimeUnit.SECONDS);
                    } catch (ExecutionException e) {
                        throw new IOException2("Failed to disconnect the current client",e);
                    } catch (TimeoutException e) {
                        throw new IOException2("Failed to disconnect the current client",e);
                    }
                } else {
                    error(out, nodeName + " is already connected to this master. Rejecting this connection.");
                    return;
                }
            }

            out.println(Engine.GREETING_SUCCESS);

            Properties response = new Properties();
            String cookie = generateCookie();
            response.put("Cookie",cookie);
            writeResponseHeaders(out, response);

            ch = jnlpConnect(computer);

            ch.setProperty(COOKIE_NAME, cookie);
        }
View Full Code Here


            final Process proc = pb.start();

            final Thread t2 = new StreamCopyThread(pb.command()+": stderr copier", proc.getErrorStream(), out);
            t2.start();

            return new Channel("locally launched channel on "+ pb.command(),
                Computer.threadPoolForRemoting, proc.getInputStream(), proc.getOutputStream(), out) {

                /**
                 * Kill the process when the channel is severed.
                 */
 
View Full Code Here

            LOGGER.fine("Trying to connect directly via TCP/IP to port "+clip+" of "+host);
            Socket s = new Socket(host,clip);
            DataOutputStream dos = new DataOutputStream(s.getOutputStream());
            dos.writeUTF("Protocol:CLI-connect");

            channel = new Channel("CLI connection to "+hudson, pool,
                    new BufferedInputStream(new SocketInputStream(s)),
                    new BufferedOutputStream(new SocketOutputStream(s)));
        } else {
            // connect via HTTP
            LOGGER.fine("Trying to connect to "+url+" via HTTP");
            url+="cli";
            hudson = new URL(url);

            FullDuplexHttpStream con = new FullDuplexHttpStream(hudson);
            channel = new Channel("Chunked connection to "+hudson,
                    pool,con.getInputStream(),con.getOutputStream());
            new PingThread(channel,30*1000) {
                protected void onDead() {
                    // noop. the point of ping is to keep the connection alive
                    // as most HTTP servers have a rather short read time out
View Full Code Here

    public boolean isRemote() {
        return channel!=null;
    }

    private void writeObject(ObjectOutputStream oos) throws IOException {
        Channel target = Channel.current();

        if(channel!=null && channel!=target)
            throw new IllegalStateException("Can't send a remote FilePath to a different remote channel");

        oos.defaultWriteObject();
View Full Code Here

        oos.defaultWriteObject();
        oos.writeBoolean(channel==null);
    }

    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
        Channel channel = Channel.current();
        assert channel!=null;

        ois.defaultReadObject();
        if(ois.readBoolean()) {
            this.channel = channel;
View Full Code Here

        // wait until we have the other channel
        while(upload==null)
            wait();

        try {
            channel = new Channel("HTTP full-duplex channel " + uuid,
                    Computer.threadPoolForRemoting, Mode.BINARY, upload, out, null, restricted);

            // so that we can detect dead clients, periodically send something
            PingThread ping = new PingThread(channel) {
                @Override
View Full Code Here

            throw new IllegalStateException("Already connected");

        final TaskListener taskListener = new StreamTaskListener(launchLog);
        PrintStream log = taskListener.getLogger();

        Channel channel = new Channel(nodeName,threadPoolForRemoting, Channel.Mode.NEGOTIATE,
            in,out, launchLog);
        channel.addListener(new Channel.Listener() {
            @Override
            public void onClosed(Channel c, IOException cause) {
                SlaveComputer.this.channel = null;
                // Orderly shutdown will have null exception
                if (cause!=null) {
                    offlineCause = new ChannelTermination(cause);
                     cause.printStackTrace(taskListener.error("Connection terminated"));
                } else {
                    taskListener.getLogger().println("Connection terminated");
                }
                launcher.afterDisconnect(SlaveComputer.this, taskListener);
            }
        });
        if(listener!=null)
            channel.addListener(listener);

        String slaveVersion = channel.call(new SlaveVersion());
        log.println("Slave.jar version: " + slaveVersion);

        boolean _isUnix = channel.call(new DetectOS());
        log.println(_isUnix? hudson.model.Messages.Slave_UnixSlave():hudson.model.Messages.Slave_WindowsSlave());

        String defaultCharsetName = channel.call(new DetectDefaultCharset());

        String remoteFs = getNode().getRemoteFS();
        if(_isUnix && !remoteFs.contains("/") && remoteFs.contains("\\"))
            log.println("WARNING: "+remoteFs+" looks suspiciously like Windows path. Maybe you meant "+remoteFs.replace('\\','/')+"?");
        FilePath root = new FilePath(channel,getNode().getRemoteFS());

        channel.call(new SlaveInitializer());
        channel.call(new WindowsSlaveInstaller(remoteFs));
        for (ComputerListener cl : ComputerListener.all())
            cl.preOnline(this,channel,root,taskListener);

        offlineCause = null;

        // update the data structure atomically to prevent others from seeing a channel that's not properly initialized yet
        synchronized(channelLock) {
            if(this.channel!=null) {
                // check again. we used to have this entire method in a big sycnhronization block,
                // but Channel constructor blocks for an external process to do the connection
                // if CommandLauncher is used, and that cannot be interrupted because it blocks at InputStream.
                // so if the process hangs, it hangs the thread in a lock, and since Hudson will try to relaunch,
                // we'll end up queuing the lot of threads in a pseudo deadlock.
                // This implementation prevents that by avoiding a lock. HUDSON-1705 is likely a manifestation of this.
                channel.close();
                throw new IllegalStateException("Already connected");
            }
            isUnix = _isUnix;
            numRetryAttempt = 0;
            this.channel = channel;
View Full Code Here

    /**
     * If still connected, disconnect.
     */
    private void closeChannel() {
        // TODO: race condition between this and the setChannel method.
        Channel c = channel;
        channel = null;
        isUnix = null;
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                logger.log(Level.SEVERE, "Failed to terminate channel to " + getDisplayName(), e);
            }
        }
        for (ComputerListener cl : ComputerListener.all())
View Full Code Here

    public static VirtualChannel getChannelToMaster() {
        if (Hudson.getInstance()!=null)
            return MasterComputer.localChannel;

        // if this method is called from within the slave computation thread, this should work
        Channel c = Channel.current();
        if (c!=null && c.getProperty("slave")==Boolean.TRUE)
            return c;

        return null;
    }
View Full Code Here

        long now = System.currentTimeMillis();
        for (Computer c: Hudson.getInstance().getComputers()) {
            VirtualChannel ch = c.getChannel();
            if (ch instanceof Channel) {
                Channel channel = (Channel) ch;
                if (now-channel.getLastHeard() > TIME_TILL_PING) {
                    // haven't heard from this slave for a while.
                    Long lastPing = (Long)channel.getProperty(ConnectionActivityMonitor.class);

                    if (lastPing!=null && now-lastPing > TIMEOUT) {
                        LOGGER.info("Repeated ping attempts failed on "+c.getName()+". Disconnecting");
                        c.disconnect(OfflineCause.create(Messages._ConnectionActivityMonitor_OfflineCause()));
                    } else {
                        // send a ping. if we receive a reply, it will be reflected in the next getLastHeard() call.
                        channel.callAsync(PING_COMMAND);
                        if (lastPing==null)
                            channel.setProperty(ConnectionActivityMonitor.class,now);
                    }
                } else {
                    // we are receiving data nicely
                    channel.setProperty(ConnectionActivityMonitor.class,null);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of hudson.remoting.Channel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.