I have the following class:
public class ChronicleMapIndex<K, V> implements Index<K, V> {
private ChronicleMap<K, V> index;
private Map<String, String> characteristicsMap;
public void buildIndex(String name, Map<String, String> characteristicsMap, Path indexPath, Class<?> keyType, Class<?> valueType){
this.characteristicsMap = characteristicsMap;
String filename = name + ".bin";
Path indexFilePath = Paths.get(indexPath + filename);
try {
index = (ChronicleMap<K, V>) ChronicleMap
.of(keyType, valueType)
.name(name)
.entries(Long.parseLong(characteristicsMap.get("entries")))
.averageValueSize(Double.parseDouble(characteristicsMap.get("averageValueSize")))
.averageKeySize(Double.parseDouble(characteristicsMap.get("averageKeySize")))
.createOrRecoverPersistedTo(indexFilePath.toFile(), true);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public V get(K key) {
return index.get(key);
}
@Override
public void put(K key, V value) {
index.put(key, value);
}
}
I basically want to store a chronicle maps map in a wrapper function. Here, K
and V
are the same as the keyType
and valueType
values passed. So I would like the ChronicleMap map to have the same key and value type as K
and V
.
However, when I create it, I get the following error:
net.openhft.chronicle.hash.ChronicleHashRecoveryFailedException: java.lang.AssertionError: java.lang.NoSuchMethodException: sun.nio.ch.FileChannelImpl.map0(int,long,long)
at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1877)
at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1701)
at net.openhft.chronicle.map.ChronicleMapBuilder.recoverPersistedTo(ChronicleMapBuilder.java:1655)
at net.openhft.chronicle.map.ChronicleMapBuilder.createOrRecoverPersistedTo(ChronicleMapBuilder.java:1638)
at net.openhft.chronicle.map.ChronicleMapBuilder.createOrRecoverPersistedTo(ChronicleMapBuilder.java:1629)
at edu.upf.taln.indexer.index.chroniclemap.ChronicleMapIndex.buildIndex(ChronicleMapIndex.java:27)
in this line:
.createOrRecoverPersistedTo(indexFilePath.toFile(), true);
I was wondering if this error is because I'm doing something wrong with generics.
I am using ChronicleMap 3.19.4 and JNA 5.5.0 in Windows 10.
Here is an individual test you can run easily:
Map<String, String> characteristicsMap = new HashMap<>();
characteristicsMap.put("entries", Long.toString(123));
characteristicsMap.put("averageKeySize", Integer.toString(5));
characteristicsMap.put("averageValueSize", Integer.toString(5));
String name = "test";
Path indexPath = Paths.get("D:/trabajo"); // substitute this as needed
ChronicleMapIndex<String, String> index = new ChronicleMapIndex<>();
index.buildIndex(name, characteristicsMap, indexPath ,String.class, String.class);