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(); }
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(); }
@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(); } } }