Print progress bar less frequently
All checks were successful
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good
All checks were successful
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good
This commit is contained in:
parent
039c3ff2b0
commit
58add14fa9
@ -46,6 +46,7 @@ import tools.ServeErrors;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
/** Class to download file
|
||||
* @author Louis Royer
|
||||
@ -70,6 +71,10 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
||||
protected Logger logger;
|
||||
protected HostItem client;
|
||||
protected HostItem tracker;
|
||||
protected int lastPercentProgress;
|
||||
protected Instant lastTimeProgress;
|
||||
final static int DIFF_TIME_PROGRESS_MILLIS = 2000;
|
||||
final static int DIFF_PERCENT_PROGRESS = 5;
|
||||
|
||||
/** Constructor with parameters: filename, list of hosts, parts subdirectory and dirStorage
|
||||
* @param filename name of file to download
|
||||
@ -89,6 +94,8 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
||||
this.client = client;
|
||||
this.tracker = tracker;
|
||||
this.stop = false;
|
||||
lastPercentProgress = - DIFF_PERCENT_PROGRESS;
|
||||
lastTimeProgress = Instant.now().minusMillis(DIFF_TIME_PROGRESS_MILLIS);
|
||||
}
|
||||
|
||||
/** Success getter.
|
||||
@ -399,6 +406,10 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
||||
progression += dl.longValue();
|
||||
}
|
||||
double percent = 100.0*progression/size;
|
||||
if (percent != 100 && percent < lastPercentProgress + DIFF_PERCENT_PROGRESS
|
||||
&& lastTimeProgress.plusMillis(DIFF_TIME_PROGRESS_MILLIS).isAfter(Instant.now())) {
|
||||
return;
|
||||
}
|
||||
String bar = "[";
|
||||
for(int i=0;i<=100;i+=10) {
|
||||
if (i>percent) {
|
||||
@ -408,7 +419,9 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
||||
}
|
||||
}
|
||||
bar += "]";
|
||||
writeLog("[[" + filename + "]] " + bar + " " + String.format("%.2f", percent) + "%", LogLevel.Progression);
|
||||
writeLog("[[" + filename + "]] " + bar + " " + String.format("%.2f", percent) + "%", LogLevel.Progression);
|
||||
lastPercentProgress = (int)percent;
|
||||
lastTimeProgress = Instant.now();
|
||||
}
|
||||
|
||||
/** Initialize infos about file to download (size, hash512sum, partslist to dl).
|
||||
|
Loading…
Reference in New Issue
Block a user