Search in sources :

Example 1 with ComputerListener

use of hudson.slaves.ComputerListener in project hudson-2.x by hudson.

the class Hudson method updateComputerList.

/**
     * Updates {@link #computers} by using {@link #getSlaves()}.
     *
     * <p>
     * This method tries to reuse existing {@link Computer} objects
     * so that we won't upset {@link Executor}s running in it.
     */
private void updateComputerList() throws IOException {
    synchronized (updateComputerLock) {
        // just so that we don't have two code updating computer list at the same time
        Map<String, Computer> byName = new HashMap<String, Computer>();
        for (Computer c : computers.values()) {
            if (c.getNode() == null) {
                // this computer is gone
                continue;
            }
            byName.put(c.getNode().getNodeName(), c);
        }
        Set<Computer> old = new HashSet<Computer>(computers.values());
        Set<Computer> used = new HashSet<Computer>();
        updateComputer(this, byName, used);
        for (Node s : getNodes()) {
            updateComputer(s, byName, used);
        }
        // find out what computers are removed, and kill off all executors.
        // when all executors exit, it will be removed from the computers map.
        // so don't remove too quickly
        old.removeAll(used);
        for (Computer c : old) {
            c.kill();
        }
    }
    getQueue().scheduleMaintenance();
    for (ComputerListener cl : ComputerListener.all()) {
        cl.onConfigurationChange();
    }
}
Also used : ComputerListener(hudson.slaves.ComputerListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with ComputerListener

use of hudson.slaves.ComputerListener in project hudson-2.x by hudson.

the class HudsonTestCase method createOnlineSlave.

/**
     * Create a new slave on the local host and wait for it to come online
     * before returning
     */
public DumbSlave createOnlineSlave(Label l, EnvVars env) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    ComputerListener waiter = new ComputerListener() {

        @Override
        public void onOnline(Computer C, TaskListener t) {
            latch.countDown();
            unregister();
        }
    };
    waiter.register();
    DumbSlave s = createSlave(l, env);
    latch.await();
    return s;
}
Also used : ComputerListener(hudson.slaves.ComputerListener) StreamTaskListener(hudson.util.StreamTaskListener) CountDownLatch(java.util.concurrent.CountDownLatch) DumbSlave(hudson.slaves.DumbSlave)

Aggregations

ComputerListener (hudson.slaves.ComputerListener)2 DumbSlave (hudson.slaves.DumbSlave)1 StreamTaskListener (hudson.util.StreamTaskListener)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1