mirror of https://github.com/zlatinb/muwire
track last successful attempt. Only re-attempt hosts if they have ever been successful. Do not serialize hosts considered hopeless
parent
549e8c2d98
commit
1d97374857
|
@ -10,6 +10,7 @@ class Host {
|
|||
private final int clearInterval
|
||||
int failures,successes
|
||||
long lastAttempt
|
||||
long lastSuccessfulAttempt
|
||||
|
||||
public Host(Destination destination, int clearInterval) {
|
||||
this.destination = destination
|
||||
|
@ -20,6 +21,7 @@ class Host {
|
|||
failures = 0
|
||||
successes++
|
||||
lastAttempt = System.currentTimeMillis()
|
||||
lastSuccessfulAttempt = lastAttempt
|
||||
}
|
||||
|
||||
synchronized void onFailure() {
|
||||
|
@ -41,6 +43,12 @@ class Host {
|
|||
}
|
||||
|
||||
synchronized void canTryAgain() {
|
||||
System.currentTimeMillis() - lastAttempt > (clearInterval * 60 * 1000)
|
||||
lastSuccessfulAttempt > 0 &&
|
||||
System.currentTimeMillis() - lastAttempt > (clearInterval * 60 * 1000)
|
||||
}
|
||||
|
||||
synchronized void isHopeless() {
|
||||
isFailed() &&
|
||||
System.currentTimeMillis() - lastSuccessfulAttempt > (clearInterval * 24 * 60 * 1000)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,6 +111,8 @@ class HostCache extends Service {
|
|||
host.successes = Integer.valueOf(String.valueOf(entry.successes))
|
||||
if (entry.lastAttempt != null)
|
||||
host.lastAttempt = entry.lastAttempt
|
||||
if (entry.lastSuccessfulAttempt != null)
|
||||
host.lastSuccessfulAttempt = entry.lastSuccessfulAttempt
|
||||
if (allowHost(host))
|
||||
hosts.put(dest, host)
|
||||
}
|
||||
|
@ -140,12 +142,13 @@ class HostCache extends Service {
|
|||
storage.delete()
|
||||
storage.withPrintWriter { writer ->
|
||||
hosts.each { dest, host ->
|
||||
if (allowHost(host)) {
|
||||
if (allowHost(host) && !host.isHopeless()) {
|
||||
def map = [:]
|
||||
map.destination = dest.toBase64()
|
||||
map.failures = host.failures
|
||||
map.successes = host.successes
|
||||
map.lastAttempt = host.lastAttempt
|
||||
map.lastSuccessfulAttempt = host.lastSuccessfulAttempt
|
||||
def json = JsonOutput.toJson(map)
|
||||
writer.println json
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue