@Test public void reuseExistingDir() throws Exception{ LuceneIndexDefinition defn = LuceneIndexDefinition.newBuilder(root, idx.getNodeState(), "/fooIndex").build(); FSDirectoryFactory factory = new FSDirectoryFactory(temporaryFolder.getRoot()); Directory dir = factory.newInstance(defn, idx, ":data", false); File fsDir1 = ((FSDirectory)dir).getDirectory(); dir.close(); Directory dir2 = factory.newInstance(defn, idx, ":data", false); File fsDir2 = ((FSDirectory)dir2).getDirectory(); dir2.close(); assertEquals(fsDir1, fsDir2); assertEquals(1, temporaryFolder.getRoot().list(DirectoryFileFilter.DIRECTORY).length); }
@Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } FSDirectoryFactory(File baseDir); }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } FSDirectoryFactory(File baseDir); @Override Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder,
                                 String dirName, boolean reindex); @Override boolean remoteDirectory(); }
FSDirectoryFactory implements DirectoryFactory { @Override public Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder, String dirName, boolean reindex) throws IOException { File indexDir = DirectoryUtils.createIndexDir(baseDir, definition.getIndexPath()); File readMe = new File(indexDir, INDEX_METADATA_FILE_NAME); File subDir = DirectoryUtils.createSubDir(indexDir, dirName); FileUtils.forceMkdir(subDir); IndexMeta meta; if (!readMe.exists()) { meta = new IndexMeta(definition.getIndexPath()); } else { meta = new IndexMeta(readMe); } meta.addDirectoryMapping(dirName, subDir.getName()); DirectoryUtils.writeMeta(indexDir, meta); return FSDirectory.open(subDir, NoLockFactory.getNoLockFactory()); } FSDirectoryFactory(File baseDir); @Override Directory newInstance(LuceneIndexDefinition definition, NodeBuilder builder,
                                 String dirName, boolean reindex); @Override boolean remoteDirectory();  }