Author: j16sdiz
Date: 2008-08-10 09:58:14 +0000 (Sun, 10 Aug 2008)
New Revision: 21701
Modified:
branches/saltedhashstore/freenet/src/freenet/node/Node.java
branches/saltedhashstore/freenet/src/freenet/store/StoreCallback.java
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
Log:
Remove SaltedHashFreenetStore dependancy on Node
Modified: branches/saltedhashstore/freenet/src/freenet/node/Node.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/Node.java 2008-08-10
09:52:19 UTC (rev 21700)
+++ branches/saltedhashstore/freenet/src/freenet/node/Node.java 2008-08-10
09:58:14 UTC (rev 21701)
@@ -3,6 +3,7 @@
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -119,7 +120,6 @@
import freenet.support.io.FileUtil;
import freenet.support.io.NativeThread;
import freenet.support.transport.ip.HostnameSyntaxException;
-import java.io.FileFilter;
/**
* @author amphibian
@@ -1434,32 +1434,32 @@
System.out.println("Initializing CHK Datastore
(" + maxStoreKeys + " keys)");
chkDatastore = new CHKStore();
SaltedHashFreenetStore chkDataFS =
SaltedHashFreenetStore.construct(storeDir, "CHK-store",
- chkDatastore, random, this,
maxStoreKeys, 0x4800000, true, shutdownHook);
+ chkDatastore, random, maxStoreKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing CHK
Datacache");
System.out.println("Initializing CHK Datacache
(" + maxCacheKeys + ':' + maxCacheKeys + " keys)");
chkDatacache = new CHKStore();
SaltedHashFreenetStore chkCacheFS =
SaltedHashFreenetStore.construct(storeDir, "CHK-cache",
- chkDatacache, random, this,
maxCacheKeys, 0x4800000, true, shutdownHook);
+ chkDatacache, random, maxCacheKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing pubKey
Datastore");
System.out.println("Initializing pubKey
Datastore");
pubKeyDatastore = new PubkeyStore();
SaltedHashFreenetStore pubkeyDataFS =
SaltedHashFreenetStore.construct(storeDir, "PUBKEY-store",
- pubKeyDatastore, random, this,
maxStoreKeys, 0x4800000, true, shutdownHook);
+ pubKeyDatastore, random, maxStoreKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing pubKey
Datacache");
System.out.println("Initializing pubKey
Datacache (" + maxCacheKeys + " keys)");
pubKeyDatacache = new PubkeyStore();
SaltedHashFreenetStore pubkeyCacheFS =
SaltedHashFreenetStore.construct(storeDir, "PUBKEY-cache",
- pubKeyDatacache, random, this,
maxCacheKeys, 0x4800000, true, shutdownHook);
+ pubKeyDatacache, random, maxCacheKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing SSK
Datastore");
System.out.println("Initializing SSK
Datastore");
sskDatastore = new SSKStore(this);
SaltedHashFreenetStore sskDataFS =
SaltedHashFreenetStore.construct(storeDir, "SSK-store",
- sskDatastore, random, this,
maxStoreKeys, 0x4800000, true, shutdownHook);
+ sskDatastore, random, maxStoreKeys,
0x4800000, true, shutdownHook);
Logger.normal(this, "Initializing SSK
Datacache");
System.out.println("Initializing SSK Datacache
(" + maxCacheKeys + " keys)");
sskDatacache = new SSKStore(this);
SaltedHashFreenetStore sskCacheFS =
SaltedHashFreenetStore.construct(storeDir, "SSK-cache",
- sskDatacache, random, this,
maxCacheKeys, 0x4800000, true, shutdownHook);
+ sskDatacache, random, maxCacheKeys,
0x4800000, true, shutdownHook);
File migrationFile = new File(storeDir,
"migrated");
if (!migrationFile.exists()) {
@@ -1695,7 +1695,16 @@
clientCore = new NodeClientCore(this, config, nodeConfig,
nodeDir, getDarknetPortNumber(), sortOrder, oldConfig, fproxyConfig, toadlets);
netid = new NetworkIDManager(this);
-
+
+ if (storeType.equals("salt-hash")) {
+ ((SaltedHashFreenetStore)
chkDatastore.getStore()).setUserAlertManager(clientCore.alerts);
+ ((SaltedHashFreenetStore)
chkDatacache.getStore()).setUserAlertManager(clientCore.alerts);
+ ((SaltedHashFreenetStore)
pubKeyDatastore.getStore()).setUserAlertManager(clientCore.alerts);
+ ((SaltedHashFreenetStore)
pubKeyDatacache.getStore()).setUserAlertManager(clientCore.alerts);
+ ((SaltedHashFreenetStore)
sskDatastore.getStore()).setUserAlertManager(clientCore.alerts);
+ ((SaltedHashFreenetStore)
sskDatacache.getStore()).setUserAlertManager(clientCore.alerts);
+ }
+
nodeConfig.register("disableHangCheckers", false, sortOrder++,
true, false, "Node.disableHangCheckers", "Node.disableHangCheckersLong", new
BooleanCallback() {
public boolean get() {
Modified: branches/saltedhashstore/freenet/src/freenet/store/StoreCallback.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/store/StoreCallback.java
2008-08-10 09:52:19 UTC (rev 21700)
+++ branches/saltedhashstore/freenet/src/freenet/store/StoreCallback.java
2008-08-10 09:58:14 UTC (rev 21701)
@@ -42,6 +42,10 @@
this.store = store;
}
+ public FreenetStore getStore() {
+ return store;
+ }
+
// Reconstruction
/** Construct a StorableBlock from the data, headers, and optionally
routing key or full key.
Modified:
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
2008-08-10 09:52:19 UTC (rev 21700)
+++
branches/saltedhashstore/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
2008-08-10 09:58:14 UTC (rev 21701)
@@ -30,9 +30,9 @@
import freenet.keys.KeyVerifyException;
import freenet.l10n.L10n;
-import freenet.node.Node;
import freenet.node.SemiOrderedShutdownHook;
import freenet.node.useralerts.UserAlert;
+import freenet.node.useralerts.UserAlertManager;
import freenet.store.FreenetStore;
import freenet.store.KeyCollisionException;
import freenet.store.StorableBlock;
@@ -75,23 +75,21 @@
private final int fullKeyLength;
private final int dataBlockLength;
private final Random random;
- private final Node node;
+ private UserAlertManager userAlertManager;
private long storeSize;
private int generation;
private int flags;
public static SaltedHashFreenetStore construct(File baseDir, String
name, StoreCallback callback, Random random,
- Node node, long maxKeys, int bloomFilterSize, boolean
bloomCounting, SemiOrderedShutdownHook shutdownHook)
+ long maxKeys, int bloomFilterSize, boolean bloomCounting,
SemiOrderedShutdownHook shutdownHook)
throws IOException {
- return new SaltedHashFreenetStore(baseDir, name, callback,
random, node, maxKeys, bloomFilterSize,
- bloomCounting,
+ return new SaltedHashFreenetStore(baseDir, name, callback,
random, maxKeys, bloomFilterSize, bloomCounting,
shutdownHook);
}
- private SaltedHashFreenetStore(File baseDir, String name, StoreCallback
callback, Random random, Node node,
- long maxKeys, int bloomFilterSize, boolean bloomCounting,
SemiOrderedShutdownHook shutdownHook)
- throws IOException {
+ private SaltedHashFreenetStore(File baseDir, String name, StoreCallback
callback, Random random, long maxKeys,
+ int bloomFilterSize, boolean bloomCounting,
SemiOrderedShutdownHook shutdownHook) throws IOException {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
@@ -106,7 +104,6 @@
dataBlockLength = callback.dataLength();
this.random = random;
- this.node = node;
storeSize = maxKeys;
this.bloomFilterSize = bloomFilterSize;
@@ -141,6 +138,7 @@
shutdownHook.addEarlyJob(new Thread(new ShutdownDB()));
cleanerThread = new Cleaner();
+ cleanerStatusUserAlert = new
CleanerStatusUserAlert(cleanerThread);
// finish all resizing before continue
if (prevStoreSize != 0 && cleanerGlobalLock.tryLock()) {
@@ -857,7 +855,8 @@
private Condition cleanerCondition = cleanerLock.newCondition();
private static Lock cleanerGlobalLock = new ReentrantLock(); // global
across all datastore
private Cleaner cleanerThread;
-
+ private CleanerStatusUserAlert cleanerStatusUserAlert;
+
private final Entry NOT_MODIFIED = new Entry();
private interface BatchProcessor {
@@ -898,89 +897,11 @@
super.run();
try {
- while (node != null && node.clientCore == null
&& !shutdown) {
- Thread.sleep(1000);
- }
Thread.sleep((int)(CLEANER_PERIOD / 2 +
CLEANER_PERIOD * Math.random()));
} catch (InterruptedException e){}
if (shutdown)
return;
-
- if (node != null)
- node.clientCore.alerts.register(new UserAlert() {
- public String anchor() {
- return "store-cleaner-" + name;
- }
-
- public String dismissButtonText() {
- return L10n.getString("UserAlert.hide");
- }
-
- public HTMLNode getHTMLText() {
- return new HTMLNode("#", getText());
- }
-
- public short getPriorityClass() {
- return UserAlert.MINOR;
- }
-
- public String getShortText() {
- if (isResizing)
- return
L10n.getString("SaltedHashFreenetStore.shortResizeProgress", //
- new String[] { "name",
"processed", "total" },//
- new String[] { name,
(entriesTotal - entriesLeft) + "", entriesTotal + "" });
- else
- return
L10n.getString("SaltedHashFreenetStore.shortRebuildProgress", //
- new String[] { "name",
"processed", "total" },//
- new String[] { name,
(entriesTotal - entriesLeft) + "", entriesTotal + "" });
- }
-
- public String getText() {
- if (isResizing)
- return
L10n.getString("SaltedHashFreenetStore.longResizeProgress", //
- new String[] { "name",
"processed", "total" },//
- new String[] { name,
(entriesTotal - entriesLeft) + "", entriesTotal + "" });
- else
- return
L10n.getString("SaltedHashFreenetStore.longRebuildProgress", //
- new String[] { "name",
"processed", "total" },//
- new String[] { name,
(entriesTotal - entriesLeft) + "", entriesTotal + "" });
- }
-
- public String getTitle() {
- return
L10n.getString("SaltedHashFreenetStore.cleanerAlertTitle", //
- new String[] { "name" }, //
- new String[] { name });
- }
-
- public Object getUserIdentifier() {
- return null;
- }
-
- public boolean isValid() {
- return isRebuilding || isResizing;
- }
-
- public void isValid(boolean validity) {
- // Ignore
- }
-
- public void onDismiss() {
- // Ignore
- }
-
- public boolean shouldUnregisterOnDismiss() {
- return true;
- }
-
- public boolean userCanDismiss() {
- return false;
- }
-
- public boolean isEventNotification() {
- return false;
- }
- });
int loop = 0;
while (!shutdown) {
@@ -1420,6 +1341,95 @@
}
}
+ private final class CleanerStatusUserAlert implements UserAlert {
+ private Cleaner cleaner;
+
+ private CleanerStatusUserAlert(Cleaner cleaner) {
+ this.cleaner = cleaner;
+ }
+
+ public String anchor() {
+ return "store-cleaner-" + name;
+ }
+
+ public String dismissButtonText() {
+ return L10n.getString("UserAlert.hide");
+ }
+
+ public HTMLNode getHTMLText() {
+ return new HTMLNode("#", getText());
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.MINOR;
+ }
+
+ public String getShortText() {
+ if (cleaner.isResizing)
+ return
L10n.getString("SaltedHashFreenetStore.shortResizeProgress", //
+ new String[] { "name", "processed",
"total" },//
+ new String[] { name,
(cleaner.entriesTotal - cleaner.entriesLeft) + "",
+ cleaner.entriesTotal + "" });
+ else
+ return
L10n.getString("SaltedHashFreenetStore.shortRebuildProgress", //
+ new String[] { "name", "processed",
"total" },//
+ new String[] { name,
(cleaner.entriesTotal - cleaner.entriesLeft) + "",
+ cleaner.entriesTotal + "" });
+ }
+
+ public String getText() {
+ if (cleaner.isResizing)
+ return
L10n.getString("SaltedHashFreenetStore.longResizeProgress", //
+ new String[] { "name", "processed",
"total" },//
+ new String[] { name,
(cleaner.entriesTotal - cleaner.entriesLeft) + "",
+ cleaner.entriesTotal + "" });
+ else
+ return
L10n.getString("SaltedHashFreenetStore.longRebuildProgress", //
+ new String[] { "name", "processed",
"total" },//
+ new String[] { name,
(cleaner.entriesTotal - cleaner.entriesLeft) + "",
+ cleaner.entriesTotal + "" });
+ }
+
+ public String getTitle() {
+ return
L10n.getString("SaltedHashFreenetStore.cleanerAlertTitle", //
+ new String[] { "name" }, //
+ new String[] { name });
+ }
+
+ public Object getUserIdentifier() {
+ return null;
+ }
+
+ public boolean isValid() {
+ return cleaner.isRebuilding || cleaner.isResizing;
+ }
+
+ public void isValid(boolean validity) {
+ // Ignore
+ }
+
+ public void onDismiss() {
+ // Ignore
+ }
+
+ public boolean shouldUnregisterOnDismiss() {
+ return true;
+ }
+
+ public boolean userCanDismiss() {
+ return false;
+ }
+
+ public boolean isEventNotification() {
+ return false;
+ }
+ }
+
+ public void setUserAlertManager(UserAlertManager userAlertManager) {
+ if (cleanerStatusUserAlert != null)
+ userAlertManager.register(cleanerStatusUserAlert);
+ }
+
public void setMaxKeys(long newStoreSize, boolean shrinkNow) throws
IOException {
Logger.normal(this, "[" + name + "] Resize newStoreSize=" +
newStoreSize + ", shinkNow=" + shrinkNow);