<div dir="ltr"><div>It looks to me like you actually want a partial order between caches on shutdown, so why not declare an explicit dependency (e.g. manager.stopOrder(before, after)? We could even throw an exception if the user tries to stop a cache manually in the wrong order (e.g. TestingUtil.killCacheManagers).</div>

<div><br></div><div>Alternatively, we could add an event CacheManagerStopEvent(pre=true) at the cache manager level that is invoked before any cache is stopped, and you could close all the indexes in that listener. The event could even be at the cache level, if it would make things easier.</div>

<div><br></div><div>Cheers</div><div>Dan</div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 15, 2014 at 3:29 PM, Sanne Grinovero <span dir="ltr">&lt;<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The goal being to resolve ISPN-4561, I was thinking to expose a very<br>
simple reference counter in the AdvancedCache API.<br>
<br>
As you know the Query module - which triggers on indexed caches - can<br>
use the Infinispan Lucene Directory to store its indexes in a<br>
(different) Cache.<br>
When the CacheManager is stopped, if the index storage caches are<br>
stopped first, then the indexed cache is stopped, this might need to<br>
flush/close some pending state on the index and this results in an<br>
illegal operation as the storate is shut down already.<br>
<br>
We could either implement a complex dependency graph, or add a method like:<br>
<br>
<br>
  boolean incRef();<br>
<br>
on AdvancedCache.<br>
<br>
when the Cache#close() method is invoked, this will do an internal<br>
decrement, and only when hitting zero it will really close the cache.<br>
<br>
A CacheManager shutdown will loop through all caches, and invoke<br>
close() on all of them; the close() method should return something so<br>
that the CacheManager shutdown loop understand if it really did close<br>
all caches or if not, in which case it will loop again through all<br>
caches, and loops until all cache instances are really closed.<br>
The return type of &quot;close()&quot; doesn&#39;t necessarily need to be exposed on<br>
public API, it could be an internal only variant. </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Could we do this?<br>
<br>
--Sanne<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>
</blockquote></div><br></div></div>