<div dir="ltr"><div><div><div><div>I guess the grouper could use a KeyAffinityService (or something similar) to generate a key local to each node and return that instead of &quot;0&quot; or &quot;1&quot;.<br></div>However, you won&#39;t have any guarantee that the keys will stay on the same node if the cache topology changes (e.g. another node joins).<br>

<br></div>It used to be that the actual address of the node would (almost) always be mapped to that node, but that was just an implementation detail, and it never worked 100%. <br><br>Ben, do you think being able to pin a key &quot;permanently&quot; to a node would be useful?<br>

<br></div>Cheers<br></div>Dan<br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 21, 2013 at 6:31 PM, Galder Zamarreño <span dir="ltr">&lt;<a href="mailto:galder@redhat.com" target="_blank">galder@redhat.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hmmm, one hacky way might be to hold on to the grouper instance passed in via configuration, and once the cache manager has been started, set it in the grouper and use to query either the address, or the physical address (via EmbeddedCacheManager.getTransport…)?<br>


<div><div class="h5"><br>
On May 14, 2013, at 6:34 PM, cotton-ben &lt;<a href="mailto:ben.cotton@ALUMNI.RUTGERS.EDU">ben.cotton@ALUMNI.RUTGERS.EDU</a>&gt; wrote:<br>
<br>
&gt; I am playing with the Infinispan 5.3 quick-start package to exercise my usage<br>
&gt; of the Grouping API.  As we know the quick start package is made up of<br>
&gt; AbstractNode.java, Node0.java, Node1.java and Node2.java (plus a<br>
&gt; util/listener).<br>
&gt;<br>
&gt; My ambition is to demonstrate<br>
&gt;<br>
&gt; 1.  that any Cache&lt;K,V&gt;.put(&quot;DIMENSION.xxx&quot;,v) will flow through my Grouper<br>
&gt; and &quot;pin&quot; that key in the Cache at @Node=0.<br>
&gt; 2.  that any Cache&lt;K,V&gt;.put(&quot;POSITION.xxx&quot;,v) will flow through my Grouper<br>
&gt; and &quot;pin&quot; that key in the Cache at either @Node=1 or @Node=2 .<br>
&gt;<br>
&gt; Here is my AbstractNode#createCacheManagerProgramatically() config:<br>
&gt;<br>
&gt; private static EmbeddedCacheManager createCacheManagerProgramatically() {<br>
&gt;               return new DefaultCacheManager(<br>
&gt;                               GlobalConfigurationBuilder.defaultClusteredBuilder()<br>
&gt;                               .transport().addProperty(&quot;configurationFile&quot;, &quot;jgroups.xml&quot;)<br>
&gt;                               .build(),<br>
&gt;                               new org.infinispan.configuration.cache.ConfigurationBuilder()<br>
&gt;                               .clustering()<br>
&gt;                               .cacheMode(CacheMode.DIST_SYNC)<br>
&gt;                               .hash().numOwners(1).groups().enabled(Boolean.TRUE)<br>
&gt;                               .addGrouper(new<br>
&gt; com.jpmorgan.ct.lri.cs.ae.test.DimensionGrouper&lt;String&gt;())<br>
&gt;                               .build()<br>
&gt;                               );<br>
&gt;       }<br>
&gt;<br>
&gt; And here is my Grouper&lt;T&gt; implementation<br>
&gt;<br>
&gt; public class DimensionGrouper&lt;T&gt; implements Grouper&lt;String&gt; {<br>
&gt;       public String computeGroup(String key, String group) {<br>
&gt;               if (key.indexOf(&quot;DIMENSION.&quot;)==0) {<br>
&gt;                       String groupPinned = &quot;0&quot;;<br>
&gt;                       System.out.println(&quot;Pinning Key=[&quot;+key+&quot;] @Node=[&quot;+groupPinned+&quot;]&quot;);<br>
&gt; //node= exactly 0<br>
&gt;                       return groupPinned;<br>
&gt;               } else if (key.indexOf(&quot;POSITION.&quot;)==0) {<br>
&gt;                       String groupPinned = &quot;&quot;+(1+ (int)(Math.random()*2));<br>
&gt;                       System.out.println(&quot;Pinning Key=[&quot;+key+&quot;] @Node=[&quot;+groupPinned+&quot;]&quot;);<br>
&gt; //node= {1,2}<br>
&gt;                       return groupPinned;<br>
&gt;               } else {<br>
&gt;                       return null;<br>
&gt;               }<br>
&gt;       }<br>
&gt;<br>
&gt;       public Class&lt;String&gt; getKeyType() {<br>
&gt;               return String.class;<br>
&gt;       }<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt; The &quot;logic&quot; is working correctly ... i.e. when from Node2.java I call<br>
&gt;<br>
&gt;                     for (int i = 0; i &lt; 10; i++) {<br>
&gt;                               cacheDP.put(&quot;DIMENSION.&quot; + i, &quot;DimensionValue.&quot; + i);<br>
&gt;                               cacheDP.put(&quot;POSITION.&quot; + i, &quot;PositionValue.&quot; + i);<br>
&gt;<br>
&gt;                       }<br>
&gt;<br>
&gt; My DimensionGrouper is returning &quot;0&quot; from computeGroup().  My question is<br>
&gt; how in Infinispan can I map the computeGroup() return value to a physical<br>
&gt; Node?  I.e.  How can I make it so that when computeGroup() returns &quot;0&quot;, I<br>
&gt; will *only* add that &lt;K,V&gt; entry to the Cache @Node 0?<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; View this message in context: <a href="http://infinispan-developer-list.980875.n3.nabble.com/Re-How-to-get-Grouper-T-computeGroup-key-return-value-to-map-to-physical-Node-tp4027134.html" target="_blank">http://infinispan-developer-list.980875.n3.nabble.com/Re-How-to-get-Grouper-T-computeGroup-key-return-value-to-map-to-physical-Node-tp4027134.html</a><br>


&gt; Sent from the Infinispan Developer List mailing list archive at Nabble.com.<br>
&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
<br>
</div></div>--<br>
Galder Zamarreño<br>
<a href="mailto:galder@redhat.com">galder@redhat.com</a><br>
<a href="http://twitter.com/galderz" target="_blank">twitter.com/galderz</a><br>
<br>
Project Lead, Escalante<br>
<a href="http://escalante.io" target="_blank">http://escalante.io</a><br>
<br>
Engineer, Infinispan<br>
<a href="http://infinispan.org" target="_blank">http://infinispan.org</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br></div>