Were you able to find a solution to the above? I an currently investigating Infinispan for a project and distributed atomic increment/decrement is an important requirement. Thanks.
While ISPN doesn't offer this as part of the API, I've implemented something similar in my application. It's actually pretty easy and very performant if you use the distributed executor framework. Here are some rough guidelines:
- You assuredly will either need a lock/increment/release pattern to get counter values. However, if you execute a task on the data owner, you're acquiring local locks.
- You will need to look at the cache configuration options for eager locks.
- You may want to consider allocating "chunks" of possible counter values for your clients to use locally. This will reduce contention on the cache, while guaranteeing uniqueness.
- (Don't forget about overflow conditions)
It's pretty easy to implement using an distributed map.
Keep the last value in a map. When you need the next value, get the last value from the map, increment it, and save the new value using the ConcurrentMap#replace method.
If replace fails, continue to incremente the next value . .