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

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

Introduction

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

Prototype

SingleInstanceLockFactory

Source Link

Usage

From source file:com.gemstone.gemfire.cache.lucene.internal.directory.RegionDirectory.java

License:Apache License

/**
 * Create a region directory with a given file and chunk region. These regions
 * may be bucket regions or they may be replicated regions.
 *///w  w w.ja  v a 2  s  .  c  om
public RegionDirectory(ConcurrentMap<String, File> fileRegion, ConcurrentMap<ChunkKey, byte[]> chunkRegion) {
    super(new SingleInstanceLockFactory());
    fs = new FileSystem(fileRegion, chunkRegion);
}

From source file:com.github.rnewson.couchdb.lucene.DatabaseIndexer.java

License:Apache License

private void init() throws IOException, JSONException {
    this.uuid = database.getOrCreateUuid();

    this.context = Context.enter();
    context.setClassShutter(new RestrictiveClassShutter());
    context.setOptimizationLevel(9);/*from  w w w. j  a  v a  2 s. c o m*/

    this.ddoc_seq = database.getInfo().getUpdateSequence();
    this.since = null;

    for (final DesignDocument ddoc : database.getAllDesignDocuments()) {
        for (final Entry<String, View> entry : ddoc.getAllViews().entrySet()) {
            final String name = entry.getKey();
            final View view = entry.getValue();
            paths.put(toPath(ddoc.getId(), name), view);

            if (!states.containsKey(view)) {
                final Directory dir = FSDirectory.open(viewDir(view, true), new SingleInstanceLockFactory());
                final UpdateSequence seq = getUpdateSequence(dir);
                if (since == null) {
                    since = seq;
                }
                since = seq.isEarlierThan(since) ? seq : since;
                logger.debug(dir + " bumped since to " + since);

                final DocumentConverter converter = new DocumentConverter(context, view);
                final IndexWriter writer = newWriter(dir);

                final IndexState state = new IndexState(converter, writer, view.getAnalyzer(), database, view);
                state.setPendingSequence(seq);
                states.put(view, state);
            }
        }
    }
    if (since == null) {
        since = UpdateSequence.START;
    }
    logger.debug("paths: " + paths);

    this.lastCommit = now();
    latch.countDown();
}

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

License:Apache License

public void open() throws Exception {
    if (!directory.exists() && !directory.mkdirs()) {
        throw new IOException("Could not make: " + directory);
    }//  w w  w.j ava  2 s  .  co  m

    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer())
            .setOpenMode(IndexWriterConfig.OpenMode.CREATE);

    niofsDirectory = new NIOFSDirectory(directory, new SingleInstanceLockFactory());
    writer = new IndexWriter(niofsDirectory, conf);
}

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

License:Apache License

public LogIndexer(Exhibitor exhibitor, InputSupplier<InputStream> source, String sourceName, long sourceLength,
        File indexDirectory) throws Exception {
    this.exhibitor = exhibitor;
    if (!indexDirectory.exists() && !indexDirectory.mkdirs()) {
        throw new IOException("Could not make: " + indexDirectory);
    }/*  w  w  w.  ja v a 2  s.c  o m*/
    this.sourceLength = sourceLength;
    this.sourceName = sourceName;

    this.indexDirectory = indexDirectory;
    inputStream = new CountingInputStream(new BufferedInputStream(source.getInput()));

    IndexWriter localWriter = null;
    NIOFSDirectory localDirectory = null;

    logParser = new ZooKeeperLogParser(inputStream);
    if (logParser.isValid()) {
        IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer())
                .setOpenMode(IndexWriterConfig.OpenMode.CREATE);

        localDirectory = new NIOFSDirectory(indexDirectory, new SingleInstanceLockFactory());
        localWriter = new IndexWriter(localDirectory, conf);
    }
    writer = localWriter;
    directory = localDirectory;
}

From source file:com.zimbra.cs.index.LuceneDirectory.java

License:Open Source License

