Author: toad
Date: 2006-01-26 22:07:23 +0000 (Thu, 26 Jan 2006)
New Revision: 7941
Modified:
trunk/freenet/src/freenet/client/InserterContext.java
trunk/freenet/src/freenet/client/async/ClientGetter.java
trunk/freenet/src/freenet/client/async/ClientPutter.java
trunk/freenet/src/freenet/client/async/ClientRequest.java
trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
trunk/freenet/src/freenet/client/async/SingleFileInserter.java
trunk/freenet/src/freenet/client/async/SplitFileFetcher.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/events/SplitfileProgressEvent.java
trunk/freenet/src/freenet/node/Version.java
Log:
393: Feedback on progress of download/upload (in TMCI, using client.events, FCP
is next).
Modified: trunk/freenet/src/freenet/client/InserterContext.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterContext.java 2006-01-26
21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/InserterContext.java 2006-01-26
22:07:23 UTC (rev 7941)
@@ -17,7 +17,7 @@
public final int consecutiveRNFsCountAsSuccess;
public final int splitfileSegmentDataBlocks;
public final int splitfileSegmentCheckBlocks;
- final ClientEventProducer eventProducer;
+ public final ClientEventProducer eventProducer;
/** Interesting tradeoff, see comments at top of Node.java. */
public final boolean cacheLocalRequests;
private boolean cancelled;
Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java 2006-01-26
21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java 2006-01-26
22:07:23 UTC (rev 7941)
@@ -7,6 +7,7 @@
import freenet.client.FetchException;
import freenet.client.FetchResult;
import freenet.client.FetcherContext;
+import freenet.client.events.SplitfileProgressEvent;
import freenet.keys.FreenetURI;
/**
@@ -34,7 +35,7 @@
public void start() throws FetchException {
try {
- currentState = new SingleFileFetcher(this, this, new
ClientMetadata(), uri, ctx, actx, getPriorityClass(), 0, false, null);
+ currentState = new SingleFileFetcher(this, this, new
ClientMetadata(), uri, ctx, actx, getPriorityClass(), 0, false, null, true);
currentState.schedule();
} catch (MalformedURLException e) {
throw new FetchException(FetchException.INVALID_URI, e);
@@ -84,5 +85,9 @@
public FreenetURI getURI() {
return uri;
}
+
+ public void notifyClients() {
+ ctx.eventProducer.produceEvent(new
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks,
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks));
+ }
}
Modified: trunk/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-01-26
21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-01-26
22:07:23 UTC (rev 7941)
@@ -5,6 +5,7 @@
import freenet.client.InserterContext;
import freenet.client.InserterException;
import freenet.client.Metadata;
+import freenet.client.events.SplitfileProgressEvent;
import freenet.keys.ClientKey;
import freenet.keys.FreenetURI;
import freenet.support.Bucket;
@@ -92,4 +93,8 @@
Logger.error(this, "Got metadata on "+this+" from "+state+"
(this means the metadata won't be inserted)");
}
+ public void notifyClients() {
+ ctx.eventProducer.produceEvent(new
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks,
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks));
+ }
+
}
Modified: trunk/freenet/src/freenet/client/async/ClientRequest.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequest.java 2006-01-26
21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/ClientRequest.java 2006-01-26
22:07:23 UTC (rev 7941)
@@ -34,4 +34,44 @@
public abstract FreenetURI getURI();
public abstract boolean isFinished();
+
+ /** Total number of blocks this request has tried to fetch/put. */
+ protected int totalBlocks;
+ /** Number of blocks we have successfully completed a fetch/put for. */
+ protected int successfulBlocks;
+ /** Number of blocks which have failed. */
+ protected int failedBlocks;
+ /** Number of blocks which have failed fatally. */
+ protected int fatallyFailedBlocks;
+ /** Minimum number of blocks required to succeed for success. */
+ protected int minSuccessBlocks;
+
+ public synchronized void addBlock() {
+ totalBlocks++;
+ }
+
+ public synchronized void addBlocks(int num) {
+ totalBlocks+=num;
+ }
+
+ public synchronized void completedBlock() {
+ successfulBlocks++;
+ notifyClients();
+ }
+
+ public synchronized void failedBlock() {
+ failedBlocks++;
+ notifyClients();
+ }
+
+ public synchronized void fatallyFailedBlock() {
+ fatallyFailedBlocks++;
+ notifyClients();
+ }
+
+ public synchronized void addMustSucceedBlocks(int blocks) {
+ minSuccessBlocks += blocks;
+ }
+
+ public abstract void notifyClients();
}
Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -11,6 +11,7 @@
import freenet.client.InserterContext;
import freenet.client.InserterException;
import freenet.client.Metadata;
+import freenet.client.events.SplitfileProgressEvent;
import freenet.keys.ClientKey;
import freenet.keys.FreenetURI;
import freenet.support.Bucket;
@@ -101,6 +102,10 @@
gotAllMetadata();
}
}
+
+ public void notifyClients() {
+ // FIXME generate per-filename events???
+ }
}
private final HashMap putHandlersByName;
@@ -288,4 +293,8 @@
fail(new InserterException(InserterException.INTERNAL_ERROR));
}
+ public void notifyClients() {
+ ctx.eventProducer.produceEvent(new
SplitfileProgressEvent(this.totalBlocks, this.successfulBlocks,
this.failedBlocks, this.fatallyFailedBlocks, this.minSuccessBlocks));
+ }
+
}
Modified: trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SingleBlockInserter.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -41,7 +41,7 @@
final int sourceLength;
private int consecutiveRNFs;
- public SingleBlockInserter(BaseClientPutter parent, Bucket data, short
compressionCodec, FreenetURI uri, InserterContext ctx, PutCompletionCallback
cb, boolean isMetadata, int sourceLength, int token, boolean getCHKOnly) throws
InserterException {
+ public SingleBlockInserter(BaseClientPutter parent, Bucket data, short
compressionCodec, FreenetURI uri, InserterContext ctx, PutCompletionCallback
cb, boolean isMetadata, int sourceLength, int token, boolean getCHKOnly,
boolean addToParent) throws InserterException {
this.consecutiveRNFs = 0;
this.token = token;
this.parent = parent;
@@ -61,6 +61,11 @@
cb.onSuccess(this);
finished = true;
}
+ if(addToParent) {
+ parent.addBlock();
+ parent.addMustSucceedBlocks(1);
+ parent.notifyClients();
+ }
}
protected ClientKeyBlock innerEncode() throws InserterException {
@@ -165,6 +170,10 @@
if(finished) return;
finished = true;
}
+ if(e.isFatal())
+ parent.fatallyFailedBlock();
+ else
+ parent.failedBlock();
cb.onFailure(e, this);
}
@@ -198,6 +207,7 @@
synchronized(this) {
finished = true;
}
+ parent.completedBlock();
cb.onSuccess(this);
}
Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -55,7 +55,7 @@
* @param token
* @param dontTellClientGet
*/
- public SingleFileFetcher(ClientGetter get, GetCompletionCallback cb,
ClientMetadata metadata, ClientKey key, LinkedList metaStrings, FetcherContext
ctx, ArchiveContext actx, int maxRetries, int recursionLevel, boolean
dontTellClientGet, Object token) throws FetchException {
+ public SingleFileFetcher(ClientGetter get, GetCompletionCallback cb,
ClientMetadata metadata, ClientKey key, LinkedList metaStrings, FetcherContext
ctx, ArchiveContext actx, int maxRetries, int recursionLevel, boolean
dontTellClientGet, Object token, boolean isEssential) throws FetchException {
Logger.minor(this, "Creating SingleFileFetcher for "+key);
this.cancelled = false;
this.dontTellClientGet = dontTellClientGet;
@@ -77,11 +77,14 @@
if(recursionLevel > ctx.maxRecursionLevel)
throw new
FetchException(FetchException.TOO_MUCH_RECURSION);
this.decompressors = new LinkedList();
+ parent.addBlock();
+ if(isEssential)
+ parent.addMustSucceedBlocks(1);
}
/** Called by ClientGet. */
- public SingleFileFetcher(ClientGetter get, GetCompletionCallback cb,
ClientMetadata metadata, FreenetURI uri, FetcherContext ctx, ArchiveContext
actx, int maxRetries, int recursionLevel, boolean dontTellClientGet, Object
token) throws MalformedURLException, FetchException {
- this(get, cb, metadata, ClientKey.getBaseKey(uri),
uri.listMetaStrings(), ctx, actx, maxRetries, recursionLevel,
dontTellClientGet, token);
+ public SingleFileFetcher(ClientGetter get, GetCompletionCallback cb,
ClientMetadata metadata, FreenetURI uri, FetcherContext ctx, ArchiveContext
actx, int maxRetries, int recursionLevel, boolean dontTellClientGet, Object
token, boolean isEssential) throws MalformedURLException, FetchException {
+ this(get, cb, metadata, ClientKey.getBaseKey(uri),
uri.listMetaStrings(), ctx, actx, maxRetries, recursionLevel,
dontTellClientGet, token, isEssential);
}
/** Copy constructor, modifies a few given fields, don't call
schedule() */
@@ -203,6 +206,7 @@
}
result = new FetchResult(result, data);
}
+ parent.completedBlock();
rcb.onSuccess(result, this);
}
@@ -302,7 +306,7 @@
metaStrings.addFirst(o);
}
- SingleFileFetcher f = new
SingleFileFetcher(parent, rcb, clientMetadata, key, metaStrings, ctx, actx,
maxRetries, recursionLevel, false, null);
+ SingleFileFetcher f = new
SingleFileFetcher(parent, rcb, clientMetadata, key, metaStrings, ctx, actx,
maxRetries, recursionLevel, false, null, true);
if(metadata.isCompressed()) {
Compressor codec =
Compressor.getCompressionAlgorithmByMetadataID(metadata.getCompressionCodec());
f.addDecompressor(codec);
@@ -433,6 +437,10 @@
}
}
// :(
+ if(e.isFatal() || forceFatal)
+ parent.fatallyFailedBlock();
+ else
+ parent.failedBlock();
rcb.onFailure(e, this);
}
Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -156,7 +156,7 @@
if((block.clientMetadata == null ||
block.clientMetadata.isTrivial())) {
if(data.size() < blockSize) {
// Just insert it
- SingleBlockInserter bi = new
SingleBlockInserter(parent, data, codecNumber, block.desiredURI, ctx, cb,
metadata, (int)block.getData().size(), -1, getCHKOnly);
+ SingleBlockInserter bi = new
SingleBlockInserter(parent, data, codecNumber, block.desiredURI, ctx, cb,
metadata, (int)block.getData().size(), -1, getCHKOnly, true);
bi.schedule();
cb.onTransition(this, bi);
return;
@@ -165,7 +165,7 @@
if (data.size() < ClientCHKBlock.MAX_COMPRESSED_DATA_LENGTH) {
// Insert single block, then insert pointer to it
if(reportMetadataOnly) {
- SingleBlockInserter dataPutter = new
SingleBlockInserter(parent, data, codecNumber, FreenetURI.EMPTY_CHK_URI, ctx,
cb, metadata, (int)origSize, -1, getCHKOnly);
+ SingleBlockInserter dataPutter = new
SingleBlockInserter(parent, data, codecNumber, FreenetURI.EMPTY_CHK_URI, ctx,
cb, metadata, (int)origSize, -1, getCHKOnly, true);
Metadata meta = new
Metadata(Metadata.SIMPLE_REDIRECT, dataPutter.getURI(), block.clientMetadata);
cb.onMetadata(meta, this);
cb.onTransition(this, dataPutter);
@@ -173,7 +173,7 @@
} else {
MultiPutCompletionCallback mcb =
new MultiPutCompletionCallback(cb,
parent);
- SingleBlockInserter dataPutter = new
SingleBlockInserter(parent, data, codecNumber, FreenetURI.EMPTY_CHK_URI, ctx,
mcb, metadata, (int)origSize, -1, getCHKOnly);
+ SingleBlockInserter dataPutter = new
SingleBlockInserter(parent, data, codecNumber, FreenetURI.EMPTY_CHK_URI, ctx,
mcb, metadata, (int)origSize, -1, getCHKOnly, true);
Metadata meta = new
Metadata(Metadata.SIMPLE_REDIRECT, dataPutter.getURI(), block.clientMetadata);
Bucket metadataBucket;
try {
@@ -181,7 +181,7 @@
} catch (IOException e) {
throw new
InserterException(InserterException.BUCKET_ERROR, e, null);
}
- SingleBlockInserter metaPutter = new
SingleBlockInserter(parent, metadataBucket, (short) -1, block.desiredURI, ctx,
mcb, true, (int)origSize, -1, getCHKOnly);
+ SingleBlockInserter metaPutter = new
SingleBlockInserter(parent, metadataBucket, (short) -1, block.desiredURI, ctx,
mcb, true, (int)origSize, -1, getCHKOnly, true);
mcb.addURIGenerator(metaPutter);
mcb.add(dataPutter);
cb.onTransition(this, mcb);
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -239,6 +239,7 @@
for(int i=0;i<segments.length;i++) {
segments[i].schedule();
}
+ parent.notifyClients();
}
public void cancel() {
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -314,12 +314,12 @@
try {
for(int i=0;i<dataBlocks.length;i++) {
dataBlockStatus[i] =
- new
SingleFileFetcher(parentFetcher.parent, this, null, dataBlocks[i],
blockFetchContext, archiveContext, blockFetchContext.maxSplitfileBlockRetries,
recursionLevel, true, new Integer(i));
+ new
SingleFileFetcher(parentFetcher.parent, this, null, dataBlocks[i],
blockFetchContext, archiveContext, blockFetchContext.maxSplitfileBlockRetries,
recursionLevel, true, new Integer(i), true);
dataBlockStatus[i].schedule();
}
for(int i=0;i<checkBlocks.length;i++) {
checkBlockStatus[i] =
- new
SingleFileFetcher(parentFetcher.parent, this, null, checkBlocks[i],
blockFetchContext, archiveContext, blockFetchContext.maxSplitfileBlockRetries,
recursionLevel, true, new Integer(dataBlocks.length+i));
+ new
SingleFileFetcher(parentFetcher.parent, this, null, checkBlocks[i],
blockFetchContext, archiveContext, blockFetchContext.maxSplitfileBlockRetries,
recursionLevel, true, new Integer(dataBlocks.length+i), false);
checkBlockStatus[i].schedule();
}
} catch (MalformedURLException e) {
Modified: trunk/freenet/src/freenet/client/async/SplitFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserter.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserter.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -101,6 +101,7 @@
segNo++;
}
}
+ parent.notifyClients();
return (SplitFileInserterSegment[]) segs.toArray(new
SplitFileInserterSegment[segs.size()]);
}
Modified: trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -45,13 +45,15 @@
dataURIs = new FreenetURI[origDataBlocks.length];
dataBlockInserters = new SingleBlockInserter[dataBlocks.length];
checkBlockInserters = new
SingleBlockInserter[checkBlocks.length];
+ parent.parent.addBlocks(dataURIs.length+checkURIs.length);
+ parent.parent.addMustSucceedBlocks(dataURIs.length);
this.segNo = segNo;
}
public void start() throws InserterException {
for(int i=0;i<dataBlockInserters.length;i++) {
dataBlockInserters[i] =
- new SingleBlockInserter(parent.parent,
dataBlocks[i], (short)-1, FreenetURI.EMPTY_CHK_URI, blockInsertContext, this,
false, ClientCHKBlock.DATA_LENGTH, i, getCHKOnly);
+ new SingleBlockInserter(parent.parent,
dataBlocks[i], (short)-1, FreenetURI.EMPTY_CHK_URI, blockInsertContext, this,
false, ClientCHKBlock.DATA_LENGTH, i, getCHKOnly, false);
dataBlockInserters[i].schedule();
}
if(splitfileAlgo == null) {
@@ -80,7 +82,7 @@
// Start the inserts
for(int i=0;i<checkBlockInserters.length;i++) {
checkBlockInserters[i] =
- new SingleBlockInserter(parent.parent,
checkBlocks[i], (short)-1, FreenetURI.EMPTY_CHK_URI, blockInsertContext, this,
false, ClientCHKBlock.DATA_LENGTH, i + dataBlocks.length, getCHKOnly);
+ new SingleBlockInserter(parent.parent,
checkBlocks[i], (short)-1, FreenetURI.EMPTY_CHK_URI, blockInsertContext, this,
false, ClientCHKBlock.DATA_LENGTH, i + dataBlocks.length, getCHKOnly, false);
checkBlockInserters[i].schedule();
}
} catch (IOException e) {
Modified: trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
2006-01-26 21:23:37 UTC (rev 7940)
+++ trunk/freenet/src/freenet/client/events/SplitfileProgressEvent.java
2006-01-26 22:07:23 UTC (rev 7941)
@@ -8,19 +8,19 @@
public final int fetchedBlocks;
public final int failedBlocks;
public final int fatallyFailedBlocks;
- public final int runningBlocks;
+ public final int minSuccessfulBlocks;
public SplitfileProgressEvent(int totalBlocks, int fetchedBlocks, int
failedBlocks,
- int fatallyFailedBlocks, int runningBlocks) {
+ int fatallyFailedBlocks, int minSuccessfulBlocks) {
this.totalBlocks = totalBlocks;
this.fetchedBlocks = fetchedBlocks;
this.failedBlocks = failedBlocks;
this.fatallyFailedBlocks = fatallyFailedBlocks;
- this.runningBlocks = runningBlocks;
+ this.minSuccessfulBlocks = minSuccessfulBlocks;
}
public String getDescription() {
- return "Completed
"+(100*(fetchedBlocks+failedBlocks+fatallyFailedBlocks)/totalBlocks)+"%
"+fetchedBlocks+"/"+totalBlocks+" (failed "+failedBlocks+", fatally
"+fatallyFailedBlocks+", running "+runningBlocks+")";
+ return "Completed
"+(100*(fetchedBlocks+failedBlocks+fatallyFailedBlocks)/minSuccessfulBlocks)+"%
"+fetchedBlocks+"/"+totalBlocks+" (failed "+failedBlocks+", fatally
"+fatallyFailedBlocks+", need "+minSuccessfulBlocks+", total "+totalBlocks+")";
}
public int getCode() {
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-01-26 21:23:37 UTC (rev
7940)
+++ trunk/freenet/src/freenet/node/Version.java 2006-01-26 22:07:23 UTC (rev
7941)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 392;
+ public static final int buildNumber = 393;
/** Oldest build of Fred we will talk to */
public static final int lastGoodBuild = 392;