private RefCounted<SolrIndexSearcher> newHolder(SolrIndexSearcher newSearcher) { RefCounted<SolrIndexSearcher> holder = new RefCounted<SolrIndexSearcher>(newSearcher) { public void close() { try { synchronized(searcherLock) { // it's possible for someone to get a reference via the _searchers queue // and increment the refcount while RefCounted.close() is being called. // we check the refcount again to see if this has happened and abort the close. // This relies on the RefCounted class allowing close() to be called every // time the counter hits zero. if (refcount.get() > 0) return; _searchers.remove(this); } resource.close(); } catch (IOException e) { log.error("Error closing searcher:" + SolrException.toStr(e)); } } }; holder.incref(); // set ref count to 1 to account for this._searcher return holder; }
/** * Return the newest {@link RefCounted}<{@link SolrIndexSearcher}> with * the reference count incremented. It <b>must</b> be decremented when no longer needed. * If no searcher is currently open, then if openNew==true a new searcher will be opened, * or null is returned if openNew==false. */ public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew) { synchronized (searcherLock) { if (_searchers.isEmpty()) { if (!openNew) return null; // Not currently implemented since simply calling getSearcher during inform() // can result in a deadlock. Right now, solr always opens a searcher first // before calling inform() anyway, so this should never happen. throw new UnsupportedOperationException(); } RefCounted<SolrIndexSearcher> newest = _searchers.getLast(); newest.incref(); return newest; } }
try { if(current != null && current.get().getVersion().equals(version)){ current.incref(); //this increase is for the holder of the returned instance log.debug(" > increase RefCount for EntityCache for version {} to {}", version, current.getRefcount()); current.incref(); current.incref(); //this increase is for the holder of the returned instance log.debug(" > increase RefCount for EntityCache for version {} to {}", version, current.getRefcount());