/**
 * Creates a new {@link LuceneDirectory} with {@code SingleInstanceLockFactory}.
 * <p>//from   w  w  w.  j  av  a2s  . c o m
 * You can switch Lucene's {@link FSDirectory} implementation by {@link LC#zimbra_index_lucene_io_impl}.
 * <ul>
 *  <li>{@code null} -Lucene will try to pick the best {@link FSDirectory} implementation given the current
 *      environment. Currently this returns {@link MMapDirectory} for most Solaris and Windows 64-bit JREs,
 *      {@link NIOFSDirectory} for other non-Windows JREs, and {@link SimpleFSDirectory} for other JREs on Windows.
 *  <li>{@code simple} - straightforward implementation using java.io.RandomAccessFile. However, it has poor
 *      concurrent performance (multiple threads will bottleneck) as it synchronizes when multiple threads read from
 *      the same file.
 *  <li>{@code nio} - uses java.nio's FileChannel's positional io when reading to avoid synchronization when reading
 *      from the same file. Unfortunately, due to a Windows-only Sun JRE bug this is a poor choice for Windows, but
 *      on all other platforms this is the preferred choice.
 *  <li>{@code mmap} - uses memory-mapped IO when reading. This is a good choice if you have plenty of virtual
 *      memory relative to your index size, eg if you are running on a 64 bit JRE, or you are running on a 32 bit
 *      JRE but your index sizes are small enough to fit into the virtual memory space. Java has currently the
 *      limitation of not being able to unmap files from user code. The files are unmapped, when GC releases the
 *      byte buffers. Due to this bug in Sun's JRE, MMapDirectory's IndexInput.close() is unable to close the
 *      underlying OS file handle. Only when GC finally collects the underlying objects, which could be quite some
 *      time later, will the file handle be closed. This will consume additional transient disk usage: on Windows,
 *      attempts to delete or overwrite the files will result in an exception; on other platforms, which typically
 *      have a "delete on last close" semantics, while such operations will succeed, the bytes are still consuming
 *      space on disk. For many applications this limitation is not a problem (e.g. if you have plenty of disk
 *      space, and you don't rely on overwriting files on Windows) but it's still an important limitation to be
 *      aware of. This class supplies a (possibly dangerous) workaround mentioned in the bug report, which may fail
 *      on non-Sun JVMs.
 * </ul>
 *
 * @param path directory path
 */
public static LuceneDirectory open(File path) throws IOException {
    String impl = LC.zimbra_index_lucene_io_impl.value();
    FSDirectory dir;
    if ("nio".equals(impl)) {
        dir = new NIOFSDirectory(path, new SingleInstanceLockFactory());
    } else if ("mmap".equals(impl)) {
        dir = new MMapDirectory(path, new SingleInstanceLockFactory());
    } else if ("simple".equals(impl)) {
        dir = new SimpleFSDirectory(path, new SingleInstanceLockFactory());
    } else {
        dir = FSDirectory.open(path, new SingleInstanceLockFactory());
    }
    ZimbraLog.index.info("OpenLuceneIndex impl=%s,dir=%s", dir.getClass().getSimpleName(), path);
    return new LuceneDirectory(dir);
}

From source file:edu.stanford.muse.index.Indexer.java

License:Apache License

private synchronized Directory initializeDirectory(Directory dir, String name) throws IOException {
    if (dir == null)
        dir = createDirectory(name);//from w  w  w  . j av  a 2  s  .  c  om
    if (dir.getLockFactory() == null)
        dir.setLockFactory(new SingleInstanceLockFactory());
    return dir;
}

From source file:it.agilelab.bigdata.spark.search.impl.BigChunksRAMDirectory.java

License:Apache License

/** Constructs an empty {@link Directory}. */
public BigChunksRAMDirectory() {
    this(new SingleInstanceLockFactory());
}

From source file:jetbrains.exodus.lucene.DebugExodusDirectory.java

License:Apache License

public DebugExodusDirectory(@NotNull final ContextualEnvironment env) throws IOException {
    this(env, new SingleInstanceLockFactory());
}

From source file:jetbrains.exodus.lucene.ExodusDirectory.java

License:Apache License

public ExodusDirectory(@NotNull final ContextualEnvironment env) throws IOException {
    this(env, new SingleInstanceLockFactory());
}

From source file:org.apache.derby.optional.lucene.DerbyLuceneDir.java

License:Apache License

/**
 * <p>//w ww .  ja v a  2 s .c  o  m
 * Lookup a directory, creating its path as necessary.
 * </p>
 */
static synchronized DerbyLuceneDir getDirectory(StorageFactory storageFactory, String schema, String table,
        String textcol) throws SQLException {
    DerbyLuceneDir candidate = new DerbyLuceneDir(storageFactory, schema, table, textcol);
    String key = getKey(candidate);
    DerbyLuceneDir result = _openDirectories.get(key);

    if (result == null) {
        result = candidate;
        result.setLockFactory(new SingleInstanceLockFactory());
        _openDirectories.put(key, result);
    }

    return result;
}