<div dir="ltr"><p dir="ltr"><br>
On 25 Jan 2013 23:26, &quot;Vladimir Blagojevic&quot; &lt;<a href="mailto:vblagoje@redhat.com" target="_blank">vblagoje@redhat.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hey,<br>
&gt;<br>
&gt; I figured out why cache listeners notifications were not fired. We have<br>
&gt; to add listener *after* cache.start() has been called. If listener is<br>
&gt; added before start it will not be registered.<br>
&gt;</p>
<p dir="ltr">This doesn&#39;t sound right... DefaultCacheManager calls cache.start() automatically, so you should never have to call it explicitly.</p>
<p dir="ltr">Looking at the code, the listener should be registered even if the cache wasn&#39;t started yet (e.g. ListenerRegistrationTest never calls start()). The only odd thing is that if you stop a cache, all the listeners are lost. Maybe that&#39;s what happened in your case?</p>



<p dir="ltr">&gt; That aside I found some problems mapping our events to jsr 107 events.<br>
&gt; The problem is specifically with JSR107 CacheEntryCreatedListener and<br>
&gt; CacheEntryExpiredListener.<br>
&gt;<br>
&gt; The first one is not easy to implement because we need both key/value<br>
&gt; pair for jsr listener and our CacheEntryCreatedEvent does not provide<br>
&gt; value. I found some references where people used CacheEntryModified<br>
&gt; instead with pre being null and post being value to detect new entry in<br>
&gt; cache. In that case listener translator class would have to keep state<br>
&gt; and track pre(true/false) for CacheEntryModified, right? Any other way<br>
&gt; to do it?<br>
&gt;</p><p>You could add an interceptor to trigger your events, without using the cache&#39;s notifications  at all. <br></p><p>If you&#39;re ok with changing the core, you could add a getValue() method to CacheEntryCreatedEvent, and an isCreated() method to CacheEntryModifiedEvent (as I suppose you don&#39;t want to call the updates listener when an entry is created). Both changes should be backwards-compatible.<br>

</p><p></p><p dir="ltr"><br>
&gt; The second I have no idea how to implement as we do not have<br>
&gt; CacheEntryExpired event. True, spec is not rigorous that such an event<br>
&gt; has to be fired immediately after an entry has expired but eventually<br>
&gt; (which might be on access). Either way, I am all ears on suggestions how<br>
&gt; to implement this one.<br>
&gt;</p><p>I guess @CacheEntryEvicted/@CacheEntriesEvicted would be the closest thing we have in Infinispan. But you can&#39;t check in the listener if the entry was evicted because it expired or because there wasn&#39;t enough space in the data container (yet).<br>

</p><p>Come to think of it, if an entry is evicted because of size constraints, there isn&#39;t any way to keep track of its expiration time and invoke the expiration listener on access either. Is the expiration event mandatory in the JSR?<br>

</p><p dir="ltr">Cheers</p><p>Dan</p><p><br>
</p>
</div>