Author: nextgens
Date: 2006-07-10 10:22:11 +0000 (Mon, 10 Jul 2006)
New Revision: 9540
Modified:
trunk/freenet/src/freenet/client/ArchiveStoreContext.java
trunk/freenet/src/freenet/client/async/ClientGetter.java
trunk/freenet/src/freenet/client/async/ClientPutter.java
trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
trunk/freenet/src/freenet/client/async/MultiPutCompletionCallback.java
trunk/freenet/src/freenet/client/async/PrioritySchedulerCallback.java
trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
trunk/freenet/src/freenet/client/async/SingleFileInserter.java
trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
trunk/freenet/src/freenet/client/async/SplitFileInserter.java
trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
trunk/freenet/src/freenet/client/async/USKFetcher.java
trunk/freenet/src/freenet/client/async/USKInserter.java
trunk/freenet/src/freenet/support/SimpleIntNumberedItemComparator.java
Log:
* More consistent locking in freenet/client/async, following lint4j
recommendations
* some log messages have switched from minor to debug
this patch might cause more backoff, but hasn't deadlocked since it's running
here
Modified: trunk/freenet/src/freenet/client/ArchiveStoreContext.java
===================================================================
--- trunk/freenet/src/freenet/client/ArchiveStoreContext.java 2006-07-10
01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/ArchiveStoreContext.java 2006-07-10
10:22:11 UTC (rev 9540)
@@ -54,7 +54,7 @@
Logger.minor(this, "Checking cache: "+key+" "+internalName);
if((data = manager.getCached(key, internalName)) != null) {
return data;
- }
+ }
return null;
}
@@ -74,7 +74,7 @@
// Archive hash
- byte[] lastHash = null;
+ byte[] lastHash;
/** Returns the hash of the archive last time we fetched it, or null */
public byte[] getLastHash() {
@@ -95,12 +95,10 @@
* Remove all ArchiveStoreItems with this key from the cache.
*/
public void removeAllCachedItems() {
- synchronized(myItems) {
- ArchiveStoreItem item;
- while((item = (ArchiveStoreItem) myItems.pop()) !=
null) {
- manager.removeCachedItem(item);
- item.finalize();
- }
+ ArchiveStoreItem item;
+ while((item = (ArchiveStoreItem) myItems.pop()) != null) {
+ manager.removeCachedItem(item);
+ item.finalize();
}
}
Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java 2006-07-10
01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java 2006-07-10
10:22:11 UTC (rev 9540)
@@ -53,7 +53,7 @@
archiveRestarts = 0;
}
- public void start() throws FetchException {
+ public synchronized void start() throws FetchException {
try {
currentState = SingleFileFetcher.create(this, this, new
ClientMetadata(),
uri, ctx, actx,
ctx.maxNonSplitfileRetries, 0, false, null, true,
@@ -65,7 +65,7 @@
}
}
- public void onSuccess(FetchResult result, ClientGetState state) {
+ public synchronized void onSuccess(FetchResult result, ClientGetState
state) {
finished = true;
currentState = null;
if((returnBucket != null) && (result.asBucket() !=
returnBucket)) {
@@ -87,7 +87,7 @@
client.onSuccess(result, this);
}
- public void onFailure(FetchException e, ClientGetState state) {
+ public synchronized void onFailure(FetchException e, ClientGetState
state) {
while(true) {
if(e.mode == FetchException.ARCHIVE_RESTART) {
archiveRestarts++;
@@ -120,7 +120,7 @@
}
}
- public boolean isFinished() {
+ public synchronized boolean isFinished() {
return finished || cancelled;
}
Modified: trunk/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-07-10
01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-07-10
10:22:11 UTC (rev 9540)
@@ -51,7 +51,7 @@
this.cancelled = false;
}
- public void start() throws InserterException {
+ public synchronized void start() throws InserterException {
try {
currentState =
new SingleFileInserter(this, this, new
InsertBlock(data, cm, targetURI), isMetadata, ctx, false, getCHKOnly, false,
null, false);
@@ -66,13 +66,13 @@
}
}
- public void onSuccess(ClientPutState state) {
+ public synchronized void onSuccess(ClientPutState state) {
finished = true;
currentState = null;
client.onSuccess(this);
}
- public void onFailure(InserterException e, ClientPutState state) {
+ public synchronized void onFailure(InserterException e, ClientPutState
state) {
finished = true;
currentState = null;
client.onFailure(e, this);
@@ -83,15 +83,13 @@
client.onGeneratedURI(uri, this);
}
- public void cancel() {
- synchronized(this) {
- super.cancel();
- if(currentState != null)
- currentState.cancel();
- }
+ public synchronized void cancel() {
+ super.cancel();
+ if(currentState != null)
+ currentState.cancel();
}
- public boolean isFinished() {
+ public synchronized boolean isFinished() {
return finished || cancelled;
}
Modified: trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -182,11 +182,12 @@
int priority;
short fuzz = -1, iteration = 0;
- if(choosenPriorityScheduler.equals(PRIORITY_SOFT))
- fuzz = -1;
- else if(choosenPriorityScheduler.equals(PRIORITY_HARD))
- fuzz = 0;
-
+ synchronized (this) {
+ if(choosenPriorityScheduler.equals(PRIORITY_SOFT))
+ fuzz = -1;
+ else if(choosenPriorityScheduler.equals(PRIORITY_HARD))
+ fuzz = 0;
+ }
// we loop to ensure we try every possibilities ( n + 1)
//
// PRIO will do 0,1,2,3,4,5,6,0
@@ -195,11 +196,11 @@
priority = fuzz<0 ?
tweakedPrioritySelector[random.nextInt(tweakedPrioritySelector.length)] :
prioritySelector[Math.abs(fuzz % prioritySelector.length)];
result = priorities[priority];
if((result != null) && !result.isEmpty()) {
- Logger.minor(this, "Found "+priority);
+ Logger.minor(this, "using priority :
"+priority);
return result;
}
- Logger.minor(this, "Priority "+priority+" is null (fuzz
= "+fuzz+")");
+ Logger.debug(this, "Priority "+priority+" is null (fuzz
= "+fuzz+")");
fuzz++;
}
Modified: trunk/freenet/src/freenet/client/async/MultiPutCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/MultiPutCompletionCallback.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/MultiPutCompletionCallback.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -32,13 +32,11 @@
finished = false;
}
- public void onSuccess(ClientPutState state) {
- synchronized(this) {
+ public synchronized void onSuccess(ClientPutState state) {
if(finished) return;
waitingFor.remove(state);
if(!(waitingFor.isEmpty() && started))
return;
- }
/* Using this.e here will cause complete to consider the
* insert as failed if onFailed has been called in the past
* for this request. This makes collisions work. It does
@@ -78,14 +76,13 @@
waitingFor.add(ps);
}
- public void arm() {
+ public synchronized void arm() {
boolean allDone;
boolean allGotBlocks;
- synchronized(this) {
- started = true;
- allDone = waitingFor.isEmpty();
- allGotBlocks = waitingForBlockSet.isEmpty();
- }
+ started = true;
+ allDone = waitingFor.isEmpty();
+ allGotBlocks = waitingForBlockSet.isEmpty();
+
if(allGotBlocks) {
cb.onBlockSetFinished(this);
}
@@ -126,7 +123,7 @@
}
}
- public void onMetadata(Metadata m, ClientPutState state) {
+ public synchronized void onMetadata(Metadata m, ClientPutState state) {
if(generator == state) {
cb.onMetadata(m, this);
} else {
Modified: trunk/freenet/src/freenet/client/async/PrioritySchedulerCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/PrioritySchedulerCallback.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/PrioritySchedulerCallback.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -8,7 +8,7 @@
ClientRequestScheduler cs;
PrioritySchedulerCallback(ClientRequestScheduler cs){
- this.value = new String(ClientRequestScheduler.PRIORITY_HARD);
+ this.value = ClientRequestScheduler.PRIORITY_HARD;
this.cs = cs;
}
Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -194,10 +194,10 @@
private long totalSize;
private boolean metadataBlockSetFinalized;
private Metadata baseMetadata;
- private boolean hasResolvedBase = false;
+ private boolean hasResolvedBase;
private final static String[] defaultDefaultNames =
new String[] { "index.html", "index.htm", "default.html",
"default.htm" };
- private int bytesOnZip = 0;
+ private int bytesOnZip;
private LinkedList elementsToPutInZip;
public SimpleManifestPutter(ClientCallback cb, ClientRequestScheduler
chkSched,
@@ -224,12 +224,10 @@
// FIXME do something.
}
- public void start() throws InserterException {
+ public synchronized void start() throws InserterException {
Logger.minor(this, "Starting "+this);
PutHandler[] running;
- synchronized(this) {
- running = (PutHandler[]) runningPutHandlers.toArray(new
PutHandler[runningPutHandlers.size()]);
- }
+ running = (PutHandler[]) runningPutHandlers.toArray(new
PutHandler[runningPutHandlers.size()]);
try {
for(int i=0;i<running.length;i++) {
@@ -309,7 +307,7 @@
return finalURI;
}
- public boolean isFinished() {
+ public synchronized boolean isFinished() {
return finished || cancelled;
}
@@ -339,10 +337,6 @@
resolveAndStartBase();
}
-
- private void startMetadataInsert() {
- resolveAndStartBase();
- }
private void resolveAndStartBase() {
Bucket bucket = null;
Modified: trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -36,7 +36,6 @@
private final FailureCodeTracker errors;
private boolean finished;
private final boolean dontSendEncoded;
- private ClientKey key;
private WeakReference refToClientKeyBlock;
final int token; // for e.g. splitfiles
private final Object tokenObject;
@@ -191,8 +190,10 @@
public ClientKeyBlock getBlock() {
try {
- if(finished) return null;
- return encode();
+ synchronized (this) {
+ if(finished) return null;
+ return encode();
+ }
} catch (InserterException e) {
cb.onFailure(e, this);
return null;
@@ -203,7 +204,7 @@
}
}
- public void schedule() throws InserterException {
+ public synchronized void schedule() throws InserterException {
if(finished) return;
if(getCHKOnly) {
ClientKeyBlock block = encode();
@@ -224,7 +225,7 @@
else throw new IllegalArgumentException();
}
- public FreenetURI getURI() {
+ public synchronized FreenetURI getURI() {
if(resultingURI == null)
getBlock();
return resultingURI;
@@ -251,7 +252,7 @@
cb.onFailure(new
InserterException(InserterException.CANCELLED), this);
}
- public boolean isFinished() {
+ public synchronized boolean isFinished() {
return finished;
}
Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -42,7 +42,7 @@
final boolean insertAsArchiveManifest;
/** If true, we are not the top level request, and should not
* update our parent to point to us as current put-stage. */
- private boolean cancelled = false;
+ private boolean cancelled;
private boolean reportMetadataOnly;
public final Object token;
@@ -230,7 +230,6 @@
cb.onTransition(this, sh);
sfi.start();
}
- return;
}
private ClientPutState createInserter(BaseClientPutter parent, Bucket
data, short compressionCodec, FreenetURI uri,
@@ -258,11 +257,11 @@
ClientPutState sfi;
ClientPutState metadataPutter;
- boolean finished = false;
- boolean splitInsertSuccess = false;
- boolean metaInsertSuccess = false;
- boolean splitInsertSetBlocks = false;
- boolean metaInsertSetBlocks = false;
+ boolean finished;
+ boolean splitInsertSuccess;
+ boolean metaInsertSuccess;
+ boolean splitInsertSetBlocks;
+ boolean metaInsertSetBlocks;
public synchronized void onTransition(ClientPutState oldState,
ClientPutState newState) {
if(oldState == sfi)
@@ -298,7 +297,7 @@
fail(e);
}
- public void onMetadata(Metadata meta, ClientPutState state) {
+ public synchronized void onMetadata(Metadata meta,
ClientPutState state) {
if(finished) return;
if(state == metadataPutter) {
Logger.error(this, "Got metadata for metadata");
@@ -311,31 +310,30 @@
cb.onMetadata(meta, this);
metaInsertSuccess = true;
} else {
- synchronized(this) {
- Bucket metadataBucket;
- try {
- metadataBucket =
BucketTools.makeImmutableBucket(ctx.bf, meta.writeToByteArray());
- } catch (IOException e) {
- InserterException ex = new
InserterException(InserterException.BUCKET_ERROR, e, null);
- fail(ex);
- return;
- } catch (MetadataUnresolvedException e)
{
- Logger.error(this, "Impossible:
"+e, e);
- InserterException ex = new
InserterException(InserterException.INTERNAL_ERROR,
"MetadataUnresolvedException in SingleFileInserter.SplitHandler: "+e, null);
- ex.initCause(e);
- fail(ex);
- return;
- }
- InsertBlock newBlock = new
InsertBlock(metadataBucket, null, block.desiredURI);
- try {
- metadataPutter = new
SingleFileInserter(parent, this, newBlock, true, ctx, false, getCHKOnly, false,
token, false);
- Logger.minor(this, "Putting
metadata on "+metadataPutter);
- } catch (InserterException e) {
- cb.onFailure(e, this);
- return;
- }
+ Bucket metadataBucket;
+ try {
+ metadataBucket =
BucketTools.makeImmutableBucket(ctx.bf, meta.writeToByteArray());
+ } catch (IOException e) {
+ InserterException ex = new
InserterException(InserterException.BUCKET_ERROR, e, null);
+ fail(ex);
+ return;
+ } catch (MetadataUnresolvedException e) {
+ Logger.error(this, "Impossible: "+e, e);
+ InserterException ex = new
InserterException(InserterException.INTERNAL_ERROR,
"MetadataUnresolvedException in SingleFileInserter.SplitHandler: "+e, null);
+ ex.initCause(e);
+ fail(ex);
+ return;
}
+ InsertBlock newBlock = new
InsertBlock(metadataBucket, null, block.desiredURI);
try {
+ metadataPutter = new
SingleFileInserter(parent, this, newBlock, true, ctx, false, getCHKOnly, false,
token, false);
+ Logger.minor(this, "Putting metadata on
"+metadataPutter);
+ } catch (InserterException e) {
+ cb.onFailure(e, this);
+ return;
+ }
+
+ try {
((SingleFileInserter)metadataPutter).start();
} catch (InserterException e) {
fail(e);
@@ -359,12 +357,12 @@
return parent;
}
- public void onEncode(BaseClientKey key, ClientPutState state) {
+ public synchronized void onEncode(BaseClientKey key,
ClientPutState state) {
if(state == metadataPutter)
cb.onEncode(key, this);
}
- public void cancel() {
+ public synchronized void cancel() {
if(sfi != null)
sfi.cancel();
if(metadataPutter != null)
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -88,7 +88,7 @@
Logger.minor(this, "Created "+this+" for "+parentFetcher);
}
- public boolean isFinished() {
+ public synchronized boolean isFinished() {
return finished;
}
@@ -129,7 +129,7 @@
}
/** How many blocks failed permanently due to fatal errors? */
- public int fatallyFailedBlocks() {
+ public synchronized int fatallyFailedBlocks() {
return fatallyFailedBlocks;
}
Modified: trunk/freenet/src/freenet/client/async/SplitFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserter.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserter.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -10,7 +10,6 @@
import freenet.client.InserterException;
import freenet.client.Metadata;
import freenet.keys.CHKBlock;
-import freenet.keys.ClientCHKBlock;
import freenet.keys.FreenetURI;
import freenet.support.Bucket;
import freenet.support.BucketTools;
@@ -154,8 +153,9 @@
// Create Metadata
m = new Metadata(splitfileAlgorithm, dataURIs,
checkURIs, segmentSize, checkSegmentSize, cm, dataLength, compressionCodec,
isMetadata, insertAsArchiveManifest);
}
- haveSentMetadata = true;
}
+ haveSentMetadata = true;
+
if(missingURIs) {
Logger.minor(this, "Missing URIs");
// Error
Modified: trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -9,7 +9,6 @@
import freenet.client.Metadata;
import freenet.keys.BaseClientKey;
import freenet.keys.CHKBlock;
-import freenet.keys.ClientCHKBlock;
import freenet.keys.FreenetURI;
import freenet.support.Bucket;
import freenet.support.Logger;
@@ -60,8 +59,6 @@
dataBlockInserters[i].schedule();
}
if(splitfileAlgo == null) {
- // Don't need to encode blocks
- } else {
// Encode blocks
Thread t = new Thread(new EncodeBlocksRunnable(),
"Blocks encoder");
t.setDaemon(true);
@@ -113,8 +110,8 @@
synchronized(this) {
if(finished) return;
finished = true;
+ toThrow = InserterException.construct(errors);
}
- toThrow = InserterException.construct(errors);
parent.segmentFinished(this);
}
@@ -172,30 +169,29 @@
finish();
}
- private boolean completed(int x) {
+ private synchronized boolean completed(int x) {
Logger.minor(this, "Completed: "+x+" on "+this+" (
completed="+blocksCompleted+",
total="+(dataBlockInserters.length+checkBlockInserters.length));
- synchronized(this) {
- if(finished) return true;
- if(x >= dataBlocks.length) {
- if(checkBlockInserters[x-dataBlocks.length] ==
null) {
- Logger.error(this, "Completed twice:
check block "+x+" on "+this);
- return true;
- }
- checkBlockInserters[x-dataBlocks.length] = null;
- } else {
- if(dataBlockInserters[x] == null) {
- Logger.error(this, "Completed twice:
data block "+x+" on "+this);
- return true;
- }
- dataBlockInserters[x] = null;
+
+ if(finished) return true;
+ if(x >= dataBlocks.length) {
+ if(checkBlockInserters[x-dataBlocks.length] == null) {
+ Logger.error(this, "Completed twice: check
block "+x+" on "+this);
+ return true;
}
- blocksCompleted++;
- if(blocksCompleted != dataBlockInserters.length +
checkBlockInserters.length) return true;
- return false;
+ checkBlockInserters[x-dataBlocks.length] = null;
+ } else {
+ if(dataBlockInserters[x] == null) {
+ Logger.error(this, "Completed twice: data block
"+x+" on "+this);
+ return true;
+ }
+ dataBlockInserters[x] = null;
}
+ blocksCompleted++;
+ if(blocksCompleted != dataBlockInserters.length +
checkBlockInserters.length) return true;
+ return false;
}
- public boolean isFinished() {
+ public synchronized boolean isFinished() {
return finished;
}
@@ -216,16 +212,18 @@
}
InserterException getException() {
- return toThrow;
+ synchronized (this) {
+ return toThrow;
+ }
}
public void cancel() {
synchronized(this) {
if(finished) return;
finished = true;
+ if(toThrow != null)
+ toThrow = new
InserterException(InserterException.CANCELLED);
}
- if(toThrow != null)
- toThrow = new
InserterException(InserterException.CANCELLED);
for(int i=0;i<dataBlockInserters.length;i++) {
SingleBlockInserter sbi = dataBlockInserters[i];
if(sbi != null)
@@ -252,7 +250,7 @@
Logger.error(this, "Should not happen:
onBlockSetFinished("+state+") on "+this);
}
- public boolean hasURIs() {
+ public synchronized boolean hasURIs() {
return hasURIs;
}
}
Modified: trunk/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcher.java 2006-07-10
01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/USKFetcher.java 2006-07-10
10:22:11 UTC (rev 9540)
@@ -99,7 +99,7 @@
boolean succeeded;
/** DNF? */
boolean dnf;
- boolean cancelled = false;
+ boolean cancelled;
public USKAttempt(long i) {
this.number = i;
this.succeeded = false;
@@ -181,7 +181,7 @@
/** Keep going forever? */
private final boolean backgroundPoll;
- private boolean started = false;
+ private boolean started;
USKFetcher(USK origUSK, USKManager manager, FetcherContext ctx,
ClientRequester parent, int minFailures, boolean pollForever) {
this(origUSK, manager, ctx, parent, minFailures, pollForever,
DEFAULT_MAX_MIN_FAILURES);
@@ -227,6 +227,8 @@
private void finishSuccess() {
if(backgroundPoll) {
long valAtEnd = uskManager.lookup(origUSK);
+ long end, newValAtEnd;
+ long now = System.currentTimeMillis();
synchronized(this) {
started = false; // don't finish before have
rescheduled
if(valAtEnd > valueAtSchedule) {
@@ -243,10 +245,9 @@
long newSleepTime = sleepTime * 2;
if(newSleepTime > maxSleepTime) newSleepTime =
maxSleepTime;
sleepTime = newSleepTime;
+ end = now + sleepTime;
+ newValAtEnd = valAtEnd;
}
- long now = System.currentTimeMillis();
- long end = now + sleepTime;
- long newValAtEnd = valAtEnd;
// FIXME do this without occupying a thread
while((now < end) && ((newValAtEnd =
uskManager.lookup(origUSK)) == valAtEnd)) {
long d = end - now;
@@ -311,17 +312,18 @@
}
}
cancelBefore(curLatest);
- }
- if(l == null) return;
- // If we schedule them here, we don't get icky recursion
problems.
- else if(!cancelled) {
- for(Iterator i=l.iterator();i.hasNext();) {
- // We may be called recursively through
onSuccess().
- // So don't start obsolete requests.
- USKAttempt a = (USKAttempt) i.next();
- lastEd = uskManager.lookup(origUSK);
- if((lastEd <= a.number) && !a.cancelled)
- a.schedule();
+
+ if(l == null) return;
+ // If we schedule them here, we don't get icky
recursion problems.
+ else if(!cancelled) {
+ for(Iterator i=l.iterator();i.hasNext();) {
+ // We may be called recursively through
onSuccess().
+ // So don't start obsolete requests.
+ USKAttempt a = (USKAttempt) i.next();
+ lastEd = uskManager.lookup(origUSK);
+ if((lastEd <= a.number) && !a.cancelled)
+ a.schedule();
+ }
}
}
}
@@ -330,9 +332,10 @@
synchronized(this) {
runningAttempts.remove(att);
if(!runningAttempts.isEmpty()) return;
+
+ if(cancelled)
+ finishCancelled();
}
- if(cancelled)
- finishCancelled();
}
private void finishCancelled() {
@@ -386,7 +389,9 @@
}
public boolean isFinished() {
- return completed || cancelled;
+ synchronized (this) {
+ return completed || cancelled;
+ }
}
public USK getOriginalUSK() {
@@ -404,10 +409,10 @@
add(i);
attempts = (USKAttempt[]) runningAttempts.toArray(new
USKAttempt[runningAttempts.size()]);
started = true;
- }
if(!cancelled)
for(int i=0;i<attempts.length;i++)
attempts[i].schedule();
+ }
}
public void cancel() {
@@ -439,23 +444,23 @@
subscribers.remove(cb);
}
- public boolean hasLastData() {
+ public synchronized boolean hasLastData() {
return this.lastRequestData != null;
}
- public boolean lastContentWasMetadata() {
+ public synchronized boolean lastContentWasMetadata() {
return this.lastWasMetadata;
}
- public short lastCompressionCodec() {
+ public synchronized short lastCompressionCodec() {
return this.lastCompressionCodec;
}
- public Bucket getLastData() {
+ public synchronized Bucket getLastData() {
return this.lastRequestData;
}
- public void freeLastData() {
+ public synchronized void freeLastData() {
lastRequestData.free();
lastRequestData = null;
}
Modified: trunk/freenet/src/freenet/client/async/USKInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKInserter.java 2006-07-10
01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/client/async/USKInserter.java 2006-07-10
10:22:11 UTC (rev 9540)
@@ -42,7 +42,7 @@
private SingleBlockInserter sbi;
private long edition;
/** Number of collisions while trying to insert so far */
- private int consecutiveCollisions = 0;
+ private int consecutiveCollisions;
private boolean finished;
/** After attempting inserts on this many slots, go back to the Fetcher
*/
private static final long MAX_TRIED_SLOTS = 10;
@@ -65,16 +65,15 @@
* The Fetcher must be insert-mode, in other words, it must know that
we want the latest edition,
* including author errors and so on.
*/
- private void scheduleFetcher() {
+ private synchronized void scheduleFetcher() {
Logger.minor(this, "scheduling fetcher for "+pubUSK.getURI());
- synchronized(this) {
- if(finished) return;
- fetcher =
ctx.uskManager.getFetcherForInsertDontSchedule(pubUSK, parent.priorityClass,
this);
- }
+ if(finished) return;
+ fetcher =
ctx.uskManager.getFetcherForInsertDontSchedule(pubUSK, parent.priorityClass,
this);
+
fetcher.schedule();
}
- public void onFoundEdition(long l, USK key) {
+ public synchronized void onFoundEdition(long l, USK key) {
edition = Math.max(l, edition);
consecutiveCollisions = 0;
if((fetcher.lastContentWasMetadata() == isMetadata) &&
fetcher.hasLastData()
@@ -87,10 +86,8 @@
// Success!
cb.onEncode(pubUSK.copy(edition), this);
cb.onSuccess(this);
- synchronized(this) {
- finished = true;
- sbi = null;
- }
+ finished = true;
+ sbi = null;
return;
}
} catch (IOException e) {
@@ -101,19 +98,17 @@
scheduleInsert();
}
- private void scheduleInsert() {
+ private synchronized void scheduleInsert() {
long edNo = Math.max(edition, ctx.uskManager.lookup(pubUSK))+1;
- synchronized(this) {
- if(finished) return;
- edition = edNo;
- Logger.minor(this, "scheduling insert for
"+pubUSK.getURI()+" "+edition);
- try {
- sbi = new SingleBlockInserter(parent, data,
compressionCodec, privUSK.getInsertableSSK(edition).getInsertURI(),
- ctx, this, isMetadata,
sourceLength, token, getCHKOnly, false, true /* we don't use it */,
tokenObject);
- } catch (InserterException e) {
- cb.onFailure(e, this);
- return;
- }
+ if(finished) return;
+ edition = edNo;
+ Logger.minor(this, "scheduling insert for "+pubUSK.getURI()+"
"+edition);
+ try {
+ sbi = new SingleBlockInserter(parent, data,
compressionCodec, privUSK.getInsertableSSK(edition).getInsertURI(),
+ ctx, this, isMetadata, sourceLength,
token, getCHKOnly, false, true /* we don't use it */, tokenObject);
+ } catch (InserterException e) {
+ cb.onFailure(e, this);
+ return;
}
try {
sbi.schedule();
@@ -122,13 +117,11 @@
}
}
- public void onSuccess(ClientPutState state) {
+ public synchronized void onSuccess(ClientPutState state) {
cb.onEncode(pubUSK.copy(edition), this);
cb.onSuccess(this);
- synchronized(this) {
- finished = true;
- sbi = null;
- }
+ finished = true;
+ sbi = null;
FreenetURI targetURI = pubUSK.getSSK(edition).getURI();
FreenetURI realURI = ((SingleBlockInserter)state).getURI();
if(!targetURI.equals(realURI))
@@ -140,7 +133,7 @@
// FINISHED!!!! Yay!!!
}
- public void onFailure(InserterException e, ClientPutState state) {
+ public synchronized void onFailure(InserterException e, ClientPutState
state) {
sbi = null;
if(e.getMode() == InserterException.COLLISION) {
// Try the next slot
@@ -195,7 +188,7 @@
scheduleInsert();
}
- public void onCancelled() {
+ public synchronized void onCancelled() {
if(finished) return;
Logger.error(this, "Unexpected onCancelled()", new
Exception("error"));
cancel();
Modified: trunk/freenet/src/freenet/support/SimpleIntNumberedItemComparator.java
===================================================================
--- trunk/freenet/src/freenet/support/SimpleIntNumberedItemComparator.java
2006-07-10 01:50:31 UTC (rev 9539)
+++ trunk/freenet/src/freenet/support/SimpleIntNumberedItemComparator.java
2006-07-10 10:22:11 UTC (rev 9540)
@@ -12,7 +12,7 @@
public int compare(Object o1, Object o2) {
int x = ocompare(o1, o2);
- Logger.minor(this, "compare("+o1+","+o2+") = "+x);
+ Logger.debug(this, "compare("+o1+","+o2+") = "+x);
return x;
}