mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-25 00:22:17 +00:00
Added key sorting in StorageBerkeleyDB
This commit is contained in:
parent
e7862b5b1c
commit
55b298678d
@ -5,6 +5,8 @@ import com.sleepycat.je.Database
|
|||||||
import com.sleepycat.je.DatabaseConfig
|
import com.sleepycat.je.DatabaseConfig
|
||||||
import com.sleepycat.je.Environment
|
import com.sleepycat.je.Environment
|
||||||
import com.sleepycat.je.EnvironmentConfig
|
import com.sleepycat.je.EnvironmentConfig
|
||||||
|
import io.github.chronosx88.influence.helpers.comparators.CompareLong
|
||||||
|
import io.github.chronosx88.influence.helpers.comparators.CompareNumber640
|
||||||
import net.tomp2p.connection.SignatureFactory
|
import net.tomp2p.connection.SignatureFactory
|
||||||
import net.tomp2p.dht.Storage
|
import net.tomp2p.dht.Storage
|
||||||
import net.tomp2p.peers.Number160
|
import net.tomp2p.peers.Number160
|
||||||
@ -16,7 +18,8 @@ import java.io.File
|
|||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
class StorageBerkeleyDB(peerId: Number160, path : File, signatureFactory: SignatureFactory) : Storage {
|
class StorageBerkeleyDB(peerId: Number160, path : File, signatureFactory: SignatureFactory) : Storage {
|
||||||
// Core
|
// Core
|
||||||
@ -47,16 +50,25 @@ class StorageBerkeleyDB(peerId: Number160, path : File, signatureFactory: Signat
|
|||||||
val envConfig = EnvironmentConfig()
|
val envConfig = EnvironmentConfig()
|
||||||
envConfig.allowCreate = true
|
envConfig.allowCreate = true
|
||||||
dbEnvironment = Environment(path, envConfig)
|
dbEnvironment = Environment(path, envConfig)
|
||||||
val dbConfig = DatabaseConfig()
|
|
||||||
dbConfig.allowCreate = true
|
|
||||||
|
|
||||||
dataMapDB = dbEnvironment.openDatabase(null, "dataMap_$peerId", dbConfig)
|
val configMap : HashMap<String, com.sleepycat.je.DatabaseConfig> = HashMap()
|
||||||
timeoutMapDB = dbEnvironment.openDatabase(null, "timeoutMap_$peerId", dbConfig)
|
|
||||||
timeoutMapRevDB = dbEnvironment.openDatabase(null, "timeoutMapRev_$peerId", dbConfig)
|
val compareNumber640 = CompareNumber640()
|
||||||
protectedDomainMapDB = dbEnvironment.openDatabase(null, "protectedDomainMap_$peerId", dbConfig)
|
val compareLong = CompareLong()
|
||||||
protectedEntryMapDB = dbEnvironment.openDatabase(null, "protectedEntryMap_$peerId", dbConfig)
|
configMap["dataMapConfig"] = DatabaseConfig().setBtreeComparator(compareNumber640)
|
||||||
responsibilityMapDB = dbEnvironment.openDatabase(null, "responsibilityMap_$peerId", dbConfig)
|
configMap["dataMapConfig"]!!.allowCreate = true
|
||||||
responsibilityMapRevDB = dbEnvironment.openDatabase(null, "responsibilityMapRev_$peerId", dbConfig)
|
configMap["timeoutMapRevConfig"] = DatabaseConfig().setBtreeComparator(compareLong)
|
||||||
|
configMap["timeoutMapRevConfig"]!!.allowCreate = true
|
||||||
|
configMap["other"] = DatabaseConfig()
|
||||||
|
configMap["other"]!!.allowCreate = true
|
||||||
|
|
||||||
|
dataMapDB = dbEnvironment.openDatabase(null, "dataMap_$peerId", configMap["dataMapConfig"])
|
||||||
|
timeoutMapDB = dbEnvironment.openDatabase(null, "timeoutMap_$peerId", configMap["other"])
|
||||||
|
timeoutMapRevDB = dbEnvironment.openDatabase(null, "timeoutMapRev_$peerId", configMap["timeoutMapRevConfig"])
|
||||||
|
protectedDomainMapDB = dbEnvironment.openDatabase(null, "protectedDomainMap_$peerId", configMap["other"])
|
||||||
|
protectedEntryMapDB = dbEnvironment.openDatabase(null, "protectedEntryMap_$peerId", configMap["other"])
|
||||||
|
responsibilityMapDB = dbEnvironment.openDatabase(null, "responsibilityMap_$peerId", configMap["other"])
|
||||||
|
responsibilityMapRevDB = dbEnvironment.openDatabase(null, "responsibilityMapRev_$peerId", configMap["other"])
|
||||||
|
|
||||||
storageCheckIntervalMillis = 60 * 1000
|
storageCheckIntervalMillis = 60 * 1000
|
||||||
|
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package io.github.chronosx88.influence.helpers.comparators;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import io.github.chronosx88.influence.helpers.Serializer;
|
||||||
|
|
||||||
|
public class CompareLong implements Comparator<byte[]>, Serializable {
|
||||||
|
@Override
|
||||||
|
public int compare(byte[] o1, byte[] o2) {
|
||||||
|
Serializer<Long> serializer = new Serializer<>();
|
||||||
|
Long num1 = serializer.deserialize(o1);
|
||||||
|
Long num2 = serializer.deserialize(o2);
|
||||||
|
return num1.compareTo(num2);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package io.github.chronosx88.influence.helpers.comparators;
|
||||||
|
|
||||||
|
import net.tomp2p.peers.Number640;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import io.github.chronosx88.influence.helpers.Serializer;
|
||||||
|
|
||||||
|
public class CompareNumber640 implements Comparator<byte[]>, Serializable {
|
||||||
|
@Override
|
||||||
|
public int compare(byte[] o1, byte[] o2) {
|
||||||
|
Serializer<Number640> serializer = new Serializer<>();
|
||||||
|
Number640 num1 = serializer.deserialize(o1);
|
||||||
|
Number640 num2 = serializer.deserialize(o2);
|
||||||
|
return num1.compareTo(num2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user