Author: toad
Date: 2008-06-18 17:25:17 +0000 (Wed, 18 Jun 2008)
New Revision: 20433
Modified:
branches/db4o/freenet/src/freenet/client/async/USKChecker.java
branches/db4o/freenet/src/freenet/client/async/USKCheckerCallback.java
branches/db4o/freenet/src/freenet/client/async/USKFetcher.java
branches/db4o/freenet/src/freenet/client/async/USKManager.java
branches/db4o/freenet/src/freenet/client/async/USKManagerPersistent.java
branches/db4o/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
branches/db4o/freenet/src/freenet/node/NodeClientCore.java
branches/db4o/freenet/src/freenet/node/fcp/SubscribeUSK.java
branches/db4o/freenet/src/freenet/node/updater/NodeUpdater.java
Log:
Fix build. Now everything builds (some plugins don't).
Modified: branches/db4o/freenet/src/freenet/client/async/USKChecker.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKChecker.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/client/async/USKChecker.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -30,7 +30,7 @@
public void onSuccess(ClientKeyBlock block, boolean fromStore, Object
token, RequestScheduler sched, ObjectContainer container, ClientContext
context) {
unregister(false);
- cb.onSuccess((ClientSSKBlock)block);
+ cb.onSuccess((ClientSSKBlock)block, context);
}
public void onFailure(LowLevelGetException e, Object token,
RequestScheduler sched, ObjectContainer container, ClientContext context) {
@@ -68,17 +68,17 @@
// Ran out of retries.
unregister(false);
if(e.code == LowLevelGetException.CANCELLED){
- cb.onCancelled();
+ cb.onCancelled(context);
return;
}else if(e.code == LowLevelGetException.DECODE_FAILED){
- cb.onFatalAuthorError();
+ cb.onFatalAuthorError(context);
return;
}
// Rest are non-fatal. If have DNFs, DNF, else network error.
if(dnfs > 0)
- cb.onDNF();
+ cb.onDNF(context);
else
- cb.onNetworkError();
+ cb.onNetworkError(context);
}
public String toString() {
Modified: branches/db4o/freenet/src/freenet/client/async/USKCheckerCallback.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKCheckerCallback.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/client/async/USKCheckerCallback.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -11,20 +11,20 @@
interface USKCheckerCallback {
/** Data Not Found */
- public void onDNF();
+ public void onDNF(ClientContext context);
/** Successfully found the latest version of the key
* @param block */
- public void onSuccess(ClientSSKBlock block);
+ public void onSuccess(ClientSSKBlock block, ClientContext context);
/** Error committed by author */
- public void onFatalAuthorError();
+ public void onFatalAuthorError(ClientContext context);
/** Network on our node or on nodes we have been talking to */
- public void onNetworkError();
+ public void onNetworkError(ClientContext context);
/** Request cancelled */
- public void onCancelled();
+ public void onCancelled(ClientContext context);
/** Get priority to run the request at */
public short getPriority();
Modified: branches/db4o/freenet/src/freenet/client/async/USKFetcher.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKFetcher.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/client/async/USKFetcher.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -19,6 +19,7 @@
import freenet.node.RequestStarter;
import freenet.support.Logger;
import freenet.support.api.Bucket;
+import freenet.support.io.BucketTools;
/**
*
@@ -116,47 +117,49 @@
this.dnf = false;
this.checker = new USKChecker(this, origUSK.getSSK(i),
ctx.maxNonSplitfileRetries, ctx, parent);
}
- public void onDNF() {
+ public void onDNF(ClientContext context) {
checker = null;
dnf = true;
- USKFetcher.this.onDNF(this);
+ USKFetcher.this.onDNF(this, context);
}
- public void onSuccess(ClientSSKBlock block) {
+ public void onSuccess(ClientSSKBlock block, ClientContext
context) {
checker = null;
succeeded = true;
- USKFetcher.this.onSuccess(this, false, block);
+ USKFetcher.this.onSuccess(this, false, block, context);
}
- public void onFatalAuthorError() {
+ public void onFatalAuthorError(ClientContext context) {
checker = null;
// Counts as success except it doesn't update
- USKFetcher.this.onSuccess(this, true, null);
+ USKFetcher.this.onSuccess(this, true, null, context);
}
- public void onNetworkError() {
+ public void onNetworkError(ClientContext context) {
checker = null;
// Not a DNF
- USKFetcher.this.onFail(this);
+ USKFetcher.this.onFail(this, context);
}
- public void onCancelled() {
+ public void onCancelled(ClientContext context) {
checker = null;
- USKFetcher.this.onCancelled(this);
+ USKFetcher.this.onCancelled(this, context);
}
- public void cancel() {
+ public void cancel(ObjectContainer container, ClientContext
context) {
+ assert(container == null);
cancelled = true;
if(checker != null)
- checker.cancel();
- onCancelled();
+ checker.cancel(container, context);
+ onCancelled(context);
}
- public void schedule() {
+ public void schedule(ObjectContainer container, ClientContext
context) {
+ assert(container == null);
if(checker == null) {
if(logMINOR)
Logger.minor(this, "Checker == null in
schedule() for "+this, new Exception("debug"));
} else
- checker.schedule();
+ checker.schedule(container, context);
}
public String toString() {
@@ -231,7 +234,7 @@
logMINOR = Logger.shouldLog(Logger.MINOR, this);
}
- void onDNF(USKAttempt att) {
+ void onDNF(USKAttempt att, ClientContext context) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR) Logger.minor(this, "DNF: "+att);
boolean finished = false;
@@ -248,11 +251,11 @@
} else if(logMINOR) Logger.minor(this, "Remaining:
"+runningAttempts.size());
}
if(finished) {
- finishSuccess();
+ finishSuccess(context);
}
}
- private void finishSuccess() {
+ private void finishSuccess(ClientContext context) {
if(backgroundPoll) {
long valAtEnd = uskManager.lookup(origUSK);
long end;
@@ -264,7 +267,7 @@
int newSleepTime = sleepTime * 2;
if(newSleepTime > maxSleepTime) newSleepTime =
maxSleepTime;
sleepTime = newSleepTime;
- end = now + ctx.random.nextInt(sleepTime);
+ end = now + context.random.nextInt(sleepTime);
if(valAtEnd > valueAtSchedule) {
// We have advanced; keep trying as if
we just started.
@@ -279,7 +282,7 @@
minFailures = newMinFailures;
}
}
- schedule(end-now);
+ schedule(end-now, null, context);
} else {
long ed = uskManager.lookup(origUSK);
USKFetcherCallback[] cb;
@@ -287,12 +290,23 @@
completed = true;
cb = (USKFetcherCallback[])
callbacks.toArray(new USKFetcherCallback[callbacks.size()]);
}
+ byte[] data;
+ if(lastRequestData == null)
+ data = null;
+ else {
+ try {
+ data =
BucketTools.toByteArray(lastRequestData);
+ } catch (IOException e) {
+ Logger.error(this, "Unable to turn
lastRequestData into byte[]: caught I/O exception: "+e, e);
+ data = null;
+ }
+ }
for(int i=0;i<cb.length;i++)
- cb[i].onFoundEdition(ed, origUSK.copy(ed));
+ cb[i].onFoundEdition(ed, origUSK.copy(ed),
null, context, lastWasMetadata, lastCompressionCodec, data);
}
}
- void onSuccess(USKAttempt att, boolean dontUpdate, ClientSSKBlock
block) {
+ void onSuccess(USKAttempt att, boolean dontUpdate, ClientSSKBlock
block, final ClientContext context) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
LinkedList l = null;
final long lastEd = uskManager.lookup(origUSK);
@@ -315,7 +329,7 @@
l.add(add(i));
}
}
- cancelBefore(curLatest);
+ cancelBefore(curLatest, context);
}
Bucket data = null;
if(decode) {
@@ -338,12 +352,12 @@
}
}
if(!dontUpdate)
- uskManager.update(origUSK, curLatest);
+ uskManager.update(origUSK, curLatest, context);
if(l == null) return;
final LinkedList toSched = l;
// If we schedule them here, we don't get icky recursion
problems.
if(!cancelled) {
- ctx.executor.execute(new Runnable() {
+ context.mainExecutor.execute(new Runnable() {
public void run() {
long last = lastEd;
for(Iterator
i=toSched.iterator();i.hasNext();) {
@@ -352,7 +366,7 @@
USKAttempt a = (USKAttempt)
i.next();
last =
uskManager.lookup(origUSK);
if((last <= a.number) &&
!a.cancelled)
- a.schedule();
+ a.schedule(null,
context);
else {
synchronized(this) {
runningAttempts.remove(a);
@@ -364,35 +378,35 @@
}
}
- public void onCancelled(USKAttempt att) {
+ void onCancelled(USKAttempt att, ClientContext context) {
synchronized(this) {
runningAttempts.remove(att);
if(!runningAttempts.isEmpty()) return;
if(cancelled)
- finishCancelled();
+ finishCancelled(context);
}
}
- private void finishCancelled() {
+ private void finishCancelled(ClientContext context) {
USKFetcherCallback[] cb;
synchronized(this) {
completed = true;
cb = (USKFetcherCallback[]) callbacks.toArray(new
USKFetcherCallback[callbacks.size()]);
}
for(int i=0;i<cb.length;i++)
- cb[i].onCancelled();
+ cb[i].onCancelled(null, context);
}
- public void onFail(USKAttempt attempt) {
+ public void onFail(USKAttempt attempt, ClientContext context) {
// FIXME what else can we do?
// Certainly we don't want to continue fetching indefinitely...
// ... e.g. RNFs don't indicate we should try a later slot,
none of them
// really do.
- onDNF(attempt);
+ onDNF(attempt, context);
}
- private void cancelBefore(long curLatest) {
+ private void cancelBefore(long curLatest, ClientContext context) {
Vector v = null;
int count = 0;
synchronized(this) {
@@ -409,7 +423,7 @@
if(v != null) {
for(int i=0;i<v.size();i++) {
USKAttempt att = (USKAttempt) v.get(i);
- att.cancel();
+ att.cancel(null, context);
}
}
}
@@ -449,13 +463,14 @@
return origUSK;
}
- public void schedule(long delay, ObjectContainer container,
ClientContext context) {
+ public void schedule(long delay, ObjectContainer container, final
ClientContext context) {
+ assert(container == null);
if (delay<=0) {
schedule(container, context);
} else {
uskManager.ticker.queueTimedJob(new Runnable() {
public void run() {
- USKFetcher.this.schedule();
+ USKFetcher.this.schedule(null, context);
}
}, delay);
}
@@ -480,7 +495,7 @@
if(keepLastData && lastEd == lookedUp)
lastEd--; // If we want the data, then
get it for the known edition, so we always get the data, so USKInserter can
compare it and return the old edition if it is identical.
if(attempts[i].number > lastEd)
- attempts[i].schedule();
+ attempts[i].schedule(container,
context);
else {
synchronized(this) {
runningAttempts.remove(attempts[i]);
@@ -490,14 +505,15 @@
}
}
- public void cancel() {
+ public void cancel(ObjectContainer container, ClientContext context) {
+ assert(container == null);
USKAttempt[] attempts;
synchronized(this) {
cancelled = true;
attempts = (USKAttempt[]) runningAttempts.toArray(new
USKAttempt[runningAttempts.size()]);
}
for(int i=0;i<attempts.length;i++)
- attempts[i].cancel();
+ attempts[i].cancel(container, context);
uskManager.onCancelled(this);
}
@@ -546,14 +562,14 @@
return !subscribers.isEmpty();
}
- public void removeSubscriber(USKCallback cb) {
+ public void removeSubscriber(USKCallback cb, ClientContext context) {
boolean kill = false;
synchronized(this) {
subscribers.remove(cb);
if(!(subscribers.isEmpty() && killOnLoseSubscribers))
kill = true;
}
updatePriorities();
- if(kill) cancel();
+ if(kill) cancel(null, context);
}
public synchronized boolean hasLastData() {
Modified: branches/db4o/freenet/src/freenet/client/async/USKManager.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKManager.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/client/async/USKManager.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -48,6 +48,8 @@
final Ticker ticker;
+ private ClientContext context;
+
public USKManager(NodeClientCore core) {
backgroundFetchContext =
core.makeClient(RequestStarter.UPDATE_PRIORITY_CLASS).getFetchContext();
backgroundFetchContext.followRedirects = false;
@@ -61,6 +63,11 @@
ticker = core.getTicker();
}
+ public void init(ObjectContainer container, ClientContext context) {
+ this.context = context;
+ USKManagerPersistent.init(this, container, context);
+ }
+
/**
* Look up the latest known version of the given USK.
* @return The latest known edition number, or -1.
@@ -132,7 +139,7 @@
if(toCancel != null) {
for(int i=0;i<toCancel.size();i++) {
USKFetcher fetcher = (USKFetcher)
toCancel.get(i);
- fetcher.cancel();
+ fetcher.cancel(null, context);
}
}
if(sched != null) sched.schedule(null, context);
@@ -171,7 +178,7 @@
* updated. Note that this does not imply that the USK will be
* checked on a regular basis, unless runBackgroundFetch=true.
*/
- public void subscribe(USK origUSK, USKCallback cb, boolean
runBackgroundFetch, RequestClient client, final ClientContext context) {
+ public void subscribe(USK origUSK, USKCallback cb, boolean
runBackgroundFetch, RequestClient client) {
if(client.persistent()) throw new
UnsupportedOperationException("USKManager subscriptions cannot be persistent");
USKFetcher sched = null;
long ed = origUSK.suggestedEdition;
@@ -249,7 +256,7 @@
else
Logger.error(this,
"Unsubscribing "+cb+" for "+origUSK+" but not already subscribed, remaining
"+newCallbacks.length+" callbacks", new Exception("error"));
} else {
- f.removeSubscriber(cb);
+ f.removeSubscriber(cb, context);
if(!f.hasSubscribers()) {
if(!temporaryBackgroundFetchersLRU.contains(clear)) {
toCancel = f;
@@ -259,7 +266,7 @@
}
}
}
- if(toCancel != null) toCancel.cancel();
+ if(toCancel != null) toCancel.cancel(null, context);
}
/**
@@ -272,9 +279,9 @@
* @param fctx Fetcher context for actually fetching the keys. Not used
by the USK polling.
* @return
*/
- public USKRetriever subscribeContent(USK origUSK, USKRetrieverCallback
cb, boolean runBackgroundFetch, FetchContext fctx, short prio, RequestClient
client, ClientContext context) {
+ public USKRetriever subscribeContent(USK origUSK, USKRetrieverCallback
cb, boolean runBackgroundFetch, FetchContext fctx, short prio, RequestClient
client) {
USKRetriever ret = new USKRetriever(fctx, prio, client, cb);
- subscribe(origUSK, ret, runBackgroundFetch, client, context);
+ subscribe(origUSK, ret, runBackgroundFetch, client);
return ret;
}
Modified:
branches/db4o/freenet/src/freenet/client/async/USKManagerPersistent.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKManagerPersistent.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/client/async/USKManagerPersistent.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -11,7 +11,7 @@
*/
public class USKManagerPersistent {
- public static void init(USKManager manager, ObjectContainer container,
final ClientContext context) {
+ static void init(USKManager manager, ObjectContainer container, final
ClientContext context) {
ObjectSet set = container.query(new Predicate() {
public boolean match(USKFetcherTag tag) {
return tag.nodeDBHandle == context.nodeDBHandle;
Modified:
branches/db4o/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
---
branches/db4o/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
2008-06-18 11:00:08 UTC (rev 20432)
+++
branches/db4o/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -95,7 +95,7 @@
private class USKUpdatedCallback implements USKCallback {
- public void onFoundEdition(long edition, USK key,
ObjectContainer container, ClientContext context) {
+ public void onFoundEdition(long edition, USK key,
ObjectContainer container, ClientContext context, boolean wasMetadata, short
codec, byte[] data) {
BookmarkItems items = MAIN_CATEGORY.getAllItems();
for(int i = 0; i < items.size(); i++) {
if(!"USK".equals(items.get(i).getKeyType()))
Modified: branches/db4o/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/NodeClientCore.java 2008-06-18
11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/node/NodeClientCore.java 2008-06-18
17:25:17 UTC (rev 20433)
@@ -297,7 +297,7 @@
Logger.normal(this, "Initializing USK Manager");
System.out.println("Initializing USK Manager");
uskManager = new USKManager(this);
- USKManagerPersistent.init(uskManager, container, clientContext);
+ uskManager.init(container, clientContext);
healingQueue = new
SimpleHealingQueue(requestStarters.chkPutScheduler,
new InsertContext(tempBucketFactory,
tempBucketFactory, persistentTempBucketFactory,
Modified: branches/db4o/freenet/src/freenet/node/fcp/SubscribeUSK.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/SubscribeUSK.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/node/fcp/SubscribeUSK.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -27,7 +27,7 @@
core.uskManager.subscribe(message.key, this, !message.dontPoll,
handler.getRebootClient().lowLevelClient);
}
- public void onFoundEdition(long l, USK key, ObjectContainer container,
ClientContext context) {
+ public void onFoundEdition(long l, USK key, ObjectContainer container,
ClientContext context, boolean wasMetadata, short codec, byte[] data) {
if(handler.isClosed()) {
core.uskManager.unsubscribe(key, this, !dontPoll);
return;
Modified: branches/db4o/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/updater/NodeUpdater.java
2008-06-18 11:00:08 UTC (rev 20432)
+++ branches/db4o/freenet/src/freenet/node/updater/NodeUpdater.java
2008-06-18 17:25:17 UTC (rev 20433)
@@ -85,7 +85,7 @@
}
}
- public synchronized void onFoundEdition(long l, USK key,
ObjectContainer container, ClientContext context){
+ public synchronized void onFoundEdition(long l, USK key,
ObjectContainer container, ClientContext context, boolean wasMetadata, short
codec, byte[] data) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR) Logger.minor(this, "Found edition "+l);
System.err.println("Found "+(extUpdate?"freenet-ext.jar " :
"")+"update edition "+l);