Author: j16sdiz
Date: 2008-09-23 10:24:41 +0000 (Tue, 23 Sep 2008)
New Revision: 22755
Modified:
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
trunk/freenet/src/freenet/store/FreenetStore.java
Log:
use enum for store type
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2008-09-23 10:24:09 UTC (rev
22754)
+++ trunk/freenet/src/freenet/node/Node.java 2008-09-23 10:24:41 UTC (rev
22755)
@@ -92,11 +92,11 @@
import freenet.pluginmanager.PluginManager;
import freenet.store.BerkeleyDBFreenetStore;
import freenet.store.CHKStore;
-import freenet.store.FreenetStore;
import freenet.store.KeyCollisionException;
import freenet.store.PubkeyStore;
import freenet.store.RAMFreenetStore;
import freenet.store.SSKStore;
+import freenet.store.FreenetStore.StoreType;
import freenet.store.saltedhash.SaltedHashFreenetStore;
import freenet.support.ByteArrayWrapper;
import freenet.support.Executor;
@@ -1810,33 +1810,33 @@
Logger.normal(this, "Initializing CHK Datastore");
System.out.println("Initializing CHK Datastore
("+maxStoreKeys+" keys)");
chkDatastore = new CHKStore();
- BerkeleyDBFreenetStore.construct(storeDir, true,
suffix, maxStoreKeys, FreenetStore.TYPE_CHK,
+ BerkeleyDBFreenetStore.construct(storeDir, true,
suffix, maxStoreKeys, StoreType.CHK,
storeEnvironment, shutdownHook,
reconstructFile, chkDatastore, random);
Logger.normal(this, "Initializing CHK Datacache");
System.out.println("Initializing CHK Datacache
("+maxCacheKeys+ ':' +maxCacheKeys+" keys)");
chkDatacache = new CHKStore();
- BerkeleyDBFreenetStore.construct(storeDir, false,
suffix, maxCacheKeys, FreenetStore.TYPE_CHK,
+ BerkeleyDBFreenetStore.construct(storeDir, false,
suffix, maxCacheKeys, StoreType.CHK,
storeEnvironment, shutdownHook,
reconstructFile, chkDatacache, random);
Logger.normal(this, "Initializing pubKey Datastore");
System.out.println("Initializing pubKey Datastore");
pubKeyDatastore = new PubkeyStore();
- BerkeleyDBFreenetStore.construct(storeDir, true,
suffix, maxStoreKeys, FreenetStore.TYPE_PUBKEY,
+ BerkeleyDBFreenetStore.construct(storeDir, true,
suffix, maxStoreKeys, StoreType.PUBKEY,
storeEnvironment, shutdownHook,
reconstructFile, pubKeyDatastore, random);
Logger.normal(this, "Initializing pubKey Datacache");
System.out.println("Initializing pubKey Datacache
("+maxCacheKeys+" keys)");
pubKeyDatacache = new PubkeyStore();
- BerkeleyDBFreenetStore.construct(storeDir, false,
suffix, maxCacheKeys, FreenetStore.TYPE_PUBKEY,
+ BerkeleyDBFreenetStore.construct(storeDir, false,
suffix, maxCacheKeys, StoreType.PUBKEY,
storeEnvironment, shutdownHook,
reconstructFile, pubKeyDatacache, random);
// FIXME can't auto-fix SSK stores.
Logger.normal(this, "Initializing SSK Datastore");
System.out.println("Initializing SSK Datastore");
sskDatastore = new SSKStore(this);
- BerkeleyDBFreenetStore.construct(storeDir, true,
suffix, maxStoreKeys, FreenetStore.TYPE_SSK,
+ BerkeleyDBFreenetStore.construct(storeDir, true,
suffix, maxStoreKeys, StoreType.SSK,
storeEnvironment, shutdownHook,
reconstructFile, sskDatastore, random);
Logger.normal(this, "Initializing SSK Datacache");
System.out.println("Initializing SSK Datacache
("+maxCacheKeys+" keys)");
sskDatacache = new SSKStore(this);
- BerkeleyDBFreenetStore.construct(storeDir, false,
suffix, maxStoreKeys, FreenetStore.TYPE_SSK,
+ BerkeleyDBFreenetStore.construct(storeDir, false,
suffix, maxStoreKeys, StoreType.SSK,
storeEnvironment, shutdownHook,
reconstructFile, sskDatacache, random);
} catch (FileNotFoundException e1) {
String msg = "Could not open datastore: "+e1;
Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2008-09-23
10:24:09 UTC (rev 22754)
+++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2008-09-23
10:24:41 UTC (rev 22755)
@@ -96,20 +96,19 @@
private boolean closed;
private boolean reallyClosed;
- public static String getName(boolean isStore, short type) {
+ public static String getName(boolean isStore, StoreType type) {
String newDBPrefix = typeName(type)+ '-' +(isStore ? "store" :
"cache")+ '-';
return newDBPrefix + "CHK";
}
- public static File getFile(boolean isStore, short type, File
baseStoreDir, String suffix) {
+ public static File getFile(boolean isStore, StoreType type, File
baseStoreDir, String suffix) {
String newStoreFileName = typeName(type) + suffix + '.' +
(isStore ? "store" : "cache");
return new File(baseStoreDir, newStoreFileName);
}
- public static FreenetStore construct(File baseStoreDir, boolean
isStore, String suffix,
- long maxStoreKeys, short type,
- Environment storeEnvironment, SemiOrderedShutdownHook
storeShutdownHook, File reconstructFile,
- StoreCallback callback, RandomSource random) throws
DatabaseException, IOException {
+ public static FreenetStore construct(File baseStoreDir, boolean
isStore, String suffix, long maxStoreKeys,
+ StoreType type, Environment storeEnvironment,
SemiOrderedShutdownHook storeShutdownHook,
+ File reconstructFile, StoreCallback callback, RandomSource
random) throws DatabaseException, IOException {
// Location of new store file
String newStoreFileName = typeName(type) + suffix + '.' +
(isStore ? "store" : "cache");
File newStoreFile = new File(baseStoreDir, newStoreFileName);
@@ -155,15 +154,8 @@
}
}
- private static String typeName(short type) {
- if(type == TYPE_CHK)
- return "chk";
- else if(type == TYPE_SSK)
- return "ssk";
- else if(type == TYPE_PUBKEY)
- return "pubkey";
- else
- throw new RuntimeException("No such type: " + type);
+ private static String typeName(StoreType type) {
+ return type.toString().toLowerCase();
}
/**
Modified: trunk/freenet/src/freenet/store/FreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/FreenetStore.java 2008-09-23 10:24:09 UTC
(rev 22754)
+++ trunk/freenet/src/freenet/store/FreenetStore.java 2008-09-23 10:24:41 UTC
(rev 22755)
@@ -8,11 +8,10 @@
* Datastore interface
*/
public interface FreenetStore {
+ public enum StoreType {
+ CHK, PUBKEY, SSK
+ };
- public static final short TYPE_CHK = 0;
- public static final short TYPE_PUBKEY = 1;
- public static final short TYPE_SSK = 2;
-
/**
* Retrieve a block. Use the StoreCallback to convert it to the
appropriate type of block.
* @param routingKey The routing key i.e. the database key under which
the block is stored.