Author: toad
Date: 2008-06-25 15:13:19 +0000 (Wed, 25 Jun 2008)
New Revision: 20684
Modified:
branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
branches/db4o/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
Log:
Add ObjectContainer to isEmpty and canRemove and use it for activation
Modified:
branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
2008-06-25 15:09:56 UTC (rev 20683)
+++ branches/db4o/freenet/src/freenet/client/async/BaseSingleFileFetcher.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -123,7 +123,7 @@
return cancelled;
}
- public synchronized boolean isEmpty() {
+ public synchronized boolean isEmpty(ObjectContainer container) {
return cancelled;
}
@@ -135,7 +135,7 @@
return !ctx.cacheLocalRequests;
}
- public boolean canRemove() {
+ public boolean canRemove(ObjectContainer container) {
// Simple request, once it's sent, it's sent. May be requeued
at a different # retries.
return true;
}
Modified: branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
2008-06-25 15:09:56 UTC (rev 20683)
+++ branches/db4o/freenet/src/freenet/client/async/OfferedKeysList.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -63,7 +63,7 @@
assert(keysList.size() == keys.size());
}
- public synchronized boolean isEmpty() {
+ public synchronized boolean isEmpty(ObjectContainer container) {
return keys.isEmpty();
}
@@ -159,7 +159,7 @@
return true;
}
- public boolean canRemove() {
+ public boolean canRemove(ObjectContainer container) {
return false;
}
Modified:
branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
2008-06-25 15:09:56 UTC (rev 20683)
+++ branches/db4o/freenet/src/freenet/client/async/SingleBlockInserter.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -311,7 +311,7 @@
cb.onFailure(new InsertException(InsertException.CANCELLED),
this, container, context);
}
- public synchronized boolean isEmpty() {
+ public synchronized boolean isEmpty(ObjectContainer container) {
return finished;
}
@@ -369,7 +369,7 @@
}
}
- public boolean canRemove() {
+ public boolean canRemove(ObjectContainer container) {
return true;
}
Modified:
branches/db4o/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2008-06-25 15:09:56 UTC (rev 20683)
+++
branches/db4o/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -351,7 +351,7 @@
return retryCount;
}
- public boolean canRemove() {
+ public boolean canRemove(ObjectContainer container) {
synchronized(segment) {
if(blockNums.size() < 2) {
// Can be removed, if the one key is processed.
@@ -369,7 +369,11 @@
}
}
- public boolean isEmpty() {
+ public boolean isEmpty(ObjectContainer container) {
+ if(persistent) {
+ container.activate(this, 1);
+ container.activate(blockNums, 1);
+ }
synchronized(segment) {
return cancelled || blockNums.isEmpty();
}
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-06-25 15:09:56 UTC (rev 20683)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -37,7 +37,7 @@
public void add(RandomGrabArrayItem req, ObjectContainer container) {
if(req.persistent() != persistent) throw new
IllegalArgumentException("req.persistent()="+req.persistent()+" but
array.persistent="+persistent+" item="+req+" array="+this);
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
- if(req.isEmpty()) {
+ if(req.isEmpty(container)) {
if(logMINOR) Logger.minor(this, "Is finished already:
"+req);
return;
}
@@ -84,7 +84,7 @@
RandomGrabArrayItem
item = reqs[i];
if(item == null) {
continue;
- } else
if(item.isEmpty()) {
+ } else
if(item.isEmpty(container)) {
changedMe =
true;
reqs[i] = null;
contents.remove(item);
@@ -117,7 +117,7 @@
ret = reqs[chosenIndex];
if(persistent)
container.activate(ret, 1);
- if(ret.canRemove()) {
+
if(ret.canRemove(container)) {
contents.remove(ret);
if(chosenIndex
!= index-1) {
reqs[chosenIndex] = reqs[index-1];
@@ -144,7 +144,7 @@
ret = reqs[validIndex];
if(persistent)
container.activate(ret, 1);
- if(ret.canRemove()) {
+
if(ret.canRemove(container)) {
changedMe =
true;
contents.remove(ret);
if(validIndex
!= index-1) {
@@ -179,7 +179,7 @@
if(persistent)
container.activate(ret, 1);
oret = ret;
- if(ret.isEmpty()) {
+ if(ret.isEmpty(container)) {
if(logMINOR) Logger.minor(this, "Not
returning because cancelled: "+ret);
ret = null;
}
@@ -193,7 +193,7 @@
}
continue;
}
- if(ret != null && !ret.canRemove()) {
+ if(ret != null && !ret.canRemove(container)) {
if(logMINOR) Logger.minor(this,
"Returning (cannot remove): "+ret+" of "+index);
if(persistent && changedMe)
container.set(this);
@@ -207,7 +207,7 @@
contents.remove(oret);
oret = reqs[i];
// May as well check whether that is
cancelled too.
- } while (index > i && (oret == null ||
oret.isEmpty()));
+ } while (index > i && (oret == null ||
oret.isEmpty(container)));
// Shrink array
if((index < reqs.length / 4) && (reqs.length >
MIN_SIZE)) {
changedMe = true;
@@ -217,7 +217,7 @@
System.arraycopy(reqs, 0, r, 0,
r.length);
reqs = r;
}
- if((ret != null) && !ret.isEmpty()) break;
+ if((ret != null) && !ret.isEmpty(container))
break;
}
}
if(logMINOR) Logger.minor(this, "Returning "+ret+" of "+index);
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
2008-06-25 15:09:56 UTC (rev 20683)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -12,14 +12,14 @@
*
* LOCKING: Should hold as few locks as possible as this needs to be
called while
* holding the RGA lock(s). */
- public boolean isEmpty();
+ public boolean isEmpty(ObjectContainer container);
/** Can this item be removed from the queue after it has been handled?
* Called immediately after finding a request to remove.
* If returns false, the item will remain in the queue and may be
chosen again.
* Note that in the case of SendableGet's, this is called before
chooseKey(), so
* it needs to return true if there are less than two requests on this
object. */
- public boolean canRemove();
+ public boolean canRemove(ObjectContainer container);
/** Does this RandomGrabArrayItem support remembering where it is
registered? */
public boolean knowsParentGrabArray();
Modified: branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-06-25 15:09:56 UTC (rev 20683)
+++ branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-06-25 15:13:19 UTC (rev 20684)
@@ -151,7 +151,7 @@
RandomGrabArrayItem item = rga.removeRandom(excluding,
container, context);
if(logMINOR)
Logger.minor(this, "RGA has picked
"+x+"/"+grabArrays.length+": "+item+
- (item==null ? "" : ("
cancelled="+item.isEmpty()+")"))+" rga.isEmpty="+rga.isEmpty());
+ (item==null ? "" : ("
cancelled="+item.isEmpty(container)+")"))+" 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.
@@ -181,7 +181,7 @@
}
continue;
}
- if(item.isEmpty()) continue;
+ if(item.isEmpty(container)) continue;
return item;
}
}