use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.
the class ConnectionActivityMonitor method execute.
protected void execute(TaskListener listener) throws IOException, InterruptedException {
if (!enabled)
return;
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);
}
}
}
}
use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.
the class SU method execute.
/**
* Starts a new priviledge-escalated environment, execute a closure, and shut it down.
*/
public static <V, T extends Throwable> V execute(TaskListener listener, String rootUsername, String rootPassword, final Callable<V, T> closure) throws T, IOException, InterruptedException {
VirtualChannel ch = start(listener, rootUsername, rootPassword);
try {
return ch.call(closure);
} finally {
ch.close();
// give some time for orderly shutdown, but don't block forever.
ch.join(3000);
}
}
use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.
the class Slave method getClockDifference.
public ClockDifference getClockDifference() throws IOException, InterruptedException {
VirtualChannel channel = getChannel();
if (channel == null)
throw new IOException(getNodeName() + " is offline");
long startTime = System.currentTimeMillis();
long slaveTime = channel.call(new GetSystemTime());
long endTime = System.currentTimeMillis();
return new ClockDifference((startTime + endTime) / 2 - slaveTime);
}
use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.
the class Computer method doDumpExportTable.
/**
* Dumps the contents of the export table.
*/
public void doDumpExportTable(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
// this is a debug probe and may expose sensitive information
checkPermission(Hudson.ADMINISTER);
rsp.setContentType("text/plain");
PrintWriter w = new PrintWriter(rsp.getCompressedWriter(req));
VirtualChannel vc = getChannel();
if (vc instanceof Channel) {
w.println("Master to slave");
((Channel) vc).dumpExportTable(w);
// flush here once so that even if the dump from the slave fails, the client gets some useful info
w.flush();
w.println("\n\n\nSlave to master");
w.print(vc.call(new DumpExportTableTask()));
} else {
w.println(Messages.Computer_BadChannel());
}
w.close();
}
use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.
the class FilePath method untarFrom.
/**
* Reads the given InputStream as a tar file and extracts it into this directory.
*
* @param _in
* The stream will be closed by this method after it's fully read.
* @param compression
* The compression method in use.
* @since 1.292
*/
public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException {
try {
final InputStream in = new RemoteInputStream(_in);
act(new FileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException {
readFromTar("input stream", dir, compression.extract(in));
return null;
}
private static final long serialVersionUID = 1L;
});
} finally {
IOUtils.closeQuietly(_in);
}
}
Aggregations