List of usage examples for org.apache.lucene.store NIOFSDirectory NIOFSDirectory
public NIOFSDirectory(Path path, LockFactory lockFactory) throws IOException
From source file:com.b2international.index.lucene.Directories.java
License:Apache License
/** * Just like {@link #openFile(File)}, but allows you to also specify a custom {@link LockFactory}. *//*from www. j a v a2s.co m*/ public static FSDirectory openFile(final Path path, final LockFactory lockFactory) throws IOException { if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX || Constants.MAC_OS_X) && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { return new MMapDirectory(path, lockFactory); } else if (Constants.WINDOWS) { return new SimpleFSDirectory(path, lockFactory); } else { return new NIOFSDirectory(path, lockFactory); } }
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); }/*from www.j a va2s. c o 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 . j a v a 2 s . c om 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.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.vmware.demo.sgf.lucene.impl.LuceneGemFireRepositoryImpl.java
License:Apache License
/** * Set up stores for indexes/*from w w w .j av a 2 s . c om*/ */ 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:com.zimbra.cs.index.LuceneDirectory.java
License:Open Source License
/** * Creates a new {@link LuceneDirectory} with {@code SingleInstanceLockFactory}. * <p>// w w w. ja v a2 s. co 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:net.paissad.waqtsalat.utils.geoip.WorldCitiesLucene.java
License:Open Source License
/** * Connects to the Lucene index.// w w w . ja v a2s.c o m * * @throws IOException */ private static void connectToIndex() throws IOException { if (getIndexDir() == null) { File destDir = new File(LUCENE_INDEX_PATH); if (Platform.isWindows()) { setIndexDir(new SimpleFSDirectory(destDir, null)); } else { setIndexDir(new NIOFSDirectory(destDir, null)); } } else { logger.trace("Already connected to the lucene index directory ({})", indexDir.toString()); } }
From source file:org.elasticsearch.index.store.fs.DefaultFsDirectoryService.java
License:Apache License
@Override protected Directory newFSDirectory(File location, LockFactory lockFactory) throws IOException { final MMapDirectory mmapDir = new MMapDirectory(location, lockFactory); return new FileSwitchDirectory(PRIMARY_EXTENSIONS, mmapDir, new NIOFSDirectory(location, lockFactory), true) {/*from w w w .j a va 2 s .c o m*/ @Override public String[] listAll() throws IOException { // Avoid doing listAll twice: return mmapDir.listAll(); } }; }
From source file:org.elasticsearch.index.store.fs.NioFsDirectoryService.java
License:Apache License
@Override protected FSDirectory newFSDirectory(File location, LockFactory lockFactory) throws IOException { return new NIOFSDirectory(location, lockFactory); }
From source file:org.elasticsearch.index.store.fs.NioFsStore.java
License:Apache License
@Inject public NioFsStore(ShardId shardId, @IndexSettings Settings indexSettings, IndexStore indexStore, ByteBufferCache byteBufferCache) throws IOException { super(shardId, indexSettings, indexStore); LockFactory lockFactory = buildLockFactory(); File location = ((FsIndexStore) indexStore).shardIndexLocation(shardId); location.mkdirs();/* ww w . j ava2 s . co m*/ this.fsDirectory = new NIOFSDirectory(location, lockFactory); boolean suggestUseCompoundFile; Tuple<SwitchDirectory, Boolean> switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory, byteBufferCache); if (switchDirectory != null) { suggestUseCompoundFile = DEFAULT_SUGGEST_USE_COMPOUND_FILE; if (switchDirectory.v2() != null) { suggestUseCompoundFile = switchDirectory.v2(); } logger.debug("using [nio_fs] store with path [{}], cache [true] with extensions [{}]", fsDirectory.getDirectory(), switchDirectory.v1().primaryExtensions()); directory = wrapDirectory(switchDirectory.v1()); } else { suggestUseCompoundFile = DEFAULT_SUGGEST_USE_COMPOUND_FILE; directory = wrapDirectory(fsDirectory); logger.debug("using [nio_fs] store with path [{}]", fsDirectory.getDirectory()); } this.suggestUseCompoundFile = suggestUseCompoundFile; }