4. Using AtomicMapLookup.getAtomicMap, how can I differentiate an empty key where a new map has been created from a retrieval of an empty map stored in the key?
You could use getAtomicMap(cache, mapName, createIfAbsent) so you get a null if createIfAbsent == false and no such atomic map exists. Does this help?
5. Must I use AtomicMapLookup.remove method to remove an atomic map?
You can just use cache.remove(), but for the sake of clean generics, it is better to go via AML.remove().
6. Can I clone an AtomicMap?
No, it's not cloneable, since a clone that is not stored in the cache (in a threadsafe manner) is meaningless, and Java's clone() API doesn't allow you to pass in a new name for the clone.
However, we could provide a AtomicMap.clone(nameOfClone) method, which could take care of this (internally call AML.getAtomicMap(nameOfClone) and copy contents across).
For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value. When I tried briefly Iw as unsure I could do that.
Yep.
Proposed improvements
I'm asking all the questions because these can potentially make AtomicMap users life quite hard and abstracting Infinispan from OGM will make a damn ugly interface / contract
1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?
It seems that either the marshaller or the get operations (probably the get ops as local cache should work as well) should be able to intercept an AtomicMap and essentually do what AtomicMapLookup is doing (and make sure it is properly wrapped).
If that's possible that would be already a big benefit for the user as it would only be limited to AtomicMap creation or cloning
Fair point, certain AML code could be moved into the CacheDelegate. But I fear a lot of instanceof checking which may be unnecessary if using the cache to store anything other than AtomicMaps.
2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.
AtomicMap<String, Object> resultSet = AtomicMapLookup.createAtomicMap();
cache.put(key, resultSet); //lazily set cache, deltaMapKey, batchContainer and icc for new AtomicMaps
The problem there is that the put() won't be atomic. You'd need to mandate a putIfAbsent, but that means any initialization of the AtomicMap (setting values) could potentially be wasted. This is why the AML registers the AtomicMap in the cache before allowing user code to store values.
3. Could we guarantee some equality between Map and AtomicMap?
if I do Map
map = new HashMap(atomicMap);
atomicMap.put("key", "value");
cache.replace(key, map, atomicMap);
Am I guaranteed that it can work (if no one has pushed a change behind my back)?
Not at the moment, but this is something we could possibly do.