private void finishCancelBefore(List<USKAttempt> v, ClientContext context) { if(v != null) { for(int i=0;i<v.size();i++) { USKAttempt att = v.get(i); att.cancel(context); } } }
/** FIXME this is a special case hack * For a generic solution see https://bugs.freenetproject.org/view.php?id=4984 */ public void changeUSKPollParameters(long time, int tries, ClientContext context) { this.ctx.setCooldownRetries(tries); this.ctxNoStore.setCooldownRetries(tries); this.ctx.setCooldownTime(time); this.ctxNoStore.setCooldownTime(time); USKAttempt[] pollers; synchronized(this) { pollers = pollingAttempts.values().toArray(new USKAttempt[pollingAttempts.size()]); } for(USKAttempt a : pollers) a.reloadPollParameters(context); }
private void registerAttempts(ClientContext context) { USKAttempt[] attempts; synchronized(USKFetcher.this) { if(cancelled || completed) return; attempts = attemptsToStart.toArray(new USKAttempt[attemptsToStart.size()]); attemptsToStart.clear(); } if(attempts.length > 0) parent.toNetwork(context); if(logMINOR) Logger.minor(this, "Registering "+attempts.length+" USKChecker's for "+this+" running="+runningAttempts.size()+" polling="+pollingAttempts.size()); for(USKAttempt attempt: attempts) { // Look up on each iteration since scheduling can cause new editions to be found sometimes. long lastEd = uskManager.lookupLatestSlot(origUSK); synchronized(USKFetcher.this) { // FIXME not sure this condition works, test it! if(keepLastData && lastRequestData == null && lastEd == origUSK.suggestedEdition) lastEd--; // If we want the data, then get it for the known edition, so we always get the data, so USKInserter can compare it and return the old edition if it is identical. } if(attempt == null) continue; if(attempt.number > lastEd) attempt.schedule(context); else { synchronized(USKFetcher.this) { runningAttempts.remove(attempt.number); } } } }
attempt.schedule(context); else { synchronized(USKFetcher.this) {
if(!a.everInCooldown()) { if(logMINOR) Logger.minor(this, "Not finished because polling attempt "+a+" never entered cooldown on "+this); return;
/** * Add a USKAttempt for another edition number. * Caller is responsible for calling .schedule(). */ private synchronized USKAttempt add(Lookup l, boolean forever) { long i = l.val; if(l.val < 0) throw new IllegalArgumentException("Can't check <0 for "+l.val+" on "+this+" for "+origUSK); if(cancelled) return null; if(checkStoreOnly) return null; if(logMINOR) Logger.minor(this, "Adding USKAttempt for "+i+" for "+origUSK.getURI()); if(forever) { if(pollingAttempts.containsKey(i)) { if(logMINOR) Logger.minor(this, "Already polling edition: "+i+" for "+this); return null; } } else { if(runningAttempts.containsKey(i)) { if(logMINOR) Logger.minor(this, "Returning because already running for "+origUSK.getURI()); return null; } } USKAttempt a = new USKAttempt(l, forever); if(forever) pollingAttempts.put(i, a); else { runningAttempts.put(i, a); } if(logMINOR) Logger.minor(this, "Added "+a+" for "+origUSK); return a; }
public void cancel(ClientContext context) { cancelled = true; USKChecker c; synchronized(this) { c = checker; } if(c != null) c.cancel(context); onCancelled(context); }