Java Code Examples for

The following examples show how to use These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File:    License: Apache License 2.0 6 votes vote down vote up
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (null == rawLockType) {
    rawLockType = DirectoryFactory.LOCK_TYPE_NATIVE;
    log.warn("No lockType configured, assuming '{}'.", rawLockType);
  final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();
  switch (lockType) {
    case DirectoryFactory.LOCK_TYPE_SIMPLE:
      return SimpleFSLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_NATIVE:
      return NativeFSLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_SINGLE:
      return new SingleInstanceLockFactory();
    case DirectoryFactory.LOCK_TYPE_NONE:
      return NoLockFactory.INSTANCE;
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
          "Unrecognized lockType: " + rawLockType);
Example 2
public void testSimpleLockErrorOnStartup() throws Exception {

  Directory directory = newFSDirectory(new File(initAndGetDataDir(), "index").toPath(), SimpleFSLockFactory.INSTANCE);
  //creates a new IndexWriter without releasing the lock yet
  IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(null));

  try {
    //opening a new core on the same index
    initCore("solrconfig-basic.xml", "schema.xml");
    if (checkForCoreInitException(LockObtainFailedException.class))
    fail("Expected " + LockObtainFailedException.class.getSimpleName());
  } finally {
Example 3
Source Project: lucene-solr   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void testWhetherDeleteAllDeletesWriteLock() throws Exception {
  // Must use SimpleFSLockFactory... NativeFSLockFactory
  // somehow "knows" a lock is held against write.lock
  // even if you remove that file:
  Directory d = newFSDirectory(createTempDir("TestIndexWriter.testWhetherDeleteAllDeletesWriteLock"), SimpleFSLockFactory.INSTANCE);
  RandomIndexWriter w1 = new RandomIndexWriter(random(), d);
  expectThrows(LockObtainFailedException.class, () -> {
    new RandomIndexWriter(random(), d, newIndexWriterConfig(null));

Example 4
 * Inizializzazione dell'indicizzatore.
 * @param dir La cartella locale contenitore dei dati persistenti.
 * @throws ApsSystemException In caso di errore
public void init(File dir) throws ApsSystemException {
    try {
        this.dir =, SimpleFSLockFactory.INSTANCE);
    } catch (Throwable t) {
        logger.error("Error creating directory", t);
        throw new ApsSystemException("Error creating directory", t);
    logger.debug("Indexer: search engine index ok.");