@Override public void run() { try { db.update(parallelizer); } catch (Throwable e) { LOGGER.log(Level.SEVERE, String.format("Problem updating index database in directory %s: ", db.indexDirectory.getDirectory()), e); } } });
private RAMDirectory(FSDirectory dir, boolean closeDir, IOContext context) throws IOException { this(); for (String file : dir.listAll()) { if (!Files.isDirectory(dir.getDirectory().resolve(file))) { copyFrom(dir, file, file, context); } } if (closeDir) { dir.close(); } }
@Override protected Lock obtainFSLock(FSDirectory dir, String lockName) throws IOException { Path lockDir = dir.getDirectory(); // Ensure that lockDir exists and is a directory. // note: this will fail if lockDir is a symlink Files.createDirectories(lockDir); Path lockFile = lockDir.resolve(lockName); // create the file: this will fail if it already exists try { Files.createFile(lockFile); } catch (FileAlreadyExistsException | AccessDeniedException e) { // convert optional specific exception to our optional specific exception throw new LockObtainFailedException("Lock held elsewhere: " + lockFile, e); } // used as a best-effort check, to see if the underlying file has changed final FileTime creationTime = Files.readAttributes(lockFile, BasicFileAttributes.class).creationTime(); return new SimpleFSLock(lockFile, creationTime); }
@Override protected Lock obtainFSLock(FSDirectory dir, String lockName) throws IOException { Path lockDir = dir.getDirectory();
/** If the dir is an {@link FSDirectory} or wraps one via possibly * nested {@link FilterDirectory} or {@link FileSwitchDirectory}, * this returns {@link #spins(Path)} for the wrapped directory, * else, true. * * @throws IOException if {@code path} does not exist. * * @lucene.internal */ public static boolean spins(Directory dir) throws IOException { dir = FilterDirectory.unwrap(dir); if (dir instanceof FileSwitchDirectory) { FileSwitchDirectory fsd = (FileSwitchDirectory) dir; // Spinning is contagious: return spins(fsd.getPrimaryDir()) || spins(fsd.getSecondaryDir()); } else if (dir instanceof RAMDirectory) { return false; } else if (dir instanceof FSDirectory) { return spins(((FSDirectory) dir).getDirectory()); } else { return true; } }
/** Returns the directory instance for the named location. * @param file the path to the directory. * @return the FSDirectory for the named file. */ public static FSDirectory getDirectory(File file) throws IOException { return getDirectory(file, null); }
/** * Creates a new <code>RAMDirectory</code> instance from the {@link FSDirectory}. * * @param dir a <code>String</code> specifying the full index directory path */ public RAMDirectory(String dir) throws IOException { this(FSDirectory.getDirectory(dir, false), true); }
/** Returns the directory instance for the named location. * @param path the path to the directory. * @return the FSDirectory for the named file. */ public static FSDirectory getDirectory(String path) throws IOException { return getDirectory(new File(path), null); }
/** Returns the directory instance for the named location. * @param path the path to the directory. * @param lockFactory instance of {@link LockFactory} providing the * locking implementation. * @return the FSDirectory for the named file. */ public static FSDirectory getDirectory(String path, LockFactory lockFactory) throws IOException { return getDirectory(new File(path), lockFactory); }
/** Returns the directory instance for the named location. * * @deprecated Use IndexWriter's create flag, instead, to * create a new index. * * @param path the path to the directory. * @param create if true, create, or erase any existing contents. * @return the FSDirectory for the named file. */ public static FSDirectory getDirectory(String path, boolean create) throws IOException { return getDirectory(new File(path), create); }
@Override public String[] listAll() throws IOException { File[] files = directory.getDirectory().listFiles(FILTER); if (files == null) { return null; } String[] names = new String[files.length]; for (int i = 0; i < names.length; i++) { names[i] = files[i].getName(); } return names; }
public static File getFSDir(Directory dir) { if (dir instanceof FilterDirectory){ dir = ((FilterDirectory) dir).getDelegate(); } if (dir instanceof FSDirectory){ return ((FSDirectory) dir).getDirectory(); } return null; } }
public IndexWriter getIndexWriter() { try { FSDirectory dir = FSDirectory.getDirectory(luceneDir); IndexWriter indexWriter = new IndexWriter(dir, new StandardAnalyzer()) ; return indexWriter ; } catch (Exception ex) { throw new ARQLuceneException("LARQ", ex) ; } } }
/** Returns an IndexReader reading the index in an FSDirectory in the named path. */ public static IndexReader open(String path) throws IOException { return open(FSDirectory.getDirectory(path, false), true); }
@Override public void stop() { try { directory.close(); } catch (Exception e) { log.unableToCloseLuceneDirectory( directory.getDirectory(), e ); } }
/** Create an on-disk index */ public IndexBuilderBase(String fileDir) { try { dir = FSDirectory.getDirectory(fileDir); makeIndex() ; } catch (Exception ex) { throw new ARQLuceneException("IndexBuilderLARQ", ex) ; } }
/** Create an on-disk index */ public IndexBuilderBase(File fileDir) { try { dir = FSDirectory.getDirectory(fileDir); makeIndex() ; } catch (Exception ex) { throw new ARQLuceneException("IndexBuilderLARQ", ex) ; } }
private RAMDirectory(FSDirectory dir, boolean closeDir, IOContext context) throws IOException { this(); for (String file : dir.listAll()) { if (!Files.isDirectory(dir.getDirectory().resolve(file))) { copyFrom(dir, file, file, context); } } if (closeDir) { dir.close(); } }
public IndexLARQ getIndexLARQ() { try { FSDirectory dir = FSDirectory.getDirectory(luceneDir); IndexReader indexReader = IndexReader.open(dir) ; return new IndexLARQ(indexReader) ; } catch (Exception ex) { throw new ARQLuceneException("LARQ", ex) ; } }
private String getFSDirPath(Directory dir){ if (dir instanceof CopyOnReadDirectory){ dir = ((CopyOnReadDirectory) dir).getLocal(); } dir = unwrap(dir); if (dir instanceof FSDirectory){ return ((FSDirectory) dir).getDirectory().getAbsolutePath(); } return null; }