|
|
|
@ -84,8 +84,9 @@ public class ClientDownloadUDP implements Runnable {
|
|
|
|
|
purgeList();
|
|
|
|
|
initThreads();
|
|
|
|
|
while(!stop) {
|
|
|
|
|
checkTasksStatus();
|
|
|
|
|
assignTasks();
|
|
|
|
|
checkTasksStatus();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.err.println("Reassembling file parts.");
|
|
|
|
@ -101,7 +102,7 @@ public class ClientDownloadUDP implements Runnable {
|
|
|
|
|
*/
|
|
|
|
|
private void initThreads() {
|
|
|
|
|
for(HostItem hostItem: hostList) {
|
|
|
|
|
sockList.add(new ClientDownloadPartUDP(filename, hostItem.getUDPSocket(), partsSubdir));
|
|
|
|
|
sockList.add(new ClientDownloadPartUDP(this, filename, hostItem.getUDPSocket(), partsSubdir));
|
|
|
|
|
}
|
|
|
|
|
for(ClientDownloadPartUDP c: sockList) {
|
|
|
|
|
Thread t = new Thread(c);
|
|
|
|
@ -114,6 +115,9 @@ public class ClientDownloadUDP implements Runnable {
|
|
|
|
|
* @throws InternalError
|
|
|
|
|
*/
|
|
|
|
|
private void checkTasksStatus() throws InternalError {
|
|
|
|
|
try {
|
|
|
|
|
synchronized(this) {
|
|
|
|
|
this.wait();
|
|
|
|
|
List<ClientDownloadPartUDP> sockListCpy = new ArrayList<>(sockList);
|
|
|
|
|
for(ClientDownloadPartUDP c: sockListCpy) {
|
|
|
|
|
if (c.hasFailed() == true) {
|
|
|
|
@ -136,6 +140,10 @@ public class ClientDownloadUDP implements Runnable {
|
|
|
|
|
throw new InternalError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new InternalError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Assign tasks randomly to threads.
|
|
|
|
|
* @throws InternalError
|
|
|
|
|