org.apache.lucene.index.IndexReader#incRef ( )源码实例Demo

下面列出了org.apache.lucene.index.IndexReader#incRef ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Apply the filter
 * 
 * @param id String
 * @param reader IndexReader
 * @param deleteNodesOnly boolean
 */
public FilterIndexReaderByStringId(String id, IndexReader reader, Set<String> deletions, Set<String> containerDeletions, boolean deleteNodesOnly)
{
    super(reader);
    reader.incRef();
    this.id = id;
    this.deletions = deletions;
    this.containerDeletions = containerDeletions;
    this.deleteNodesOnly = deleteNodesOnly;
    
    if (s_logger.isDebugEnabled())
    {
        s_logger.debug("Applying deletions FOR "+id +" (the index ito which these are applied is the previous one ...)");
    }

}
 
public IndexSearcherCloseable getIndexSearcher(boolean security) throws IOException {
  final IndexReader indexReader;
  _indexRefreshReadLock.lock();
  try {
    indexReader = _indexReader.get();
    indexReader.incRef();
  } finally {
    _indexRefreshReadLock.unlock();
  }
  if (indexReader instanceof ExitableReader) {
    ((ExitableReader) indexReader).reset();
  }
  if (security) {
    return getSecureIndexSearcher(indexReader);
  } else {
    return getInsecureIndexSearcher(indexReader);
  }
}
 
源代码3 项目: alfresco-repository   文件: IndexInfo.java
/**
 * Get the main reader for committed index data
 * 
 * @return IndexReader
 * @throws IOException
 */
public IndexReader getMainIndexReferenceCountingReadOnlyIndexReader() throws IOException
{
    getReadLock();
    try
    {
        // Check if we need to rebuild the main indexer as it is invalid.
        // (it is shared and quick version check fails)
        if (indexIsShared && !checkVersion())
        {
            releaseReadLock();
            getWriteLock();
            try
            {
                if (mainIndexReader != null)
                {
                    ((ReferenceCounting)mainIndexReader).setInvalidForReuse();
                }
                mainIndexReader = null;
            }
            finally
            {
                getReadLock();
                releaseWriteLock();
            }
        }

        // Build if required
        if (mainIndexReader == null)
        {
            releaseReadLock();
            getWriteLock();
            try
            {
                if (mainIndexReader == null)
                {
                    // Sync with disk image if required
                    doWithFileLock(new LockWork<Object>()
                    {
                        public Object doWork() throws Exception
                        {
                            return null;
                        }

                        public boolean canRetry()
                        {
                            return true;
                        }

                    });
                    mainIndexReader = createMainIndexReader();

                }

            }
            finally
            {
                getReadLock();
                releaseWriteLock();
            }
        }
        // Manage reference counting
        mainIndexReader.incRef();
        if (s_logger.isDebugEnabled())
        {
            s_logger.debug("Main index reader references = " + ((ReferenceCounting) mainIndexReader).getReferenceCount());
        }

        // ALF-10040: Wrap with a one-off CachingIndexReader (with cache disabled) so that LeafScorer behaves and passes through SingleFieldSelectors to the main index readers
        IndexReader reader = ReferenceCountingReadOnlyIndexReaderFactory.createReader(MAIN_READER + GUID.generate(), mainIndexReader, false, config);
        ReferenceCounting refCounting = (ReferenceCounting) reader;
        reader.incRef();
        refCounting.setInvalidForReuse();
        return reader;
    }
    catch (RuntimeException e)
    {
        e.printStackTrace();
        throw e;
    }
    finally
    {
        releaseReadLock();
    }
}