Example usage for org.apache.lucene.store NativeFSLockFactory NativeFSLockFactory

List of usage examples for org.apache.lucene.store NativeFSLockFactory NativeFSLockFactory

Introduction

In this page you can find the example usage for org.apache.lucene.store NativeFSLockFactory NativeFSLockFactory.

Prototype

private NativeFSLockFactory() 

Source Link

Usage

From source file:ccc.plugins.search.lucene.SimpleLuceneFS.java

License:Open Source License

private Directory createDirectory() throws IOException {
    return FSDirectory.open(new java.io.File(_indexPath), new NativeFSLockFactory());
}

From source file:com.netflix.exhibitor.core.index.LogSearch.java

License:Apache License

public LogSearch(File file) throws Exception {
    this.file = file;
    directory = new NIOFSDirectory(file, new NativeFSLockFactory());
    reader = IndexReader.open(directory);
    searcher = new IndexSearcher(reader);
}

From source file:com.novartis.pcs.ontology.service.search.OntologySearchServiceImpl.java

License:Apache License

@PostConstruct
public void start() {
    try {/* w ww .  j  av  a 2 s  . co  m*/
        Analyzer analyzer = new TermNameAnalyzer(true);
        File indexPath = new File(path);

        if (!indexPath.exists()) {
            indexPath.mkdirs();
        }

        directory = new MMapDirectory(indexPath, new NativeFSLockFactory());
        if (MMapDirectory.UNMAP_SUPPORTED) {
            ((MMapDirectory) directory).setUseUnmap(true);
        }
        boolean indexExists = IndexReader.indexExists(directory);

        writer = new IndexWriter(directory, analyzer, new IndexWriter.MaxFieldLength(MAX_CHARS));

        if (!indexExists) {
            logger.info("Building ontology search index.");
            Collection<Term> terms = termDAO.loadAll();
            for (Term term : terms) {
                if (StatusChecker.isValid(term)) {
                    Collection<Document> docs = createDocuments(term);
                    for (Document doc : docs) {
                        writer.addDocument(doc);
                    }
                }
            }
        }
        writer.optimize();
        writer.commit();
        numberOfDocuments = writer.numDocs();
        xar = new LuceneIndexWriterXAResource(writer, this);
        reader = IndexReader.open(directory, true);
        searcher = new IndexSearcher(reader);
        rwlock = new ReentrantReadWriteLock();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to start Lucene term searcher", e);
        stop();
        throw new RuntimeException("Failed to start Lucene term searcher", e);
    }
}

From source file:org.apache.solr.core.SolrCoreCheckLockOnStartupTest.java

License:Apache License

@Test
public void testNativeLockErrorOnStartup() throws Exception {

    File indexDir = new File(dataDir, "index");
    log.info("Acquiring lock on {}", indexDir.getAbsolutePath());
    Directory directory = newFSDirectory(indexDir, new NativeFSLockFactory());
    //creates a new IndexWriter without releasing the lock yet
    IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null));

    ignoreException("locked");
    try {/*from w  ww  .  j  ava2 s.  c  o m*/
        System.setProperty("solr.tests.lockType", "native");
        //opening a new core on the same index
        initCore("solrconfig-basic.xml", "schema.xml");
        CoreContainer cc = h.getCoreContainer();
        if (checkForCoreInitException(LockObtainFailedException.class))
            return;
        fail("Expected " + LockObtainFailedException.class.getSimpleName());
    } finally {
        System.clearProperty("solr.tests.lockType");
        unIgnoreException("locked");
        indexWriter.close();
        directory.close();
        deleteCore();
    }
}

From source file:org.eclipse.vorto.remoterepository.VortoTestApplication.java

License:Open Source License

@Bean(name = "fsDirectory")
@DependsOn("analyzer")
public FSDirectory getFSDirectory() {
    FSDirectory fsd = null;//from   w  w  w .  ja  va  2  s .co m

    Path indexLocation = Paths.get("src/test/resources/temp/lucent");

    File location = indexLocation.toFile();

    if (!location.exists() || !location.canRead()) {
        log.info("Creating index directory: '" + location.getAbsolutePath() + "'");
        location.mkdirs();
    }

    try {
        fsd = FSDirectory.open(location, new NativeFSLockFactory());
    } catch (IOException e) {
        log.log(Level.SEVERE, " IOException for creating Indexing folder", e);
    }

    return fsd;
}

From source file:org.elasticsearch.index.store.fs.FsDirectoryService.java

License:Apache License

protected final LockFactory buildLockFactory() throws IOException {
    String fsLock = componentSettings.get("lock", componentSettings.get("fs_lock", "native"));
    LockFactory lockFactory = NoLockFactory.getNoLockFactory();
    if (fsLock.equals("native")) {
        // TODO LUCENE MONITOR: this is not needed in next Lucene version
        lockFactory = new NativeFSLockFactory();
    } else if (fsLock.equals("simple")) {
        lockFactory = new SimpleFSLockFactory();
    } else if (fsLock.equals("none")) {
        lockFactory = NoLockFactory.getNoLockFactory();
    }//  w  w w . ja  v a2 s .c o m
    return lockFactory;
}

From source file:org.elasticsearch.index.store.fs.FsStore.java

License:Apache License

protected LockFactory buildLockFactory() throws IOException {
    String fsLock = componentSettings.get("fs_lock", "native");
    LockFactory lockFactory = new NoLockFactory();
    if (fsLock.equals("native")) {
        // TODO LUCENE MONITOR: this is not needed in next Lucene version
        lockFactory = new NativeFSLockFactory() {
            @Override//from   ww  w .ja v a 2 s.  c o  m
            public void clearLock(String lockName) throws IOException {
                // Note that this isn't strictly required anymore
                // because the existence of these files does not mean
                // they are locked, but, still do this in case people
                // really want to see the files go away:
                if (lockDir.exists()) {

                    // Try to release the lock first - if it's held by another process, this
                    // method should not silently fail.
                    // NOTE: makeLock fixes the lock name by prefixing it w/ lockPrefix.
                    // Therefore it should be called before the code block next which prefixes
                    // the given name.
                    makeLock(lockName).release();

                    if (lockPrefix != null) {
                        lockName = lockPrefix + "-" + lockName;
                    }

                    // As mentioned above, we don't care if the deletion of the file failed.
                    new File(lockDir, lockName).delete();
                }
            }
        };
    } else if (fsLock.equals("simple")) {
        lockFactory = new SimpleFSLockFactory();
    }
    return lockFactory;
}

From source file:org.exoplatform.services.jcr.impl.core.query.lucene.directory.FSDirectoryManager.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w w  .ja v a 2s .  c  om*/
 */
public Directory getDirectory(final String name) throws IOException {
    return SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Directory>() {
        public Directory run() throws Exception {
            File dir;
            if (name.equals(".")) {
                dir = baseDir;
            } else {
                dir = new File(baseDir, name);
            }
            // FSDirectory itself doesnt create dirs now
            if (!dir.exists()) {
                if (!dir.mkdirs()) {
                    throw new IOException("Cannot create directory: " + dir);
                }
            }
            LockFactory lockFactory = (LOCK_FACTORY_CLASS == null) ? new NativeFSLockFactory()
                    : (LockFactory) LOCK_FACTORY_CLASS.newInstance();

            if (FS_DIRECTORY_CLASS == null) {
                return FSDirectory.open(dir, lockFactory);
            } else {
                Constructor<? extends FSDirectory> constructor = FS_DIRECTORY_CLASS.getConstructor(File.class,
                        LockFactory.class);
                return constructor.newInstance(dir, lockFactory);
            }
        }
    });
}