long now = System.currentTimeMillis();
for (Computer c: Jenkins.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);
}
}
}
}