int uid = Misc.nextInt();
Dispatcher.getDispatcher().registerUid(uid);
VeryLongInteger checkHash = null;
try {
checkHash = Dispatcher.getDispatcher().retrieveHash(
new BlockInfo(_url, _length, _lastModified, blockNo), 10, uid, false);
} catch (Exception e) {
Logger.warning("Failed to retrieve hash " + e.getMessage());
}
Dispatcher.getDispatcher().unregisterUid(uid);
if (checkHash != null) {
_retrievedHashes.put(new Integer(blockNo), checkHash);
}
Logger.info("Done with retrieval of hash " + blockNo);
} else {
PartiallyReceivedBlock block;
BlockInfo bi;
synchronized (this) {
blockNo = _nextBlockToDownload++;
bi = new BlockInfo(_url, _length, _lastModified, blockNo);
block = new PartiallyReceivedBlock(Dijjer.PACKETS_IN_BLOCK, Dijjer.PACKET_SIZE);
_pending.addLast(new BlockPair(bi, block));
this.notify();
}
try {
// If the remote transfer fails we don't want the transfer to the client to be aborted, rather
// we want to rerequest with TTL of 0, so we tell the PartiallyRetrievedBlock to ignore any
// abort
block.setIgnoreAbort(true);
if (Dispatcher.getDispatcher().retrieveData(bi, 15, block, this)) {
_fromCacheCount++;
}
block.setIgnoreAbort(false);
} catch (Exception e) {
Logger.warning("Error during download of block " + blockNo + ": " + e.getMessage());
try {
Logger.info("Retrying block " + blockNo + " with TTL of 0");
Dispatcher.getDispatcher().retrieveData(new BlockInfo(_url, _length, _lastModified, blockNo), 0,
block, this);
} catch (Exception e1) {
Logger.error("Error during direct download of block " + blockNo + ", aborting", e1);
this.abort();
}