Author: toad
Date: 2008-04-02 16:48:40 +0000 (Wed, 02 Apr 2008)
New Revision: 18919
Modified:
trunk/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
trunk/freenet/src/freenet/node/SendableRequest.java
trunk/freenet/src/freenet/node/SimpleSendableInsert.java
trunk/freenet/src/freenet/support/RandomGrabArray.java
trunk/freenet/src/freenet/support/RandomGrabArrayItem.java
trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
Log:
Split isCancelled() into two methods:
SendableRequest.isCancelled() : has the method been cancelled, or otherwise
finished?
RandomGrabArrayItem.isEmpty() : should the item be removed from the list?
The latter is not the same as the former, in particular not having anything to
send at this moment doesn't mean there is an error.
Modified: trunk/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
2008-04-02 16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
2008-04-02 16:48:40 UTC (rev 18919)
@@ -115,6 +115,10 @@
return cancelled;
}
+ public synchronized boolean isEmpty() {
+ return cancelled;
+ }
+
public Object getClient() {
return parent.getClient();
}
Modified: trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
2008-04-02 16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
2008-04-02 16:48:40 UTC (rev 18919)
@@ -280,10 +280,14 @@
cb.onFailure(new InsertException(InsertException.CANCELLED),
this);
}
+ public synchronized boolean isEmpty() {
+ return finished;
+ }
+
public synchronized boolean isCancelled() {
return finished;
}
-
+
public boolean send(NodeClientCore core, RequestScheduler sched, Object
keyNum) {
// Ignore keyNum, key, since we're only sending one block.
try {
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2008-04-02 16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2008-04-02 16:48:40 UTC (rev 18919)
@@ -314,6 +314,12 @@
return cancelled;
}
}
+
+ public boolean isEmpty() {
+ synchronized(segment) {
+ return cancelled || blockNums.isEmpty();
+ }
+ }
public boolean isSSK() {
// Not allowed in splitfiles
Modified: trunk/freenet/src/freenet/node/SendableRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/SendableRequest.java 2008-04-02 16:38:51 UTC
(rev 18918)
+++ trunk/freenet/src/freenet/node/SendableRequest.java 2008-04-02 16:48:40 UTC
(rev 18919)
@@ -45,6 +45,11 @@
* be removed if it hasn't already been). */
public abstract boolean send(NodeClientCore node, RequestScheduler
sched, Object keyNum);
+ /** If true, the request has been cancelled, or has completed, either
way it need not
+ * be registered any more. isEmpty() on the other hand means there are
no queued blocks.
+ */
+ public abstract boolean isCancelled();
+
/** Get client context object */
public abstract Object getClient();
Modified: trunk/freenet/src/freenet/node/SimpleSendableInsert.java
===================================================================
--- trunk/freenet/src/freenet/node/SimpleSendableInsert.java 2008-04-02
16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/node/SimpleSendableInsert.java 2008-04-02
16:48:40 UTC (rev 18919)
@@ -91,6 +91,10 @@
public boolean isCancelled() {
return finished;
}
+
+ public boolean isEmpty() {
+ return finished;
+ }
public boolean canRemove() {
return true;
Modified: trunk/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/RandomGrabArray.java 2008-04-02
16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/support/RandomGrabArray.java 2008-04-02
16:48:40 UTC (rev 18919)
@@ -31,7 +31,7 @@
public void add(RandomGrabArrayItem req) {
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
- if(req.isCancelled()) {
+ if(req.isEmpty()) {
if(logMINOR) Logger.minor(this, "Is finished already:
"+req);
return;
}
@@ -76,7 +76,7 @@
RandomGrabArrayItem
item = reqs[i];
if(item == null) {
continue;
- } else
if(item.isCancelled()) {
+ } else
if(item.isEmpty()) {
reqs[i] = null;
contents.remove(item);
continue;
@@ -148,7 +148,7 @@
continue;
}
oret = ret;
- if(ret.isCancelled()) {
+ if(ret.isEmpty()) {
if(logMINOR) Logger.minor(this, "Not
returning because cancelled: "+ret);
ret = null;
}
@@ -171,7 +171,7 @@
contents.remove(oret);
oret = reqs[i];
// May as well check whether that is
cancelled too.
- } while (index > i && (oret == null ||
oret.isCancelled()));
+ } while (index > i && (oret == null ||
oret.isEmpty()));
// Shrink array
if((index < reqs.length / 4) && (reqs.length >
MIN_SIZE)) {
// Shrink array
@@ -180,7 +180,7 @@
System.arraycopy(reqs, 0, r, 0,
r.length);
reqs = r;
}
- if((ret != null) && !ret.isCancelled()) break;
+ if((ret != null) && !ret.isEmpty()) break;
}
}
if(logMINOR) Logger.minor(this, "Returning "+ret+" of "+index);
Modified: trunk/freenet/src/freenet/support/RandomGrabArrayItem.java
===================================================================
--- trunk/freenet/src/freenet/support/RandomGrabArrayItem.java 2008-04-02
16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/support/RandomGrabArrayItem.java 2008-04-02
16:48:40 UTC (rev 18919)
@@ -5,9 +5,12 @@
/** If true, will be automatically removed from the RGA, and not
returned.
* True indicates that the item is no longer needed for some reason -
in a request,
* usually that it has either been explicitly cancelled or that it is
not needed
- * because other queued blocks have been sufficient. LOCKING: Should
hold as few
- * locks as possible as this needs to be called while holding the RGA
lock(s). */
- public boolean isCancelled();
+ * because other queued blocks have been sufficient. If it becomes
useful again,
+ * it must be re-registered.
+ *
+ * LOCKING: Should hold as few locks as possible as this needs to be
called while
+ * holding the RGA lock(s). */
+ public boolean isEmpty();
/** Can this item be removed from the queue after it has been handled?
* Called immediately after finding a request to remove.
Modified: trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-04-02 16:38:51 UTC (rev 18918)
+++ trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-04-02 16:48:40 UTC (rev 18919)
@@ -120,7 +120,7 @@
RandomGrabArrayItem item = rga.removeRandom(excluding);
if(logMINOR)
Logger.minor(this, "RGA has picked
"+x+"/"+grabArrays.length+": "+item+
- (item==null ? "" : ("
cancelled="+item.isCancelled()+")"))+" rga.isEmpty="+rga.isEmpty());
+ (item==null ? "" : ("
cancelled="+item.isEmpty()+")"))+" rga.isEmpty="+rga.isEmpty());
// Just because the item is cancelled does not
necessarily mean the whole client is.
// E.g. a segment may return cancelled because it is
decoding, that doesn't mean
// other segments are cancelled. So just go around the
loop in that case.
@@ -147,7 +147,7 @@
}
continue;
}
- if(item.isCancelled()) continue;
+ if(item.isEmpty()) continue;
return item;
}
}