Is a map type value possible?

83 views
Skip to first unread message

Ryan Kitchens

unread,
Jun 24, 2015, 4:55:15 PM6/24/15
to java-ch...@googlegroups.com
I want something like a ChronicleMap<String, ConcurrentHashMap<String,String>>. I tried to mess around with ChronicleMapBuilder, but it seems what I am doing is not possible this way. Any ideas or different approach suggested?

    private static ChronicleMap<String, ConcurrentHashMap<String,String>> createChronicleMap() throws IOException {
       
File dnmapfile = new File(dnmapfilename);

       
ChronicleMapBuilder<String, ConcurrentHashMap<String, String>> builder = ChronicleMapBuilder.of(String.class, (Class<ConcurrentHashMap<String, String>>) (Class) ConcurrentHashMap.class);

       
return builder.createPersistedTo(dnmapfile);
   
}


I get the following error: "No field 'actualChunksPerSegment' found in class 'net.openhft.chronicle.map.VanillaChronicleMap"

Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
    at net.openhft.chronicle.map.ChronicleMapBuilder.deserializeHeaderViaXStream(ChronicleMapBuilder.java:1356)
    at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1270)
    at net.openhft.chronicle.map.ChronicleMapBuilder.createPersistedTo(ChronicleMapBuilder.java:1241)
    at com.corp.group.DTracker.createChronicleMap(DTracker.java:53)
    at com.corp.group.DTracker.<init>(DTracker.java:40)
    at com.corp.group.LNotifier.main(LNotifier.java:27)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at net.openhft.chronicle.map.ChronicleMapBuilder.deserializeHeaderViaXStream(ChronicleMapBuilder.java:1353)
    ... 5 more
Caused by: com.thoughtworks.xstream.converters.ConversionException: Could not call net.openhft.chronicle.map.VanillaChronicleMap.readObject() : No field 'actualChunksPerSegment' found in class 'net.openhft.chronicle.map.VanillaChronicleMap'
---- Debugging information ----
message             : Could not call net.openhft.chronicle.map.VanillaChronicleMap.readObject()
cause-exception     : com.thoughtworks.xstream.converters.reflection.MissingFieldException
cause-message       : No field 'actualChunksPerSegment' found in class 'net.openhft.chronicle.map.VanillaChronicleMap'
class               : net.openhft.chronicle.map.VanillaChronicleMap
required-type       : net.openhft.chronicle.map.VanillaChronicleMap
converter-type      : com.thoughtworks.xstream.converters.reflection.SerializableConverter
path                : /net.openhft.chronicle.map.VanillaChronicleMap/net.openhft.chronicle.map.VanillaChronicleMap/default/actualChunksPerSegment
line number         : 5
version             : 3.1.2-alpha-SNAPSHOT
-------------------------------
    at com.thoughtworks.xstream.core.util.SerializationMembers.callReadObject(SerializationMembers.java:133)
    at com.thoughtworks.xstream.converters.reflection.SerializableConverter.doUnmarshal(SerializableConverter.java:455)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:263)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1206)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1190)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1070)
    ... 10 more
Caused by: com.thoughtworks.xstream.converters.reflection.MissingFieldException: No field 'actualChunksPerSegment' found in class 'net.openhft.chronicle.map.VanillaChronicleMap'
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.field(FieldDictionary.java:94)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.getFieldType(PureJavaReflectionProvider.java:159)
    at com.thoughtworks.xstream.converters.reflection.ReflectionProviderWrapper.getFieldType(ReflectionProviderWrapper.java:45)
    at com.thoughtworks.xstream.converters.reflection.SerializableConverter$2.defaultReadObject(SerializableConverter.java:411)
    at com.thoughtworks.xstream.core.util.CustomObjectInputStream.defaultReadObject(CustomObjectInputStream.java:116)
    at net.openhft.chronicle.map.VanillaChronicleMap.readObject(VanillaChronicleMap.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.thoughtworks.xstream.core.util.SerializationMembers.callReadObject(SerializationMembers.java:125)
    ... 21 more



Rob Austin

unread,
Jun 24, 2015, 5:27:44 PM6/24/15
to java-ch...@googlegroups.com
 Do you have a limited number of entries in the inner map. Under the covers, Chronicle works using fixed sizes. 
--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roman Leventov

unread,
Jun 24, 2015, 5:38:09 PM6/24/15
to java-ch...@googlegroups.com
Ryan,
1) seems you have serialized (created) a Chronicle Map of version 2.x..., then updated the dependency to the latest ChronicleMap, and then tried to deserialize. You should either revert dependency to 2.x or remove the map file and create a Map of version 3.x from scratch

2) Having ChronicleMap<K, ConcurrentMap<K2, V>> is pointless. all operations with the first-level key are synchronized on this key. Reads to the Map<K2, V> are already parallel. If you want to have _parallel writes_ to this secondary map, this is possible, but much more complex. You should access the first-level key like you are going to "read" the value (Map<K2, V>), and then update the raw bytes of the value via atomic operations.

Roman Leventov

unread,
Jun 24, 2015, 5:41:39 PM6/24/15
to java-ch...@googlegroups.com
I mean pointless to have ConcurrentMap<K2, V>. It's no different than just Map<K2, V>. If you want parallel writes to the secondary map, it shouldn't be even a map, if should be a complex bespoke data structure over raw bytes.

Francesco Nigro

unread,
Jun 25, 2015, 1:33:39 AM6/25/15
to java-ch...@googlegroups.com
Hi,
It's a "dirty" trick but maybe if the model Map<k1,Map<k2,v>> worth only to access a value V using K1 and then K2 , it could be possible to create a composite key:

interface CompositeKey{
K1 getKey1();
void setKey1(K1 key1);
K2 getKey2();
void setKey2(K2 key2);
}

And then create a ChronicleMap<CompositeKey,V>...

Rob Austin

unread,
Jun 25, 2015, 2:14:43 AM6/25/15
to java-ch...@googlegroups.com
Yes this would work, in certain circumstances, depending on your types. What type is K1 and K2.

Rob
Reply all
Reply to author
Forward
0 new messages