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();
}
}
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;
}
Aggregations