<div class="gmail_quote">On Fri, Jul 6, 2012 at 3:10 PM, Mircea Markus <span dir="ltr">&lt;<a href="mailto:mmarkus@redhat.com" target="_blank">mmarkus@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">
<div class="im"><br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Dan Berindei&quot; &lt;<a href="mailto:dan.berindei@gmail.com">dan.berindei@gmail.com</a>&gt;<br>
&gt; To: &quot;infinispan -Dev List&quot; &lt;<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a>&gt;<br>
</div><div><div class="h5">&gt; Sent: Friday, July 6, 2012 12:43:44 PM<br>
&gt; Subject: Re: [infinispan-dev] singleton @Listeners<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Jul 6, 2012 at 1:44 PM, Mircea Markus &lt; <a href="mailto:mmarkus@redhat.com">mmarkus@redhat.com</a> &gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; ----- Original Message -----<br>
&gt; &gt; From: &quot;Galder Zamarreño&quot; &lt; <a href="mailto:galder@redhat.com">galder@redhat.com</a> &gt;<br>
&gt; &gt; To: &quot;infinispan -Dev List&quot; &lt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a> &gt;<br>
&gt;<br>
&gt; &gt; Sent: Friday, July 6, 2012 2:46:20 AM<br>
&gt; &gt; Subject: Re: [infinispan-dev] singleton @Listeners<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt; &gt; On Jun 28, 2012, at 11:26 AM, Mircea Markus wrote:<br>
&gt; &gt;<br>
&gt; &gt; &gt; This is a problem that pops up constantly:<br>
&gt; &gt; &gt; User: &quot;I add a listener to my distributed/replicated cache but<br>
&gt; &gt; &gt; this gets invoked numOwners times - can I make that to be invoked<br>
&gt; &gt; &gt; only once cluster wise?&quot;<br>
&gt; &gt; &gt; Developer: &quot;Yes, you can! You have to do that and that...&quot;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; What about a &quot;singleton&quot; attribute on the Listener? Would make<br>
&gt; &gt; &gt; the<br>
&gt; &gt; &gt; reply shorter:<br>
&gt; &gt; &gt; Developer: &quot;Use @Listener(singleton=true)&quot;<br>
&gt; &gt;<br>
&gt; &gt; Hmmm, that seems doable without any extra attributes.<br>
&gt; &gt;<br>
&gt; &gt; For a replicated cache, take the view and pick a node (consistently<br>
&gt; &gt;<br>
&gt;<br>
&gt; &gt; For a distributed cache, find the primary owner of a key.<br>
&gt; That&#39;s pretty much how I had in mind to implement it. But I think the<br>
&gt; attribute is needed though: there are use cases in which you still<br>
&gt; want to be notified on all the owners, as you do now. OTOH if you<br>
&gt; only want a per-cluster notification you&#39;d add this attribute to the<br>
&gt; listener.<br>
&gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt; If we add the attribute we&#39;re going to raise some new questions:<br>
&gt; * Is the listener guaranteed to fire on the primary owner?<br>
&gt; * If two keys are Group-ed together, is the listener guaranteed to<br>
&gt; fire on the same node for both keys? What if a new node becomes the<br>
&gt; primary owner between the two modifications?<br>
</div></div>I&#39;d rather not offer any such explicit guarantees but the uniqueness of execution. If users are concerned with the locality of the events they should use the general @Listener interface and figure it out internally.<br>

<div class="im"><br>
&gt; * If the key is modified by the same put command on two owners, and<br>
&gt; each node is the primary owner of the key at the moment when it<br>
&gt; receives the put command, does the listener fire on still fire only<br>
&gt; once?<br>
</div>I guess that might be a tricky one, as once-and-only-once guarantee is tricky to implement...<br>
<div class="im"><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; &gt; Has this been asked so often? I don&#39;t recall right now… :)<br>
&gt; Yes, CBOE had the same issue as they needed to push updates from one<br>
&gt; cluster to the other over hotrod.<br>
&gt; Also in this article they have to do quite a workaround to enforce<br>
&gt; uniqueness:<br>
&gt; <a href="http://blog.c2b2.co.uk/2012/06/infinispan-event-push-to-tomcat.html" target="_blank">blog.c2b2.co.uk/2012/06/infinispan-event-push-to-tomcat.html</a><br>
&gt; And there were some others :)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; I think what C2B2 are doing is more like replicated listeners in a<br>
&gt; distributed cache. They probably had to post the message on JMS only<br>
&gt; from the primary owner, but the blog doesn&#39;t mention it, so I don&#39;t<br>
&gt; think it was that hard to figure it out ;)<br>
<br>
</div>They post the message to the JMS from all the owners and the used HormetQ stuff to remove duplicated messages. It doesn&#39;t seem like they thought about the primary-owenr approach, but that would have helped.<br>

<br></blockquote><div><br>I see, they only describe that in part 2.<br></div></div><br>