@Override
public void run() {
boolean failed = false;
File tmp = null;
FileRandomAccessBuffer raf = null;
try {
System.out.println("Fetching "+saveTo+" from "+fetchFrom);
long uid = updateManager.node.fastWeakRandom.nextLong();
fetchFrom.sendAsync(DMT.createUOMFetchDependency(uid, expectedHash, size), null, updateManager.ctr);
tmp = FileUtil.createTempFile(saveTo.getName(), NodeUpdateManager.TEMP_FILE_SUFFIX, saveTo.getParentFile());
raf = new FileRandomAccessBuffer(tmp, size, false);
PartiallyReceivedBulk prb =
new PartiallyReceivedBulk(updateManager.node.getUSM(), size,
Node.PACKET_SIZE, raf, false);
BulkReceiver br = new BulkReceiver(prb, fetchFrom, uid, updateManager.ctr);
failed = !br.receive();
raf.close();
raf = null;
if(!failed) {
// Check the hash.
if(MainJarDependenciesChecker.validFile(tmp, expectedHash, size, executable)) {
if(FileUtil.renameTo(tmp, saveTo)) {