public synchronized boolean obtain() throws LockObtainFailedException, IOException { return lock.obtain(); }
public synchronized boolean obtain() throws LockObtainFailedException, IOException { return lock.obtain(); }
@Override public synchronized boolean obtain() throws IOException { return lock.obtain(); }
public synchronized boolean obtain(long lockWaitTimeout) throws LockObtainFailedException, IOException { boolean obtained = lock.obtain(lockWaitTimeout); if (obtained) verify((byte) 1); return obtained; }
@Override public boolean obtain(long lockWaitTimeout) throws LockObtainFailedException, IOException { boolean unlocked; try { rwl.readLock().unlock(); unlocked = true; } catch (IllegalMonitorStateException e) { unlocked = false; } try { return lock.obtain(lockWaitTimeout); } finally { if (unlocked) { rwl.readLock().lock(); } } }
@Override public boolean obtain() throws IOException { boolean unlocked; try { rwl.readLock().unlock(); unlocked = true; } catch (IllegalMonitorStateException e) { unlocked = false; } try { return lock.obtain(); } finally { if (unlocked) { rwl.readLock().lock(); } } }
public synchronized boolean obtain(long lockWaitTimeout) throws LockObtainFailedException, IOException { boolean obtained = lock.obtain(lockWaitTimeout); if (obtained) verify((byte) 1); return obtained; }
@Override public synchronized boolean obtain(long lockWaitTimeout) throws IOException { boolean obtained = lock.obtain(lockWaitTimeout); if (obtained) verify((byte) 1); return obtained; }
/** Attempts to obtain an exclusive lock within amount * of time given. Currently polls once per second until * lockWaitTimeout is passed. * @param lockWaitTimeout length of time to wait in ms * @return true if lock was obtained * @throws IOException if lock wait times out or obtain() throws an IOException */ public boolean obtain(long lockWaitTimeout) throws IOException { boolean locked = obtain(); int maxSleepCount = (int)(lockWaitTimeout / LOCK_POLL_INTERVAL); int sleepCount = 0; while (!locked) { if (++sleepCount == maxSleepCount) { throw new IOException("Lock obtain timed out: " + this.toString()); } try { Thread.sleep(LOCK_POLL_INTERVAL); } catch (InterruptedException e) { throw new IOException(e.toString()); } locked = obtain(); } return locked; }
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(); }
/** Calls {@link #doBody} while <i>lock</i> is obtained. Blocks if lock * cannot be obtained immediately. Retries to obtain lock once per second * until it is obtained, or until it has tried ten times. Lock is released when * {@link #doBody} exits. */ public Object run() throws IOException { boolean locked = false; try { locked = lock.obtain(lockWaitTimeout); return doBody(); } finally { if (locked) lock.release(); } } }
/** Calls {@link #doBody} while <i>lock</i> is obtained. Blocks if lock * cannot be obtained immediately. Retries to obtain lock once per second * until it is obtained, or until it has tried ten times. Lock is released when * {@link #doBody} exits. * @throws LockObtainFailedException if lock could not * be obtained * @throws IOException if {@link Lock#obtain} throws IOException */ public Object run() throws LockObtainFailedException, IOException { boolean locked = false; try { locked = lock.obtain(lockWaitTimeout); return doBody(); } finally { if (locked) lock.release(); } } }
/** Calls {@link #doBody} while <i>lock</i> is obtained. Blocks if lock * cannot be obtained immediately. Retries to obtain lock once per second * until it is obtained, or until it has tried ten times. Lock is released when * {@link #doBody} exits. * @throws LockObtainFailedException if lock could not * be obtained * @throws IOException if {@link Lock#obtain} throws IOException */ public Object run() throws LockObtainFailedException, IOException { boolean locked = false; try { locked = lock.obtain(lockWaitTimeout); return doBody(); } finally { if (locked) lock.release(); } } }
/** Calls {@link #doBody} while <i>lock</i> is obtained. Blocks if lock * cannot be obtained immediately. Retries to obtain lock once per second * until it is obtained, or until it has tried ten times. Lock is released when * {@link #doBody} exits. * @throws LockObtainFailedException if lock could not * be obtained * @throws IOException if {@link Lock#obtain} throws IOException */ public Object run() throws IOException { boolean locked = false; try { locked = lock.obtain(lockWaitTimeout); return doBody(); } finally { if (locked) lock.release(); } } }
private IndexWriter(Directory d, Analyzer a, final boolean create, boolean closeDir) throws IOException { this.closeDir = closeDir; directory = d; analyzer = a; Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME); if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock throw new IOException("Index locked for write: " + writeLock); this.writeLock = writeLock; // save it synchronized (directory) { // in- & inter-process sync new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) { public Object doBody() throws IOException { if (create) segmentInfos.write(directory); else segmentInfos.read(directory); return null; } }.run(); } }
/** * Trys to acquire the WriteLock on this directory. * this method is only valid if this IndexReader is directory owner. * * @throws IOException If WriteLock cannot be acquired. */ private void aquireWriteLock() throws IOException { if (stale) throw new IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations"); if (writeLock == null) { Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME); if (!writeLock.obtain(IndexWriter.WRITE_LOCK_TIMEOUT)) // obtain write lock throw new IOException("Index locked for write: " + writeLock); this.writeLock = writeLock; // we have to check whether index has changed since this reader was opened. // if so, this reader is no longer valid for deletion if (SegmentInfos.readCurrentVersion(directory) > segmentInfos.getVersion()) { stale = true; this.writeLock.release(); this.writeLock = null; throw new IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations"); } } }
public Object doInTransaction() throws CompassException { for (int i = 0; i < finalSubIndexes.length; i++) { Directory dir = getDirectory(finalSubIndexes[i]); writerLocks[i] = dir.makeLock(IndexWriter.WRITE_LOCK_NAME); try { writerLocks[i].obtain(luceneSettings.getTransactionLockTimout()); } catch (IOException e) { throw new SearchEngineException("Failed to retrieve transaction locks", e); } } return null; } });
private void obtainOrderLockIfNeeded(String subIndex) throws SearchEngineException { if (!maintainOrder) { return; } Lock lock = orderLocks.get(subIndex); if (lock == null) { lock = searchEngine.getSearchEngineFactory().getLuceneIndexManager().getStore().openDirectory(subIndex).makeLock("order.lock"); try { lock.obtain(searchEngine.getSearchEngineFactory().getLuceneSettings().getTransactionLockTimout()); } catch (IOException e) { clearLocksIfNeeded(); throw new SearchEngineException("Failed to obtain order lock on sub index [" + subIndex + "]", e); } orderLocks.put(subIndex, lock); } }