Author: bombe
Date: 2008-08-20 18:50:33 +0000 (Wed, 20 Aug 2008)
New Revision: 22062
Modified:
trunk/freenet/src/freenet/client/async/USKFetcher.java
Log:
use generics
Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java 2008-08-20
18:41:58 UTC (rev 22061)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java 2008-08-20
18:50:33 UTC (rev 22062)
@@ -71,7 +71,7 @@
private final USK origUSK;
/** Callbacks */
- private final LinkedList callbacks;
+ private final LinkedList<USKFetcherCallback> callbacks;
/** Fetcher context */
final FetchContext ctx;
@@ -175,7 +175,7 @@
}
}
- private final Vector runningAttempts;
+ private final Vector<USKAttempt> runningAttempts;
private long lastFetchedEdition;
private long lastAddedEdition;
@@ -219,9 +219,9 @@
this.origUSK = origUSK;
this.uskManager = manager;
this.minFailures = this.origMinFailures = minFailures;
- runningAttempts = new Vector();
- callbacks = new LinkedList();
- subscribers = new HashSet();
+ runningAttempts = new Vector<USKAttempt>();
+ callbacks = new LinkedList<USKFetcherCallback>();
+ subscribers = new HashSet<USKCallback>();
lastFetchedEdition = -1;
lastAddedEdition = -1;
this.ctx = ctx;
@@ -284,7 +284,7 @@
USKFetcherCallback[] cb;
synchronized(this) {
completed = true;
- cb = (USKFetcherCallback[])
callbacks.toArray(new USKFetcherCallback[callbacks.size()]);
+ cb = callbacks.toArray(new
USKFetcherCallback[callbacks.size()]);
}
for(int i=0;i<cb.length;i++)
cb[i].onFoundEdition(ed, origUSK.copy(ed));
@@ -293,7 +293,7 @@
void onSuccess(USKAttempt att, boolean dontUpdate, ClientSSKBlock
block) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
- LinkedList l = null;
+ LinkedList<USKAttempt> l = null;
final long lastEd = uskManager.lookup(origUSK);
long curLatest;
boolean decode = false;
@@ -308,7 +308,7 @@
long addFrom = Math.max(lastAddedEdition + 1, curLatest
+ 1);
if(logMINOR) Logger.minor(this, "Adding from
"+addFrom+" to "+addTo+" for "+origUSK);
if(addTo >= addFrom) {
- l = new LinkedList();
+ l = new LinkedList<USKAttempt>();
for(long i=addFrom;i<=addTo;i++) {
if(logMINOR) Logger.minor(this, "Adding
checker for edition "+i+" for "+origUSK);
l.add(add(i));
@@ -339,16 +339,16 @@
if(!dontUpdate)
uskManager.update(origUSK, curLatest);
if(l == null) return;
- final LinkedList toSched = l;
+ final LinkedList<USKAttempt> toSched = l;
// If we schedule them here, we don't get icky recursion
problems.
if(!cancelled) {
ctx.executor.execute(new Runnable() {
public void run() {
long last = lastEd;
- for(Iterator
i=toSched.iterator();i.hasNext();) {
+ for(Iterator<USKAttempt>
i=toSched.iterator();i.hasNext();) {
// We may be called recursively
through onSuccess().
// So don't start obsolete
requests.
- USKAttempt a = (USKAttempt)
i.next();
+ USKAttempt a = i.next();
last =
uskManager.lookup(origUSK);
if((last <= a.number) &&
!a.cancelled)
a.schedule();
@@ -377,7 +377,7 @@
USKFetcherCallback[] cb;
synchronized(this) {
completed = true;
- cb = (USKFetcherCallback[]) callbacks.toArray(new
USKFetcherCallback[callbacks.size()]);
+ cb = callbacks.toArray(new
USKFetcherCallback[callbacks.size()]);
}
for(int i=0;i<cb.length;i++)
cb[i].onCancelled();
@@ -392,13 +392,13 @@
}
private void cancelBefore(long curLatest) {
- Vector v = null;
+ Vector<USKAttempt> v = null;
int count = 0;
synchronized(this) {
- for(Iterator i=runningAttempts.iterator();i.hasNext();)
{
- USKAttempt att = (USKAttempt) (i.next());
+ for(Iterator<USKAttempt>
i=runningAttempts.iterator();i.hasNext();) {
+ USKAttempt att = i.next();
if(att.number < curLatest) {
- if(v == null) v = new
Vector(runningAttempts.size()-count);
+ if(v == null) v = new
Vector<USKAttempt>(runningAttempts.size()-count);
v.add(att);
i.remove();
}
@@ -407,7 +407,7 @@
}
if(v != null) {
for(int i=0;i<v.size();i++) {
- USKAttempt att = (USKAttempt) v.get(i);
+ USKAttempt att = v.get(i);
att.cancel();
}
}
@@ -421,7 +421,7 @@
if(cancelled) return null;
if(logMINOR) Logger.minor(this, "Adding USKAttempt for "+i+"
for "+origUSK.getURI());
if(!runningAttempts.isEmpty()) {
- USKAttempt last = (USKAttempt)
runningAttempts.lastElement();
+ USKAttempt last = runningAttempts.lastElement();
if(last.number >= i) {
if(logMINOR) Logger.minor(this, "Returning
because last.number="+i+" for "+origUSK.getURI());
return null;
@@ -469,7 +469,7 @@
long startPoint = Math.max(origUSK.suggestedEdition,
valueAtSchedule);
for(long i=startPoint;i<startPoint+minFailures;i++)
add(i);
- attempts = (USKAttempt[]) runningAttempts.toArray(new
USKAttempt[runningAttempts.size()]);
+ attempts = runningAttempts.toArray(new
USKAttempt[runningAttempts.size()]);
started = true;
}
if(!cancelled) {
@@ -493,7 +493,7 @@
USKAttempt[] attempts;
synchronized(this) {
cancelled = true;
- attempts = (USKAttempt[]) runningAttempts.toArray(new
USKAttempt[runningAttempts.size()]);
+ attempts = runningAttempts.toArray(new
USKAttempt[runningAttempts.size()]);
}
for(int i=0;i<attempts.length;i++)
attempts[i].cancel();
@@ -505,7 +505,7 @@
* an alternative to a refcount. This could be replaced with a
* Bloom filter or whatever, we only need .exists and .count.
*/
- final HashSet subscribers;
+ final HashSet<USKCallback> subscribers;
public void addSubscriber(USKCallback cb) {
synchronized(this) {
@@ -522,7 +522,7 @@
short progressPrio = RequestStarter.MINIMUM_PRIORITY_CLASS;
USKCallback[] callbacks;
synchronized(this) {
- callbacks = (USKCallback[]) subscribers.toArray(new
USKCallback[subscribers.size()]);
+ callbacks = subscribers.toArray(new
USKCallback[subscribers.size()]);
}
if(callbacks.length == 0) {
normalPollPriority = DEFAULT_NORMAL_POLL_PRIORITY;