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

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

Introduction

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

Prototype

private SimpleFSLockFactory() 

Source Link

Usage

From source file:com.vmware.demo.sgf.lucene.impl.LuceneGemFireRepositoryImpl.java

License:Apache License

/**
 * Set up stores for indexes/*from ww  w . j av a  2 s.  c o  m*/
 */
public void initialize() {
    if (!hasInitialized) {
        try {
            directory = new NIOFSDirectory(new File(filepath), new SimpleFSLockFactory());
            analyzer = new StandardAnalyzer(Version.LUCENE_40);

            IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_40, analyzer);
            conf.setRAMBufferSizeMB(ramsize);
            conf.setOpenMode(OpenMode.CREATE_OR_APPEND);
            conf.setWriteLockTimeout(2000);
            indexWriter = new IndexWriter(directory, conf);

            // Open a reader/searcher
            searchManager = new SearcherManager(indexWriter, applyAllDeletes, new SearcherFactory());

            hasInitialized = true;

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

License:Apache License

@Test
public void testSimpleLockErrorOnStartup() throws Exception {

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

    ignoreException("locked");
    try {//  w w w .j  a  v  a 2 s  .  c om
        System.setProperty("solr.tests.lockType", "simple");
        //opening a new core on the same index
        initCore("solrconfig-basic.xml", "schema.xml");
        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.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();
    }/*  ww  w.jav 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   w w  w  . jav  a2  s  .c  om
            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.opensolaris.opengrok.index.IndexDatabase.java

License:Open Source License

/**
 * Create a new instance of an Index Database for a given project
 *
 * @param project the project to create the database for
 * @throws java.io.IOException if an error occurs while creating
 * directories//from  w  w  w .j ava 2s .c o  m
 */
public IndexDatabase(Project project) throws IOException {
    this.project = project;
    lockfact = new SimpleFSLockFactory();
    initialize();
}

From source file:org.watermint.sourcecolon.org.opensolaris.opengrok.index.IndexDatabase.java

License:Open Source License

/**
 * Create a new instance of an Index Database for a given project
 *
 * @param project the project to create the database for
 * @throws java.io.IOException if an error occurs while creating directories
 */// ww  w. j a  va 2  s  . c o  m
public IndexDatabase(Project project) throws IOException {
    this.project = project;
    lockFactory = new SimpleFSLockFactory();
    initialize();
}