-
-
2. Re: Hotrod-Client and locking
infinikli Jun 28, 2011 5:13 AM (in response to mircea.markus)Thanks for the answer, but how do I put a not yet existent value with version into cache?
E.g. two RemoteCacheManager-instances invoke parallel RemoteCache.getVersioned on a not-yet-existent-value. Both clients will receive null for the given key. I can not use RemoteCache.replaceWithVersion because no such value exists, so I have to use RemoteCache.put which means that one value will be overridden by the other. Is there a way to handle this issue?
I'd like to have a feature where I can put a value with an initial version (say 0) which succeeds only if no such value exists.
-
3. Re: Hotrod-Client and locking
dan.berindei Jun 30, 2011 9:35 AM (in response to infinikli)The first time you can use remoteCache.putIfAbsent(key, value) (it's actually inherited from ConcurrentMap).
Unfortunately if that fails it returns a non-versioned value, if you want to retry you have to either use remoteCache.replace(key, oldValue, newValue), which calls equals() on the values, or do another remoteCache.getVersioned(key) so you can call replaceWithVersion. I suspect in most cases it would be better to use replace() and avoid the extra RPC.