public LogSearch(File file) throws Exception { this.file = file; directory = new NIOFSDirectory(file, new NativeFSLockFactory()); reader = IndexReader.open(directory); searcher = new IndexSearcher(reader); }
if (lock == null) { // not successful - clear up and move out clearLockHeld(realPath); // clear LOCK_HELD last
/** * Create a NativeFSLockFactory instance, storing lock * files into the specified lockDir: * * @param lockDir where lock files are created. */ public NativeFSLockFactory(File lockDir) throws IOException { setLockDir(lockDir); }
private void acquireTestLock() throws IOException { String randomLockName = "lucene-" + Long.toString(new Random().nextInt(), Character.MAX_RADIX) + "-test.lock"; Lock l = makeLock(randomLockName); try { l.obtain(); } catch (IOException e) { IOException e2 = new IOException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking"); e2.initCause(e); throw e2; } l.release(); }
/** * Set the lock directory. This is package-private and is * only used externally by FSDirectory when creating this * LockFactory via the System property * org.apache.lucene.store.FSDirectoryLockFactoryClass. */ void setLockDir(File lockDir) throws IOException { this.lockDir = lockDir; if (lockDir != null) { // Ensure that lockDir exists and is a directory. if (!lockDir.exists()) { if (!lockDir.mkdirs()) throw new IOException("Cannot create directory: " + lockDir.getAbsolutePath()); } else if (!lockDir.isDirectory()) { throw new IOException("Found regular file where directory expected: " + lockDir.getAbsolutePath()); } acquireTestLock(); } }
/** * Create a NativeFSLockFactory instance, storing lock * files into the specified lockDir: * * @param lockDir where lock files are created. */ public NativeFSLockFactory(File lockDir) throws IOException { setLockDir(lockDir); }
@Override 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(); } } }
/** * Set the lock directory. This is package-private and is * only used externally by FSDirectory when creating this * LockFactory via the System property * org.apache.lucene.store.FSDirectoryLockFactoryClass. */ void setLockDir(File lockDir) throws IOException { this.lockDir = lockDir; if (lockDir != null) { // Ensure that lockDir exists and is a directory. if (!lockDir.exists()) { if (!lockDir.mkdirs()) throw new IOException("Cannot create directory: " + lockDir.getAbsolutePath()); } else if (!lockDir.isDirectory()) { throw new IOException("Found regular file where directory expected: " + lockDir.getAbsolutePath()); } acquireTestLock(); } }
public FSDir(File dir, boolean simpleFS) throws IOException { if (!dir.mkdirs()) { if (!dir.isDirectory()) { throw new IOException("Unable to create directory: '" + dir + "'"); } } LockFactory lockFactory = new NativeFSLockFactory(dir); if (simpleFS) { directory = new SimpleFSDirectory(dir, lockFactory); } else { directory = FSDirectory.open(dir, lockFactory); } }
/** * Create a NativeFSLockFactory instance, storing lock * files into the specified lockDir: * * @param lockDir where lock files are created. */ public NativeFSLockFactory(File lockDir) { setLockDir(lockDir); }
if (lock == null) { // not successful - clear up and move out clearLockHeld(realPath); // clear LOCK_HELD last
private void acquireTestLock() throws IOException { String randomLockName = "lucene-" + Long.toString(new Random().nextInt(), Character.MAX_RADIX) + "-test.lock"; Lock l = makeLock(randomLockName); try { l.obtain(); } catch (IOException e) { IOException e2 = new IOException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking"); e2.initCause(e); throw e2; } l.release(); }
public FSDir(File dir, boolean simpleFS) throws IOException { if (!dir.mkdirs()) { if (!dir.isDirectory()) { throw new IOException("Unable to create directory: '" + dir + "'"); } } LockFactory lockFactory = new NativeFSLockFactory(dir); if (simpleFS) { directory = new SimpleFSDirectory(dir, lockFactory); } else { directory = FSDirectory.open(dir, lockFactory); } }
((NativeFSLockFactory) lockFactory).setLockDir(lockDir); } else if (lockFactory instanceof SimpleFSLockFactory) { ((SimpleFSLockFactory) lockFactory).setLockDir(lockDir);
if (lock == null) { // not successful - clear up and move out clearLockHeld(realPath); // clear LOCK_HELD last
(LOCK_FACTORY_CLASS == null) ? new NativeFSLockFactory() : (LockFactory)LOCK_FACTORY_CLASS.newInstance();
((NativeFSLockFactory) lockFactory).setLockDir(lockDir); } else if (lockFactory instanceof SimpleFSLockFactory) { ((SimpleFSLockFactory) lockFactory).setLockDir(lockDir);
if (lock == null) { // not successful - clear up and move out clearLockHeld(realPath); // clear LOCK_HELD last
/** Create a new FSDirectory for the named location (ctor for subclasses). * @param path the path of the directory * @param lockFactory the lock factory to use, or null for the default * ({@link NativeFSLockFactory}); * @throws IOException if there is a low-level I/O error */ protected FSDirectory(File path, LockFactory lockFactory) throws IOException { // new ctors use always NativeFSLockFactory as default: if (lockFactory == null) { lockFactory = new NativeFSLockFactory(); } directory = getCanonicalPath(path); if (directory.exists() && !directory.isDirectory()) throw new NoSuchDirectoryException("file '" + directory + "' exists but is not a directory"); setLockFactory(lockFactory); }
((NativeFSLockFactory) lockFactory).setLockDir(path); } else if (lockFactory instanceof SimpleFSLockFactory) { ((SimpleFSLockFactory) lockFactory).setLockDir(path);