List of usage examples for org.apache.lucene.index IndexReader getRefCount
public final int getRefCount()
From source file:org.apache.blur.manager.writer.BlurIndexCloser.java
License:Apache License
private void tryToCloseReaders() { LOG.debug("Trying to close [{0}] readers", readers.size()); Iterator<IndexReader> it = readers.iterator(); while (it.hasNext()) { IndexReader reader = it.next(); if (reader.getRefCount() == 1) { it.remove();//from w w w.ja va 2 s. c o m closeInternal(reader); } else { LOG.debug("Could not close indexreader [" + reader + "] because of ref count [" + reader.getRefCount() + "]."); } } }
From source file:org.apache.blur.manager.writer.BlurIndexCloser.java
License:Apache License
private void closeInternal(final IndexReader reader) { if (reader.getRefCount() == 0) { // Already closed. return;/* w ww. ja v a2s . co m*/ } executorService.submit(new Runnable() { @Override public void run() { try { long s = System.currentTimeMillis(); reader.close(); long e = System.currentTimeMillis(); LOG.debug("Size [{0}] time to close [{1}] Closing indexreader [{2}].", readers.size(), (e - s), reader); } catch (Exception e) { readers.add(reader); LOG.error("Error while trying to close indexreader [" + reader + "].", e); } } }); }
From source file:org.apache.jena.larq.TestLuceneNRT.java
License:Apache License
@Test public void indexReaderOpenDirectory() throws Exception { IndexReader reader = IndexReader.open(directory); assertNotNull(reader);//from w ww . j ava 2 s . c om assertSame(directory, reader.directory()); assertEquals(1, reader.getRefCount()); assertTrue(reader.isCurrent()); assertEquals(0, reader.maxDoc()); close(reader); assertEquals(0, reader.getRefCount()); }
From source file:org.apache.jena.larq.TestLuceneNRT.java
License:Apache License
@Test public void indexReaderOpenWriter() throws Exception { IndexReader reader = IndexReader.open(writer, true); assertNotNull(reader);/*from w ww .j av a2 s .com*/ assertSame(directory, reader.directory()); assertEquals(1, reader.getRefCount()); assertTrue(reader.isCurrent()); assertEquals(0, reader.maxDoc()); close(reader); assertEquals(0, reader.getRefCount()); }
From source file:org.mulgara.resolver.lucene.LuceneIndexerCache.java
License:Apache License
/** Force the reader closed by cleaning up outstanding references. * @throws IOException *//*from ww w. j av a 2 s. co m*/ private static void forceClose(IndexReader reader) throws IOException { try { if (reader.getRefCount() > 1) { // This likely indicates a FullTextStringIndexTuples that was not properly closed. // Closing it now is likely to break any existing references to it. logger.warn("Forcing close of a reader that was returned to the cache with active references: " + System.identityHashCode(reader)); while (reader.getRefCount() > 1) { reader.decRef(); } } } catch (IOException e) { logger.error("Can't decrement reference count to abandoned reader", e); throw e; } finally { reader.close(); } }
From source file:org.weborganic.flint.SearcherManager.java
License:artistic-license-2.0
/** * Check if the reader provided is not current and not used anymore in which case it is closed. * * @param reader the reader to check/*w w w . j ava2 s .c o m*/ * * @throws IOException if closing failed */ private void closeIfDirty(IndexReader reader) throws IOException { // check if we should close an old one if (this.currentSearcher.getIndexReader() != reader) { if (reader.getRefCount() == 0) { LOGGER.debug("Closing reader {}", reader.hashCode()); try { reader.close(); } catch (AlreadyClosedException e) { // good then, no need to worry } } else { LOGGER.debug("Cannot close reader {} as there are still references ({})", reader.hashCode(), reader.getRefCount()); } } }