My apologies to all for cluttering the issue.
New simplified version based on Yonik's example for trunk 685913 (post solr-695 commit), dont let the patch size fool you:
CoreContainer.getCore() & CoreContainer.getAdminCore() now return an incref-ed ("opened") core;
core.close() must be called when these 2 have been used.
SolrCore.Reference is gone.
SolrCore.open() & SolrCore.close() method are kept because we can retrieve cores in 3 "close-unprotected" ways:
1 - a call to CoreDescriptor.getCore(), descriptors that can be retrieved through CoreContainer.getCoreDescriptors())
2 - a list of close-unprotected cores through CoreContainer.getCores().
3 - SolrCore.getCore() - which is deprecated
The first 2 can be used in a user-defined filter/servlet after the SolrDispatchFilter falls through the filter-chain, the CoreContainer being
set as an attribute of the request ("org.apache.solr.CoreContainer").
Because of this, we are not always synchronized by the CoreContainer#cores when we incref/decref.
We can thus try to open() a core which is closed and cant use a simple refCount.incrementAndGet().
Thus the refCount.get()/refCount.compareAndSet() pattern in both open & close.
The TestHarness is modified to always create a CoreContainer that contains the "unnamed" core so testCoreMT uses
Also touched some tests that were using SolrCore.getCore() when they can use the TestHarness core.