-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTTRChecker.java
More file actions
52 lines (40 loc) · 1.1 KB
/
TTRChecker.java
File metadata and controls
52 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*--------- start change ----------*/
/**
* Class which defines a TTR checker thread. It is basically a trigger which
* sleeps until TTR milliseconds. When it wakes up, pulls off a metadata refresh
* in the peer.
*
* @author palvare3
*
*/
public class TTRChecker implements Runnable {
private static int nCounters = 0;
private static final int MAX_COUNTERS = 5;
private Peer peer;
public TTRChecker(Peer p) {
this.peer = p;
}
@Override
public void run() {
// Sets a limit to the counters, so as not to overflow memory
if (nCounters <= MAX_COUNTERS) {
nCounters++;
try {
int ttr = peer.getMinimumTTR();
System.out.println("Calculated TTR: " + ttr);
if (ttr > 0) {
long initialTime = System.currentTimeMillis();
Thread.sleep(ttr);
long finalTime = System.currentTimeMillis();
int waitingTime = (int) (finalTime - initialTime);
System.out.println("Refreshing downloads after "
+ waitingTime);
peer.refreshDownloads(ttr);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/*--------- end change ----------*/