|
|
@ -132,7 +132,7 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sockList.get(rand.nextInt(sockList.size())).assignTask(offset);
|
|
|
|
sockList.get(rand.nextInt(sockList.size())).assignTask(offset);
|
|
|
|
offsetsPending.add(offset);
|
|
|
|
offsetsPending.add(offset);
|
|
|
|
writeLog("Assigned task: #"+ offset, LogLevel.Info);
|
|
|
|
writeLog("Assigned task: #"+ offset, LogLevel.Debug);
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
writeLog(e, LogLevel.Error);
|
|
|
|
writeLog(e, LogLevel.Error);
|
|
|
|
throw new InternalError();
|
|
|
|
throw new InternalError();
|
|
|
@ -180,7 +180,7 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ratioUpdater.put(c.getServer(), c.getReceivedBytesCount());
|
|
|
|
ratioUpdater.put(c.getServer(), c.getReceivedBytesCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeLog("Task check status: " + offsetsToAsk.size() + " to asks, " + offsetsPending.size() + " pending", LogLevel.Info);
|
|
|
|
writeLog("Task check status: " + offsetsToAsk.size() + " to asks, " + offsetsPending.size() + " pending", LogLevel.Debug);
|
|
|
|
if (offsetsToAsk.isEmpty() && offsetsPending.isEmpty()) {
|
|
|
|
if (offsetsToAsk.isEmpty() && offsetsPending.isEmpty()) {
|
|
|
|
stop = true;
|
|
|
|
stop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -380,6 +380,7 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
while(!stop) {
|
|
|
|
while(!stop) {
|
|
|
|
assignTasks();
|
|
|
|
assignTasks();
|
|
|
|
checkTasksStatus();
|
|
|
|
checkTasksStatus();
|
|
|
|
|
|
|
|
printProgression();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeLog("Reassembling file parts.", LogLevel.Info);
|
|
|
|
writeLog("Reassembling file parts.", LogLevel.Info);
|
|
|
|
reassembleFile();
|
|
|
|
reassembleFile();
|
|
|
@ -390,6 +391,26 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Print progression of the download.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void printProgression() {
|
|
|
|
|
|
|
|
long progression = 0;
|
|
|
|
|
|
|
|
for(Long dl: ratioUpdater.values()) {
|
|
|
|
|
|
|
|
progression += dl.longValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
double percent = 100.0*progression/size;
|
|
|
|
|
|
|
|
String bar = "[";
|
|
|
|
|
|
|
|
for(int i=0;i<=100;i+=10) {
|
|
|
|
|
|
|
|
if (i>percent) {
|
|
|
|
|
|
|
|
bar += "-";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
bar += "=";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bar += "]";
|
|
|
|
|
|
|
|
writeLog("[[" + filename + "]] " + bar + " " + String.format("%.2f", percent) + "%", LogLevel.Progression);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Initialize infos about file to download (size, hash512sum, partslist to dl).
|
|
|
|
/** Initialize infos about file to download (size, hash512sum, partslist to dl).
|
|
|
|
* Also download first partfile (to get size).
|
|
|
|
* Also download first partfile (to get size).
|
|
|
|
* @throws InternalError
|
|
|
|
* @throws InternalError
|
|
|
|