nathanmarz/trident-memcached — pull request #7 by svendx4f (2013-10-15 09:58:22+00:00)
Title: added pluggable key creation strategy: support for compound keys and prefix

Hi,

The current version of the MemcachedState does not support compound keys. Also, if several parts of the topology save distinct states to memcached, the current implementation could lead to key overlap and thus destruction of state information. For example, a count grouping/saving by word running simultaneously to a count grouping/saving by first letter of the word could both yield key overlap for one-letter words like "a" in English or "y" in French.

I added a mechanism that delegates to a IStateSingleKeyBuilder to make the creation of memcached key more flexibly. I also added a default ConcatKeyBuilder implementation of IStateSingleKeyBuilder, which just concatenates the toString() of the compound key to solve issue #1 and allows a optional prefix to be configured to solve issue #2.

The new usage is backward compatible with the old syntax. I illustrate the new features in the updated example in Test.java.

Unfortunately, I had to de-activate usage of CachedMap to have this working: data with compound keys put in the CachedMap by the example topology are never retrieved. I failed to understand why and failed to reproduce a bug with junit in CachedMap with compound keys. Simply commenting out CachedMap from MemcachedState solved the issue.