Why don't we ping Emmanuel for an advice. He's done similar API design in Hibernate IIRC.
On 2010-04-12, at 8:58 AM, Mircea Markus wrote:


On 12 Apr 2010, at 15:36, Manik Surtani wrote:

Re: subject (see https://jira.jboss.org/jira/browse/ISPN-359), there are a couple of approaches that could be taken:

1.  Don't use key.hashcode() as the seed in determining to which nodes an entry is mapped, but instead on a well-known method or annotated method (e.g., int getGroupID() or a method annotated with @GroupId).  The way I see it, this approach has:

+ Will work, no additional overheads of AtomicMaps
- Cost (reflection)
- Intrusive (what if users have no control over the key class, e.g., String keys?)

2.  Additional API methods on the cache - cache.put(K, V, G), cache.putAll(Map, G), etc.

+ Non-intrusive
- Overhead of AtomicMaps + additional entries for mappings
+ or - (depending on how you look at it) all keys in the group will be locked together, etc, a side-effect of using AtomicMaps

My pref is for approach #2.  In terms of implementation, here is what I have in mind:

* A GroupingInterceptor that intercepts the call early on if the call is a put(K, V, G) or something similar.  
* Breaks up the call to a put(K, G) and a getAtomicMap(G).put(K, V).  Wrapped in a tx to ensure atomicity.
* get(K), etc intercepted as well, replaced with getAtomicMap(get(K)).get(K)
* remove(K), etc intercepted with getAtomicMap(get(K)).remove(K)

One of the issues with the API approach is that it heavily pollutes the Cache API.  It will double the number of put() methods on Cache (currently 18 variants of put, including ones that take in lifespans and maxIdles, async versions that return futures, etc.)  Perhaps this could be in an additional sub-interface interface?  GroupedCache?  Or is this degree of method overloading not too confusing?
what about using an Flag-like api?
cache.inGroup("groupName").put(...).
or an "parametrized" flag:
cache.withFlag(Flags.getColocateFlag("grouName").put(...)
as long as we can create "parametrized" flags as bellow, I like the second approach


Cheers,
--
Manik Surtani
Lead, Infinispan
Lead, JBoss Cache




_______________________________________________
infinispan-dev mailing list
infinispan-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev

_______________________________________________
infinispan-dev mailing list
infinispan-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev