SimpleSingleFileFetcher(ClientKey key, int maxRetries, FetchContext ctx, ClientRequester parent, GetCompletionCallback rcb, boolean isEssential, boolean dontAdd, long l, ClientContext context, boolean deleteFetchContext, boolean realTimeFlag) { super(key, maxRetries, ctx, parent, deleteFetchContext, realTimeFlag); this.rcb = rcb; this.token = l; if(!dontAdd) { if(isEssential) parent.addMustSucceedBlocks(1); else parent.addBlock(); parent.notifyClients(context); } }
@Override public void setSplitfileBlocks(int requiredBlocks, int remainingBlocks) { parent.addMustSucceedBlocks(requiredBlocks); parent.addBlocks(remainingBlocks); parent.notifyClients(context); }
@Override public void onResume(int succeededBlocks, int failedBlocks, ClientMetadata meta, long finalSize) { for(int i=0;i<succeededBlocks-1;i++) parent.completedBlock(true, context); if(succeededBlocks > 0) parent.completedBlock(false, context); for(int i=0;i<failedBlocks-1;i++) parent.failedBlock(true, context); if(failedBlocks > 0) parent.failedBlock(false, context); parent.blockSetFinalized(context); try { cb.onExpectedMIME(meta, context); } catch (FetchException e) { fail(e); return; } cb.onExpectedSize(finalSize, context); }
nf.setMaximumFractionDigits(0); nf.setMinimumIntegerDigits(2); ClientRequester[] requests = ClientRequester.getAll(); Arrays.sort(requests, new Comparator<ClientRequester>() { @Override long now = System.currentTimeMillis(); for(ClientRequester request : requests) { if(request.isFinished() || request.isCancelled()) continue; row = table.addChild("tr"); RequestClient client = request.getClient(); row.addChild("td", client.toString()); try { sb.append(TimeUtil.formatTime(diff, 2)); row.addChild("td", sb.toString()); row.addChild("td", Short.toString(request.getPriorityClass())); row.addChild("td", client==null ? "?" : Boolean.toString(client.realTimeFlag())); FreenetURI uri = request.getURI(); // getURI() sometimes returns null, eg for ClientPutters row.addChild("td", uri == null ? "null" : uri.toString());
protected void onFailure(FetchException e, boolean forceFatal, ClientContext context) { if(logMINOR) Logger.minor(this, "onFailure( "+e+" , "+forceFatal+")", e); if(parent.isCancelled() || cancelled) { if(logMINOR) Logger.minor(this, "Failing: cancelled"); e = new FetchException(FetchExceptionMode.CANCELLED); forceFatal = true; } if(!(e.isFatal() || forceFatal) ) { if(retry(context)) { if(logMINOR) Logger.minor(this, "Retrying"); return; } } // :( unregisterAll(context); synchronized(this) { finished = true; } if(e.isFatal() || forceFatal) parent.fatallyFailedBlock(context); else parent.failedBlock(context); rcb.onFailure(e, this, context); }
/** Called by onResume() once and only once after restarting. Must be overridden, and must call * super.innerOnResume(). * @throws ResumeFailedException */ protected void innerOnResume(ClientContext context) throws ResumeFailedException { ClientBaseCallback cb = getCallback(); client = cb.getRequestClient(); assert(client.persistent()); if(sentToNetwork) innerToNetwork(context); }
context.uskManager.getFetcher(usk.copy(usk.suggestedEdition), ctx, false, requester.persistent(), realTimeFlag, new MyUSKFetcherCallback(requester, cb, usk, metaStrings, ctx, actx, realTimeFlag, maxRetries, recursionLevel, dontTellClientGet, l, requester.persistent(), true), false, context, true); if(isEssential) requester.addMustSucceedBlocks(1); return tag; new USKProxyCompletionCallback(usk, cb, requester.persistent()); context.uskManager.getFetcher(usk.copy(-usk.suggestedEdition), ctx, false, requester.persistent(), realTimeFlag, new MyUSKFetcherCallback(requester, cb, usk, metaStrings, ctx, actx, realTimeFlag, maxRetries, recursionLevel, dontTellClientGet, l, requester.persistent(), false), false, context, false); if(isEssential) requester.addMustSucceedBlocks(1); return tag;
void startWithMetadata(Bucket data, ClientContext context) { parent.completedBlock(true, context); handleMetadata(data, context); }
/** A block failed. Count it and notify our clients. */ public void failedBlock(ClientContext context) { failedBlock(false, context); }
public void cancel(ClientContext context) { ClientRequester cr = getClientRequest(); // It might have been finished on startup. if(logMINOR) Logger.minor(this, "Cancelling "+cr+" for "+this+" persistence = "+persistence); if(cr != null) cr.cancel(context); freeData(); }
@Override public void onFetchedBlock() { boolean dontNotify = true; if(getter.hasQueued()) { dontNotify = false; } else { synchronized(this) { if(storeFetchCounter++ == STORE_NOTIFY_BLOCKS) { storeFetchCounter = 0; dontNotify = false; lastNotifiedStoreFetch = System.currentTimeMillis(); } else { long now = System.currentTimeMillis(); if(now - lastNotifiedStoreFetch >= STORE_NOTIFY_INTERVAL) { dontNotify = false; lastNotifiedStoreFetch = now; } } } } parent.completedBlock(dontNotify, context); }
@Override public void onFailedBlock() { parent.failedBlock(context); }
if(parent instanceof ClientGetter) ((ClientGetter)parent).addKeyToBinaryBlob(block, context); parent.completedBlock(fromStore, context);