当前位置: 首页>>代码示例>>Java>>正文


Java AlreadyClosedException类代码示例

本文整理汇总了Java中org.apache.lucene.store.AlreadyClosedException的典型用法代码示例。如果您正苦于以下问题:Java AlreadyClosedException类的具体用法?Java AlreadyClosedException怎么用?Java AlreadyClosedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AlreadyClosedException类属于org.apache.lucene.store包,在下文中一共展示了AlreadyClosedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: commit

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
/**
 * Commits any changes since the last commit or rollback.
 * Afterwards a new {@link IndexReader} will be created.
 * @throws IOException if there is a low-level IO error
 */
void commit() throws IOException {
	try {
		writer.commit();

		if(writer.hasDeletions()) {
			writer.forceMergeDeletes(); // delete now the documents which are marked to delete.
		}
	}
	catch(final AlreadyClosedException e) {
		reopenIndex();
	}
	finally {
		unlock();

		// new reader because new data is available.
		createReader();
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:24,代码来源:Index.java

示例2: flushAndClose

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
/**
 * Flush the engine (committing segments to disk and truncating the
 * translog) and close it.
 */
public void flushAndClose() throws IOException {
    if (isClosed.get() == false) {
        logger.trace("flushAndClose now acquire writeLock");
        try (ReleasableLock lock = writeLock.acquire()) {
            logger.trace("flushAndClose now acquired writeLock");
            try {
                logger.debug("flushing shard on close - this might take some time to sync files to disk");
                try {
                    flush(); // TODO we might force a flush in the future since we have the write lock already even though recoveries are running.
                } catch (AlreadyClosedException ex) {
                    logger.debug("engine already closed - skipping flushAndClose");
                }
            } finally {
                close(); // double close is not a problem
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:Engine.java

示例3: maybeFailEngine

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
@Override
protected boolean maybeFailEngine(String source, Exception e) {
    boolean shouldFail = super.maybeFailEngine(source, e);
    if (shouldFail) {
        return true;
    }
    // Check for AlreadyClosedException -- ACE is a very special
    // exception that should only be thrown in a tragic event. we pass on the checks to failOnTragicEvent which will
    // throw and AssertionError if the tragic event condition is not met.
    if (e instanceof AlreadyClosedException) {
        return failOnTragicEvent((AlreadyClosedException)e);
    } else if (e != null &&
            ((indexWriter.isOpen() == false && indexWriter.getTragicException() == e)
                    || (translog.isOpen() == false && translog.getTragicException() == e))) {
        // this spot on - we are handling the tragic event exception here so we have to fail the engine
        // right away
        failEngine(source, e);
        return true;
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:InternalEngine.java

示例4: maybeFSyncTranslogs

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
private void maybeFSyncTranslogs() {
    if (indexSettings.getTranslogDurability() == Translog.Durability.ASYNC) {
        for (IndexShard shard : this.shards.values()) {
            try {
                Translog translog = shard.getTranslog();
                if (translog.syncNeeded()) {
                    translog.sync();
                }
            } catch (AlreadyClosedException ex) {
                // fine - continue;
            } catch (IOException e) {
                logger.warn("failed to sync translog", e);
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:IndexService.java

示例5: maybeRefreshEngine

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
private void maybeRefreshEngine() {
    if (indexSettings.getRefreshInterval().millis() > 0) {
        for (IndexShard shard : this.shards.values()) {
            switch (shard.state()) {
                case CREATED:
                case RECOVERING:
                case CLOSED:
                    continue;
                case POST_RECOVERY:
                case STARTED:
                case RELOCATED:
                    try {
                        if (shard.isRefreshNeeded()) {
                            shard.refresh("schedule");
                        }
                    } catch (IndexShardClosedException | AlreadyClosedException ex) {
                        // fine - continue;
                    }
                    continue;
                default:
                    throw new IllegalStateException("unknown state: " + shard.state());
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:IndexService.java

示例6: maybeUpdateGlobalCheckpoints

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
private void maybeUpdateGlobalCheckpoints() {
    for (IndexShard shard : this.shards.values()) {
        if (shard.routingEntry().primary()) {
            switch (shard.state()) {
                case CREATED:
                case RECOVERING:
                case CLOSED:
                case RELOCATED:
                    continue;
                case POST_RECOVERY:
                case STARTED:
                    try {
                        shard.updateGlobalCheckpointOnPrimary();
                    } catch (AlreadyClosedException ex) {
                        // fine - continue, the shard was concurrently closed on us.
                    }
                    continue;
                default:
                    throw new IllegalStateException("unknown state: " + shard.state());
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:IndexService.java

示例7: handleRefreshException

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
private void handleRefreshException(Exception e) {
    if (e instanceof AlreadyClosedException) {
        // ignore
    } else if (e instanceof RefreshFailedEngineException) {
        RefreshFailedEngineException rfee = (RefreshFailedEngineException) e;
        if (rfee.getCause() instanceof InterruptedException) {
            // ignore, we are being shutdown
        } else if (rfee.getCause() instanceof ClosedByInterruptException) {
            // ignore, we are being shutdown
        } else if (rfee.getCause() instanceof ThreadInterruptedException) {
            // ignore, we are being shutdown
        } else {
            if (state != IndexShardState.CLOSED) {
                logger.warn("Failed to perform engine refresh", e);
            }
        }
    } else {
        if (state != IndexShardState.CLOSED) {
            logger.warn("Failed to perform engine refresh", e);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:IndexShard.java

示例8: testAddingAClosedReader

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
public void testAddingAClosedReader() throws Exception {
    LeafReader reader;
    try (Directory dir = newDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(random(), dir)) {
        writer.addDocument(new Document());
        try (DirectoryReader dirReader = ElasticsearchDirectoryReader.wrap(writer.getReader(), new ShardId("index1", "_na_", 1))) {
            reader = dirReader.leaves().get(0).reader();
        }
    }
    ShardCoreKeyMap map = new ShardCoreKeyMap();
    try {
        map.add(reader);
        fail("Expected AlreadyClosedException");
    } catch (AlreadyClosedException e) {
        // What we wanted
    }
    assertEquals(0, map.size());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ShardCoreKeyMapTests.java

示例9: execute

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
/**
 * Executes the provided operation against this store
 */
// we can do FS ops with only two elevated permissions:
// 1) hadoop dynamic proxy is messy with access rules
// 2) allow hadoop to add credentials to our Subject
<V> V execute(Operation<V> operation) throws IOException {
    SpecialPermission.check();
    if (closed) {
        throw new AlreadyClosedException("HdfsBlobStore is closed: " + this);
    }
    try {
        return AccessController.doPrivileged((PrivilegedExceptionAction<V>)
                () -> operation.run(fileContext), null, new ReflectPermission("suppressAccessChecks"),
                 new AuthPermission("modifyPrivateCredentials"), new SocketPermission("*", "connect"));
    } catch (PrivilegedActionException pae) {
        throw (IOException) pae.getException();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:HdfsBlobStore.java

示例10: getAllDescendantReaderKeys

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
/**
 * Checks if the seed is an IndexReader, and if so will walk
 * the hierarchy of subReaders building up a list of the objects 
 * returned by {@code seed.getCoreCacheKey()}
 */
private List<Object> getAllDescendantReaderKeys(Object seed) {
  List<Object> all = new ArrayList<>(17); // will grow as we iter
  all.add(seed);
  for (int i = 0; i < all.size(); i++) {
    final Object obj = all.get(i);
    // TODO: We don't check closed readers here (as getTopReaderContext
    // throws AlreadyClosedException), what should we do? Reflection?
    if (obj instanceof IndexReader) {
      try {
        final List<IndexReaderContext> childs =
          ((IndexReader) obj).getContext().children();
        if (childs != null) { // it is composite reader
          for (final IndexReaderContext ctx : childs) {
            all.add(ctx.reader().getCoreCacheKey());
          }
        }
      } catch (AlreadyClosedException ace) {
        // ignore this reader
      }
    }
  }
  // need to skip the first, because it was the seed
  return all.subList(1, all.size());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:FieldCacheSanityChecker.java

示例11: run

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
@Override
public void run() {
  int i = 0;
  while (i < 10000) {
    try {
      if (data.size() <= i) {
        sleep(1);
        continue;
      }
      final String key = "key" + i;
      final String val = "value" + i;
      final List<Document> documents = index.searchForDocuments(new TermQuery(new Term(key, val)), 10, new Sort(new SortField(key, SortField.Type.STRING)));
      if (documents.size() != 1) {
        throw new RuntimeException("Invalid number of matching documents for " + key + ", found " + documents);
      }
      ++i;
    } catch (IOException ioe) {
      error = ioe;
      break;
    } catch (InterruptedException e) {
    } catch (AlreadyClosedException ace) {
      error = ace;
      break;
    }
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:27,代码来源:TestLuceneIndexer.java

示例12: close

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
@Override
public void close() throws IOException {
    synchronized (lock) {
        if (isOpen()) {
            try {
                flush();
            } catch (AlreadyClosedException ignore) { }
        }

        if (searcherManager != null) {
            searcherManager.close();
            searcherManager = null;
        }
        if (writer != null) {
            writer.close();
            writer = null;
        }
        if (owningDirectory) {
            if (directory != null) {
                directory.close();
                directory = null;
            }
        }
    }
}
 
开发者ID:Sproutigy,项目名称:LucenePlus,代码行数:26,代码来源:LuceneIndex.java

示例13: getDocument

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
/**
 *  Gets the Lucene {@link org.apache.lucene.document.Document} associated with this ResultDoc. If the index
 *  has changed since the search was conducted, this method may return an empty or incorrect Document. It is
 *  therefore best to read all Documents as soon as possible after a search if the index is being
 *  concurrently modified.
 *
 * @return    The {@link org.apache.lucene.document.Document} associated with this ResultDoc.
 */
public final Document getDocument() {
	try {
		if (_document == null)
			_document = _resultDocConfig.index.getReader().document(_docNum);
		return _document;
	} catch (AlreadyClosedException ace) {
		prtlnErr("Error retrieving document: The current IndexReader is already closed.");			
	} catch (IllegalArgumentException iae) {
		// IllegalArgumentException is thrown when index has changed since the search was performed and _docNum is no longer valid:
		prtlnErr("Error retrieving document: Lucene docID " + _docNum + " is no longer valid.");	
	} catch (Throwable e) {
		prtlnErr("Error retrieving document: " + e);
		e.printStackTrace();
	}
	
	// If all else fails, return empty document:
	return new Document();
}
 
开发者ID:NCAR,项目名称:dls-repository-stack,代码行数:27,代码来源:ResultDoc.java

示例14: close

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
/**
 * Closes the handler, releases resources and flushes the recent index changes
 * to persistent storage.
 */
@Override
public synchronized void close() {
  if (isClosed) {
    throw new AlreadyClosedException("Already closed");
  }
  isClosed = true;
  try {
    nrtManager.close();
    if (analyzer != null) {
      analyzer.close();
    }
    nrtManagerReopenThread.close();
    indexWriter.close();
  } catch (IOException ex) {
    LOG.log(Level.SEVERE, "Failed to close the Lucene index", ex);
  }
  LOG.info("Successfully closed the Lucene index...");
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:23,代码来源:LuceneSearchImpl.java

示例15: swapSearcher

import org.apache.lucene.store.AlreadyClosedException; //导入依赖的package包/类
private void swapSearcher(final Directory dir) throws IOException {
  /*
   * opening a searcher is possibly very expensive.
   * We rather close it again if the Spellchecker was closed during
   * this operation than block access to the current searcher while opening.
   */
  final IndexSearcher indexSearcher = createSearcher(dir);
  synchronized (searcherLock) {
    if(closed){
      indexSearcher.getIndexReader().close();
      throw new AlreadyClosedException("Spellchecker has been closed");
    }
    if (searcher != null) {
      searcher.getIndexReader().close();
    }
    // set the spellindex in the sync block - ensure consistency.
    searcher = indexSearcher;
    this.spellIndex = dir;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:SpellChecker.java


注:本文中的org.apache.lucene.store.AlreadyClosedException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。