<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Another behavior I'm seeing that is surprising me is:<div><br></div><div>tx.begin();</div><div>Map&lt;?,?&gt; map = AtomicMapLookup.getAtomicMap(cache, key);</div><div>assert map.size() == 3;</div><div>AtomicMapLookup.removeAtomicMap(cache, key);</div><div>assert map.size() == 0;</div><div>tx.commit();</div><div><br></div><div>I can sort understand in a twisted way that removeAtomicMap clears the underlying map but that's for sure surprising and can lead to weird bugs for ATM users. Is that necessary?</div><div><br></div><div>Emmanuel</div><div><br><div><div>On 14 avr. 2011, at 10:30, Manik Surtani wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Apologies for the late response.<div><br><div><div>On 13 Apr 2011, at 10:38, Emmanuel Bernard wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">In exchange for answers, I will improve at least the JavaDoc and maybe create a wiki from this info.</div></blockquote><div><br></div><div>Sounds like a fair exchange. &nbsp;:-)</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I've tried to search the wiki but found nothing on AtomicMap (only forum posts) and I've read the AtomicMap JavaDoc but I am still a bit unsure of what's going on.</div><div><div><br></div><div>When I need to create an AtomicMap, I must use&nbsp;</div><div>AtomicMap&lt;String, Object&gt; resultset = AtomicMapLookup.getAtomicMap(cache, "my_atomic_map_key");</div></div></div></blockquote><div><br></div><div>Well, AtomicMapLookup.getAtomicMap(cache, myAtomicMapName).</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><b>Questions</b></div><div>Here are a few questions for you</div><div><br></div><div>1. How can I apply advanced flags to get or create the AtomicMap?</div><div>cache.withFlag(SKIP_CACHE_STORE,FORCE_ASYNCHRONOUS).get("my_atomic_map_key");</div></div></div></blockquote><div><br></div><div>You can't right now; as a "dirty hack", you can just do what getAtomicMap() does internally, adding the flags&nbsp;you need.</div><div><br></div><div><a href="https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java#L49">https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java#L49</a></div><div><br></div><div>The real solution: create a feature request on JIRA so that we can add flags to getAtomicMap() as well.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>3. Is that legal to use other cache methods like replace on an AtomicMap value, what are the consequences?</div></div></div></blockquote><div><br></div><div>cache.putIfAbsent() is used internally by getAtomicMap(). &nbsp;replace() is harder, since it may mean that a thread may be storing stuff in an AtomicMap that has been replaced, so those changes get lost. &nbsp;Why would you need to replace() an atomic map?</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>3. When I expect a map to be present in the key, can I use cache.get("my_atomic_map_key") and still benefit from my properly proxied AtomicMap? Or am I forced to use&nbsp;AtomicMapLookup.getAtomicMap?</div></div></div></blockquote><div><br></div><div>You need to use AML.getAtomicMap() to make sure your proxy is properly created/wrapped. &nbsp;See:</div><div><br></div><div><a href="https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java#L49">https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java#L49</a></div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>4. Using&nbsp;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?</div></div></div></blockquote><div><br></div><div>You could use getAtomicMap(cache, mapName, createIfAbsent) so you get a null if createIfAbsent == false and no such atomic map exists. &nbsp;Does this help?</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>5. Must I use AtomicMapLookup.remove method to remove an atomic map?</div></div></div></blockquote><div><br></div>You can just use cache.remove(), but for the sake of clean generics, it is better to go via AML.remove().</div><div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>6. Can I clone an AtomicMap?</div></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>However, we could provide a AtomicMap.clone(nameOfClone) method, which could take care of this (internally call AML.getAtomicMap(nameOfClone) and copy contents across).</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value.&nbsp;When I tried briefly Iw as unsure I could do that.</div></div></div></blockquote><div><br></div><div>Yep.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><b>Proposed improvements</b></div><div><br></div><div>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</div><div><br></div><div>1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?</div><div>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).</div><div>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</div></div></div></blockquote><div><br></div><div>Fair point, certain AML code could be moved into the CacheDelegate. &nbsp;But I fear a lot of instanceof checking which may be unnecessary if using the cache to store anything other than AtomicMaps.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.</div><div>AtomicMap&lt;String, Object&gt; resultSet = AtomicMapLookup.createAtomicMap();</div><div>cache.put(key, resultSet); //lazily set&nbsp;cache,&nbsp;deltaMapKey,&nbsp;batchContainer and&nbsp;icc for new AtomicMaps</div></div></div></blockquote><div><br></div><div>The problem there is that the put() won't be atomic. &nbsp;You'd need to mandate a putIfAbsent, but that means any initialization of the AtomicMap (setting values) could potentially be wasted. &nbsp;This is why the AML registers the AtomicMap in the cache before allowing user code to store values.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>3. Could we guarantee some equality between Map and AtomicMap?</div><div>if I do Map&nbsp;</div><div><br></div><div>map = new HashMap(atomicMap);</div><div>atomicMap.put("key", "value");</div><div>cache.replace(key, map, atomicMap);</div><div><br></div><div>Am I guaranteed that it can work (if no one has pushed a change behind my back)?</div></div></div></blockquote><div><br></div><div>Not at the moment, but this is something we could possibly do.</div></div><div><br class="webkit-block-placeholder"></div><div><div><div>Hope this helps</div><div>Manik</div><div>--</div><div>Manik Surtani</div><div><a href="mailto:manik@jboss.org">manik@jboss.org</a></div><div><a href="http://twitter.com/maniksurtani">twitter.com/maniksurtani</a></div><div><br></div><div>Lead, Infinispan</div><div><a href="http://www.infinispan.org/">http://www.infinispan.org</a></div><div><br></div></div><br class="Apple-interchange-newline">
</div>
<br></div></div>_______________________________________________<br>infinispan-dev mailing list<br><a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/infinispan-dev</blockquote></div><br></div></body></html>